troglobit / mdnsd

Jeremie Miller's original mdnsd
BSD 3-Clause "New" or "Revised" License
57 stars 35 forks source link

libmdnsd: Make SPRIME actually a prime number #65

Closed fzs closed 2 years ago

fzs commented 2 years ago

Hashing strings for hash tables usually involves a prime number. It breaks down the raw hash into one bucket and therefore defines the size of the hash table. Chosing a prime number as hash table size will greatly reduce the number of collisions.

mdnsd uses two hash table sizes, defined by LPRIME and SPRIME. While LPRIME is defined to 1009, which is a prime number, SPRIME is defined to 108 - obviously not a prime number. Since I could not find any reason for this in code or history, this commit sets the value of SPRIME to 109 so that it actually is a prime number. Since using prime numbers just makes sense for hash table sizes.