2
$\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 character. Is that a good first hash function? And what should I do for the second function now?

$\endgroup$

2 Answers 2

1
$\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$
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
    Commented Jun 3, 2020 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.
    Commented Jun 4, 2020 at 2:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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