I understand the mathematical basis for hash tables. I have a hash function (which I found somewhere) below:
static const size_t InitialFNV = 2166136261U;
static const size_t FNVMultiple = 16777619;
size_t myhash(const string &s, int length)
{
size_t hash = InitialFNV;
for(size_t i = 0; i < length; i++)
{
hash = hash ^ (s[i]);
hash = hash * FNVMultiple;
}
return hash;
}
- Why does this return
size_t? - How to use this to write
store()that places a row in a hash table? - How can this be adapted for an array of characters?
- As for No. 3, would it be advisable to replace a loop
forwith a loop whilethat ends with a symbol '\0'?
FYI, I'm studying for a second job interview, and that’s why I ask.
source
share