Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libmdnsd: Make SPRIME actually a prime number #65

Merged
merged 1 commit into from
Oct 1, 2022

Conversation

fzs
Copy link
Contributor

@fzs fzs commented Sep 29, 2022

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.

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.
@troglobit troglobit merged commit 5fb29c7 into troglobit:master Oct 1, 2022
@fzs fzs deleted the the-real-prime branch October 4, 2022 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants