c++ - Accessing the intrinsic type hash functions for tr1/unordered_map -
i'm messing around unordered_map class template, , i'd write custom hasher class. documentation mentions default hashing functions provided intrinsic types. so, if declare:
std::tr1::unordered_map<std::string, int> foo; you automatically hasher defined you.
there's example on here on how provide functor if want custom hash function.
however, if have complex class has std::string member use key insertion/deletion unordered_map? don't want rewrite own hasher. want leverage written std::string type.
the default hash functor provided std::hash<t> returns size_t.
so can combine hash several members of class e.g. computing (std::hash<t>()(a) + prime * (std::hash<t>()(b) + prime * std::hash<t>()(c))).
Comments
Post a Comment