Unorder_map <float, short> Why does this work?

I use unordered_map> float, unsigned short> to implement a hash table in C ++.

I know that using floats as keys of a hash table is a BAD idea in most cases, because comparing them with an error. However, under these conditions, I read floats from large files, and their accuracy is known and constant.

However, I would like to know the details of how unordered_map hashes my floats in order to estimate the collision frequency. I do not override the default hash implementation when I create an unordered map. According to the documentation, the default hash function is std :: hash> Key>. In my case, this is std :: hash> float>. However, when I look at the std :: hash documentation, it is defined only for "template arguments like char *, const char *, crope, wrope and built-in integral types".

Does anyone know which function is called for hash values ​​when I add them to unordered_map?

unordered_map - http://msdn.microsoft.com/en-us/library/bb982522.aspx

std :: hash - http://www.sgi.com/tech/stl/hash.html#1

+1
source share
1 answer

According to the C ++ 11 standard, float supported for std::hash . The actual hash function is implementation dependent, so even if you can determine the collision frequency for your current compiler, a newer version or another compiler may implement a different hash function. Here is the complete list of std::hash specializations:

 template <> struct hash<bool>; template <> struct hash<char>; template <> struct hash<signed char>; template <> struct hash<unsigned char>; template <> struct hash<char16_t>; template <> struct hash<char32_t>; 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 <class T> struct hash<T*>; 
+1
source

All Articles