diff options
author | Luca Deri <deri@ntop.org> | 2023-08-31 09:14:17 +0200 |
---|---|---|
committer | Luca Deri <deri@ntop.org> | 2023-08-31 09:14:17 +0200 |
commit | 16b0ce37100242b6cbaafe65d05ee4940b5aab3f (patch) | |
tree | 3275f107daeb62c09da6b2409db01aa381a49b27 /src/lib/ndpi_utils.c | |
parent | f82493966286e4ec88f909baa5b5066df12f73e6 (diff) |
Code cleanup
Diffstat (limited to 'src/lib/ndpi_utils.c')
-rw-r--r-- | src/lib/ndpi_utils.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/lib/ndpi_utils.c b/src/lib/ndpi_utils.c index 35c0410e2..c62d82edf 100644 --- a/src/lib/ndpi_utils.c +++ b/src/lib/ndpi_utils.c @@ -3006,3 +3006,26 @@ u_int32_t ndpi_nearest_power_of_two(u_int32_t x) { x++; return(x); } + +/* ********************************************************** */ + +/* + https://en.wikipedia.org/wiki/Jenkins_hash_function + + See also http://burtleburtle.net/bob/hash/spooky.html +*/ +u_int32_t ndpi_hash_string(char *str) { + u_int32_t hash, i; + + for(hash = i = 0; str[i] != '\0'; ++i) { + hash += str[i]; + hash += (hash << 10); + hash ^= (hash >> 6); + } + + hash += (hash << 3); + hash ^= (hash >> 11); + hash += (hash << 15); + + return(hash); +} |