Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

unordered_multiset::rehash

公众成员函数  <unordered_set>
hasher hash_function() const;

获取哈希函数

返回unordered_multiset容器使用的哈希函数对象。

哈希函数是一个一元函数,它接受一个类型为key_type的对象作为参数, 并基于该对象返回一个类型为size_t的唯一值。它被容器在构造时采用 (参阅unordered_multiset的构造函数了解更多信息)。 缺省情况下,它是对应键类型的缺省哈希函数:hash<key_type>

☲  参数


none

☉  返回值



hash函数.成员类型hasher是容器使用的hasher函数的类型, 在unordered_multiset中定义为其第二个模板形参(hash)的别名。

☣  示例



// 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

请注意,两个相似的字符串如何产生完全不同的哈希值。

✥ 复杂度



常量

☣ 迭代器的有效性



不变

🍄  另请参阅



unordered_multiset::key_eq 获取键的等价谓词(公众成员函数)
unordered_multiset::get_allocator 获取分配器(公众成员函数)

联系我们 免责声明 关于CandCplus 网站地图