Hash table – analyze the target and select a good hash function

This is not a specific problem of a specific solution; Instead, it's a response to any good stack overflow question I can't find about how to select a good hash function for hash tables and similar tasks

So! Let's talk about hash functions and how to choose hash functions If a novice programmer needs to choose a good hash function for their specific task, what about choosing one? When is the simple and fast Fowler Noll VO suitable? When should they supply in murmurhash3? Do you have good resource links when comparing various options?

Solution

The hash function of the hash table should have these two properties

>Uniformity (H) all outputs shall be distributed as evenly as possible In other words, for a 32-bit hash function, the probability of each output should be equal to 1 / 2 ^ 32 (for n bits, it should be 1 / 2 ^ n) Using the unified hash function, the possibility of collision is minimized for any possible input. > Low computational cost compared with the encrypted hash function, the hash function of the table is expected to be fast, in which the speed is the transaction against the front image resistance (for example, it is difficult to find messages from a given hash value) and collision resistance

For the purpose of hash table, all encryption functions are bad choice, because the computational cost is huge Because the hash here is not for security, but for fast access Murmurhash is considered to be one of the fastest and unified functions for large hash tables or hash indexes For small tables, a simple hash function should be fine A simple hash is the value of our mixed object (by multiplication, addition and subtraction with some primes)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>