public member type
<unordered_map>

std::unordered_multimap::hash_function

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

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

引數



返回值

雜湊函式。

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

示例

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

typedef std::unordered_multimap<std::string,std::string> stringmap;

int main ()
{
  stringmap myumm;

  stringmap::hasher fn = myumm.hash_function();

  std::cout << "this: " << fn ("this") << std::endl;
  std::cout << "thin: " << fn ("thin") << std::endl;

  return 0;
}

可能的輸出
this: 671344778
thin: 3223852919


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

複雜度

常量。

迭代器有效性

沒有變化。

另見