From 80d24223e63ccb72b3bf4d9aa63f49074efe47c4 Mon Sep 17 00:00:00 2001 From: Florian Zschocke Date: Thu, 29 Sep 2022 12:13:12 +0200 Subject: [PATCH] libmdnsd: Make SPRIME actually a prime number 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. --- libmdnsd/mdnsd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmdnsd/mdnsd.c b/libmdnsd/mdnsd.c index 2dedab7..c2ca7a9 100644 --- a/libmdnsd/mdnsd.c +++ b/libmdnsd/mdnsd.c @@ -33,7 +33,7 @@ #include #include -#define SPRIME 108 /* Size of query/publish hashes */ +#define SPRIME 109 /* Size of query/publish hashes */ #define LPRIME 1009 /* Size of cache hash */ #define GC 86400 /* Brute force garbage cleanup