hash function for well-defined string c++ -
i have string consist of numbers between 1-30 , 1 of 'r','t'or'm' char. allow me illustrate examples.
string a="15t","1r","12m","24t","24m" ... // valid string now need have hash function gives me unique hash value every input string. since input have finite set think possible.
is there can tell kind of hash function define ?
by way, i'll create hash table using vector hence guess size not of import issue i'll define 10000 upper bound. mean assume can not have more 10000 such string
thanks in advance.
just have big plenty integer type , set (maximal) 3 characters integer:
std::size_t hash(const char* s) { std::size_t result = 0; while(*s) { result <<= 8; result |= *s++; } homecoming result; } c++ hash hashtable
No comments:
Post a Comment