Original Post
I was messing around with the std::hash_map and I tried making my own hash function for a key of type const char*. I looked into the hash_map source files and in the file called xhash a few lines down the hash_compare class has a function that hashes the key into a size_t type, so it does "return ((size_t)_Key)". hash_compare takes a template parameter of type _Pt. and _Pt is a function object that should provide two overloaded operator () for key comparisons and key hashing. the variable "comm" is of type _Pt in class hash_compare.
in the _Traits parameter of std::hash_map I was passing in the following
:::: [ Triple Buffer V2.0 ] ::::
struct obj
{
size_t operator () ( const char* str )
{
size_t ret = 0;
while( *str )
{
ret ^= *str | ret;
}
return ret;
}
bool operator () ( const char* left, const char* right )
{
return strcmp( left, right ) > 0;
}
};
hash_map<const char*, ValueType, hash_compare<const char*, obj> >
it says that the second parameter in the hash_compare function should be an object with to function objects. one to compare values and the other to hash a value. It says this in msdn.
so in the file xhash I has to change "return ((size_t)_Key);" to "return comm(_Key);"
Everything works fine apparently, but i dunno is this a bug in xhash or in msdn?
:::: [ Triple Buffer V2.0 ] ::::