J
jbo5112
I'm working on a program that uses hash maps and a slightly modified
version of the murmurhash2 hash function (I removed the seed). I am
trying to figure out if there is a decent way to write specialized
versions of the hash function for different lengths of strings. If it
helps, I'll be wrapping my hash function inside of an object that just
has a function "int operator() ( const std::string &str ) {return
my_hash(str.c_str(), str.length());}".
The length will be computed at run time, so I don't think I can use
template functions to sort out which one to use. Another program uses
strings with lengths that can be hard coded so I can use class
specialization and special hash functions with different names. Right
now, the only thing I can think of is to have an array of different
functions for any reasonable length (starting from zero length) and a
default that works with any length. I'm thinking a switch statement
or if statements would more than negate any speed gained by the
specialization.
version of the murmurhash2 hash function (I removed the seed). I am
trying to figure out if there is a decent way to write specialized
versions of the hash function for different lengths of strings. If it
helps, I'll be wrapping my hash function inside of an object that just
has a function "int operator() ( const std::string &str ) {return
my_hash(str.c_str(), str.length());}".
The length will be computed at run time, so I don't think I can use
template functions to sort out which one to use. Another program uses
strings with lengths that can be hard coded so I can use class
specialization and special hash functions with different names. Right
now, the only thing I can think of is to have an array of different
functions for any reasonable length (starting from zero length) and a
default that works with any length. I'm thinking a switch statement
or if statements would more than negate any speed gained by the
specialization.