Skip to content

Best Collection of String Hash Function Comparison

hash function comparison
What is hashing.

This is a small collection of string hash function comparison.

Before checking string hash comparision table, we need to know what a hash function is. A hash function is any function that can map data of any size to values of a fixed size. Hash values, hash codes, digests, or just “hashes” are the names for the values that a hash function gives back. Most of the time, the values are used to index a table with a fixed size called a “hash table.” Hashing or scatter storage addressing is the use of a hash function to index a hash table.

Hash functions and the hash tables that go with them are used in applications that store and retrieve data to get to the data quickly and in almost the same amount of time each time. They only need a little bit more storage space than the amount needed for the data or records themselves. Hashing is a way to access data that is easy to compute and takes up little storage space. It avoids the non-constant access times of ordered and unordered lists and structured trees, as well as the often exponential storage needs of direct access to state spaces with large or variable-length keys.

Commonly used string Hash functions and ELFHash, APHash, etc., are very simple and effective methods. These functions use bitwise operations so that each character contributes to the final function value. There are also hash functions represented by MD5 and SHA1, which are almost impossible to find collisions.

Commonly used string hash functions are BKDRHash, APHash, DJBHash, JSHash, RSHash, SDBMHash, PJWHash, ELFHash and so on. For the above hash functions, I made a small evaluation of them.

String hash function comparison

Among them,

  • Data 1 is the number of hash collisions of random strings composed of 100,000 letters and numbers.
  • Data 2 is the number of hash collisions of 100,000 meaningful English sentences.
  • Data 3 is the number of conflicts stored in the linear table after the hash value of data 1 is modulo 1000003 (a large prime number).
  • Data 4 is the number of conflicts stored in the linear table after the hash value of data 1 is modulo 10000019 (a larger prime number).
Hash FunctionData1Data2Data3Data4D1 ScoreD2 ScoreD3 ScoreD4 ScoreAverage
BKDRHash20477448196.5510090.9582.0592.64
APHash23475449396.5588.4610051.2886.28
DJBHash22497547496.5592.31010083.43
JSHash14476150610084.6296.8317.9581.94
RSHash10486150510010051.5820.5175.96
SDBMHash32484950493.192.3157.0123.0872.41
PJWHash302648785130043.89021.95
ELFHash302648785130043.89021.95
Comparison

After comparison, the above average scores are obtained. The mean is the mean of squares. It can be found that the effect of BKDRHash is the most prominent in both the actual effect and the encoding implementation. APHash is also a relatively good algorithm. DJBHash, JSHash, RSHash and SDBMHash each have their own merits. PJWHash and ELFHash have the worst effect, but have similar scores, and their algorithmic essences are similar.

In the information repair competition, based on the principle of easy coding and debugging, I personally think that BKDRHash is the most suitable for memory and use.

(Visited 33 times, 1 visits today)

Share your feelings with us.

Your email address will not be published. Required fields are marked *

%d bloggers like this: