icn
icn

Reputation: 17876

what hash function is being used by boost c++ unordered_map?

what hash function is being used by boost c++ unordered_map ? I meant what kind of hash algorithms being used by boost::hash, for example

template<> struct hash;

Thanks

Upvotes: 2

Views: 2460

Answers (2)

ta.speot.is
ta.speot.is

Reputation: 27214

It depends on the type you are using, if you look here the boost::hash template class is specialised:

  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*>;

You can also specify your own hash as the third template argument:

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;

Upvotes: 5

Johan Kotlinski
Johan Kotlinski

Reputation: 25739

By default, it uses boost::hash :)

Upvotes: 9

Related Questions