I would like to know if there is a difference in speed between computing hash value (for example std::map key) of primitive integral type, such as int64_t and pod type, for example struct { int16_t v[4]; };. what about int128_t versus struct {int32_t v[4];}?
I know this is going to implementation specific, so my question ultimately pertains to gnu standard library.
Thanks
the link I found very useful
How can I use a custom type for keys in a boost::unordered_map?
std::mapis not a hash table. It is usually implemented as a balanced binary tree. What you want isstd::unordered_map* .And for
std::unordered_map, C++ only defines the hash value for the internal types and the common ones** such asstd::string. You need to implement the hash function forstruct { int16_t v[4]; };yourself. You can cast this struct intoint64_tin the computation, then there won’t be any difference in hashing speed.(*: ==
std::tr1::unordered_map==boost::unordered_map≈__gnu_cxx::hash_map==stdext::hash_mapetc)(**: 20.8.16 Class template
hash: … integer types (3.9.1), floating-point types (3.9.1), pointer types (8.3.1), andstd::string,std::u16string,std::u32string,std::wstring,std::error_code,std::thread::id,std::bitset, andstd::vector<bool>.)