public member type
<unordered_set>

std::unordered_multiset::hash_function

hasher hash_function() const;
獲取雜湊函式
返回由 unordered_multiset 容器使用的雜湊函式物件。

雜湊函式是一個一元函式,它接受一個型別為key_type作為引數,並基於它返回一個唯一的 size_t 型別值。它在構造時被容器採納(有關更多資訊,請參閱 unordered_set 的建構函式)。預設情況下,它是對應 key_type 的預設雜湊函式:hash<key_type>

引數



返回值

雜湊函式。

成員型別hasher是容器使用的雜湊函式的型別,在 unordered_multiset 中定義為其第二個模板引數的別名(Hash).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// unordered_multiset::hash_function
#include <iostream>
#include <string>
#include <unordered_set>

typedef std::unordered_multiset<std::string> stringset;

int main ()
{
  stringset myums;

  stringset::hasher fn = myums.hash_function();

  std::cout << "that: " << fn ("that") << std::endl;
  std::cout << "than: " << fn ("than") << std::endl;

  return 0;
}

可能的輸出
this: 1046150783
thin: 929786026


請注意,兩個相似的字串如何產生截然不同的雜湊值。

複雜度

常量。

迭代器有效性

沒有變化。

另見