【问题标题】:what hash function is being used by boost c++ unordered_map?boost c ++ unordered_map正在使用什么哈希函数?
【发布时间】:2011-01-15 00:40:13
【问题描述】:

boost c++ unordered_map 正在使用什么哈希函数?我的意思是 boost::hash 使用什么样的哈希算法,例如

模板结构哈希;

谢谢

【问题讨论】:

标签: c++ boost hash hash-function


【解决方案1】:

默认情况下,它使用boost::hash :)

【讨论】:

    【解决方案2】:

    这取决于你使用的类型,如果你看here boost::hash 模板类是专门的:

      template<> struct hash<bool>;
      template<> struct hash<char>;
      template<> struct hash<signed char>;
      template<> struct hash<unsigned char>;
      template<> struct hash<wchar_t>;
      template<> struct hash<short>;
      template<> struct hash<unsigned short>;
      template<> struct hash<int>;
      template<> struct hash<unsigned int>;
      template<> struct hash<long>;
      template<> struct hash<unsigned long>;
      template<> struct hash<long long>;
      template<> struct hash<unsigned long long>;
      template<> struct hash<float>;
      template<> struct hash<double>;
      template<> struct hash<long double>;
      template<> struct hash<std::string>;
      template<> struct hash<std::wstring>;
      template<typename T> struct hash<T*>;
    

    您还可以指定自己的哈希作为第三个模板参数:

    namespace boost {
      template<typename Key, typename Mapped, typename Hash = boost::hash<Key>, 
               typename Pred = std::equal_to<Key>, 
               typename Alloc = std::allocator<std::pair<Key const, Mapped> > > 
        class unordered_map;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-05
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多