1
$\begingroup$

How would you choose the second hash function with for double hashing with string as key? My first hash function is the scalar product of a random int array with the 16 bit number of each char. Is that a good first hash function? And what should I do for the second function now? hanks in advance.

$\endgroup$
0
$\begingroup$

There are many hash functions for hashing a string; a web search should turn up a bunch. You can use any one you like. The fact that you are using double hashing doesn't impose any additional requirements on the hash function. Yes, that would be a reasonable hash (and you could use two different int arrays for the two different hash functions); there are many other choices that would be reasonable as well.

$\endgroup$
2
  • $\begingroup$ Ok and how i can choose a good in array for my string hash function? $\endgroup$
    – buku juku
    Jun 3 '20 at 12:54
  • $\begingroup$ @bukujuku, assuming you're working modulo $2^n$ (e.g., $2^{32}$) rather than modulo a prime, choose random odd numbers. $\endgroup$
    – D.W.
    Jun 4 '20 at 2:29
0
$\begingroup$

Today, I would choose a second hash function that has the same form as the first hash function, but uses different constants.

The reason why is that modern CPUs have SIMD instructions, so you can compute both hash functions at the same time.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.