swissChili | ca0d2e2 | 2020-08-16 15:09:25 -0700 | [diff] [blame] | 1 | #include "hash.h" |
2 | |||||
3 | uint32_t hash(char *str) | ||||
4 | { | ||||
swissChili | 7acb4ce | 2020-08-16 20:16:10 -0700 | [diff] [blame] | 5 | uint32_t hash = 5381; |
6 | char c; | ||||
swissChili | ca0d2e2 | 2020-08-16 15:09:25 -0700 | [diff] [blame] | 7 | |
swissChili | 7acb4ce | 2020-08-16 20:16:10 -0700 | [diff] [blame] | 8 | while (c = *str++) |
9 | { | ||||
10 | hash = (hash << 5) + hash + c; | ||||
11 | } | ||||
swissChili | ca0d2e2 | 2020-08-16 15:09:25 -0700 | [diff] [blame] | 12 | |
swissChili | 7acb4ce | 2020-08-16 20:16:10 -0700 | [diff] [blame] | 13 | return hash; |
swissChili | ca0d2e2 | 2020-08-16 15:09:25 -0700 | [diff] [blame] | 14 | } |