Trouble using hash function
I am implementing google's dense hash map in my C++ code. I want to use MurmurHash2 ( http://murmurhash.g开发者_运维百科ooglepages.com/ ) as a hash function. But here's the problem. I have tried a lot but cant seem to get the hash function to work. The example shows the use of a default hash function (hash< const char * >).
dense_hash_map < const char * , int, hash < const char*>, eqstr> months;
I would like to replace hash< const char * > by
unsigned int MurmurHash2 ( const char * key, int len, unsigned int seed)
Clearly you have a mismatch between the signature that the dense_hash_map requires from its hashing function, and the signature that MurmurHash2 provides. You'll have to perform your own "impedence matching" in a function or functor of your own that implements the required signature and internally uses the provided one. This, however, requires the ability to determine the len corresponding to a given const char *, and there's no obvious answer to that. Do you plan to store in your hash map only "null terminated arrays of characters", as in old-fashioned C "pseudo-strings", so that strlen will suffice? or, what else...?
Maybe using std::string (or some other unambiguous C++ type depending on exactly what you're trying to achieve!) instead of those dubious const char *s would be a better start!
加载中,请稍侯......
精彩评论