Change meaning of "bits" in FNV hash functions to bitlen instead of 32-bitlen.
Do reduction like recommended by http://www.isthe.com/chongo/tech/comp/fnv/index.html#xor-fold
This commit is contained in:
parent
176489286d
commit
1cda7a9cb2
2 changed files with 12 additions and 8 deletions
|
@ -44,19 +44,19 @@ extern struct Dictionary *nd_dict;
|
||||||
#define FNV1_32_INIT 0x811c9dc5UL
|
#define FNV1_32_INIT 0x811c9dc5UL
|
||||||
|
|
||||||
/* Client hash table size, used in hash.c/s_debug.c */
|
/* Client hash table size, used in hash.c/s_debug.c */
|
||||||
#define U_MAX_BITS (32-17)
|
#define U_MAX_BITS 17
|
||||||
#define U_MAX 131072 /* 2^17 */
|
#define U_MAX 131072 /* 2^17 */
|
||||||
|
|
||||||
/* Channel hash table size, hash.c/s_debug.c */
|
/* Channel hash table size, hash.c/s_debug.c */
|
||||||
#define CH_MAX_BITS (32-16)
|
#define CH_MAX_BITS 16
|
||||||
#define CH_MAX 65536 /* 2^16 */
|
#define CH_MAX 65536 /* 2^16 */
|
||||||
|
|
||||||
/* hostname hash table size */
|
/* hostname hash table size */
|
||||||
#define HOST_MAX_BITS (32-17)
|
#define HOST_MAX_BITS 17
|
||||||
#define HOST_MAX 131072 /* 2^17 */
|
#define HOST_MAX 131072 /* 2^17 */
|
||||||
|
|
||||||
/* RESV/XLINE hash table size, used in hash.c */
|
/* RESV/XLINE hash table size, used in hash.c */
|
||||||
#define R_MAX_BITS (32-10)
|
#define R_MAX_BITS 10
|
||||||
#define R_MAX 1024 /* 2^10 */
|
#define R_MAX 1024 /* 2^10 */
|
||||||
|
|
||||||
|
|
||||||
|
|
12
src/hash.c
12
src/hash.c
|
@ -109,7 +109,8 @@ fnv_hash_upper(const unsigned char *s, int bits)
|
||||||
h ^= ToUpper(*s++);
|
h ^= ToUpper(*s++);
|
||||||
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
||||||
}
|
}
|
||||||
h = (h >> bits) ^ (h & ((2^bits)-1));
|
if (bits < 32)
|
||||||
|
h = ((h >> bits) ^ h) & ((1<<bits)-1);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +124,8 @@ fnv_hash(const unsigned char *s, int bits)
|
||||||
h ^= *s++;
|
h ^= *s++;
|
||||||
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
||||||
}
|
}
|
||||||
h = (h >> bits) ^ (h & ((2^bits)-1));
|
if (bits < 32)
|
||||||
|
h = ((h >> bits) ^ h) & ((1<<bits)-1);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +139,8 @@ fnv_hash_len(const unsigned char *s, int bits, int len)
|
||||||
h ^= *s++;
|
h ^= *s++;
|
||||||
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
||||||
}
|
}
|
||||||
h = (h >> bits) ^ (h & ((2^bits)-1));
|
if (bits < 32)
|
||||||
|
h = ((h >> bits) ^ h) & ((1<<bits)-1);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +154,8 @@ fnv_hash_upper_len(const unsigned char *s, int bits, int len)
|
||||||
h ^= ToUpper(*s++);
|
h ^= ToUpper(*s++);
|
||||||
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
h += (h<<1) + (h<<4) + (h<<7) + (h << 8) + (h << 24);
|
||||||
}
|
}
|
||||||
h = (h >> bits) ^ (h & ((2^bits)-1));
|
if (bits < 32)
|
||||||
|
h = ((h >> bits) ^ h) & ((1<<bits)-1);
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue