diff options
author | Chet Ramey <chet.ramey@case.edu> | 2018-12-20 11:41:58 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2018-12-20 11:41:58 -0500 |
commit | f250956cb2a8dca13fc0242affc225f9d6983604 (patch) | |
tree | 2df8e15963af786dc8efed1c91c4d823a3bf05bb /hashlib.c | |
parent | 2ae59c1134a75d5778997b7202b15b0586283042 (diff) | |
download | bash-5.0-testing.tar.gz |
bash-5.0-rc1 releasebash-5.0-rc1bash-5.0-testing
Diffstat (limited to 'hashlib.c')
-rw-r--r-- | hashlib.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -125,6 +125,20 @@ hash_copy (table, cpdata) return new_table; } +/* This is the best 32-bit string hash function I found. It's one of the + Fowler-Noll-Vo family (FNV-1). + + The magic is in the interesting relationship between the special prime + 16777619 (2^24 + 403) and 2^32 and 2^8. */ + +#define FNV_OFFSET 2166136261 +#define FNV_PRIME 16777619 + +/* If you want to use 64 bits, use +FNV_OFFSET 14695981039346656037 +FNV_PRIMT 1099511628211 +*/ + /* The `khash' check below requires that strings that compare equally with strcmp hash to the same value. */ unsigned int @@ -133,14 +147,9 @@ hash_string (s) { register unsigned int i; - /* This is the best string hash function I found. - - The magic is in the interesting relationship between the special prime - 16777619 (2^24 + 403) and 2^32 and 2^8. */ - - for (i = 0; *s; s++) + for (i = FNV_OFFSET; *s; s++) { - i *= 16777619; + i *= FNV_PRIME; i ^= *s; } |