2 * Copyright (C) 2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
11 /* FNV hash'es lifted from Dustin Sallings work */
12 static uint64_t FNV_64_INIT
= UINT64_C(0xcbf29ce484222325);
13 static uint64_t FNV_64_PRIME
= UINT64_C(0x100000001b3);
14 static uint32_t FNV_32_INIT
= 2166136261UL;
15 static uint32_t FNV_32_PRIME
= 16777619;
17 uint32_t hashkit_fnv1_64(const char *key
, size_t key_length
)
19 /* Thanks to pierre@demartines.com for the pointer */
20 uint64_t hash
= FNV_64_INIT
;
23 for (x
= 0; x
< key_length
; x
++)
26 hash
^= (uint64_t)key
[x
];
29 return (uint32_t)hash
;
32 uint32_t hashkit_fnv1a_64(const char *key
, size_t key_length
)
34 uint32_t hash
= (uint32_t) FNV_64_INIT
;
37 for (x
= 0; x
< key_length
; x
++)
39 uint32_t val
= (uint32_t)key
[x
];
41 hash
*= (uint32_t) FNV_64_PRIME
;
47 uint32_t hashkit_fnv1_32(const char *key
, size_t key_length
)
49 uint32_t hash
= FNV_32_INIT
;
52 for (x
= 0; x
< key_length
; x
++)
54 uint32_t val
= (uint32_t)key
[x
];
62 uint32_t hashkit_fnv1a_32(const char *key
, size_t key_length
)
64 uint32_t hash
= FNV_32_INIT
;
67 for (x
= 0; x
< key_length
; x
++)
69 uint32_t val
= (uint32_t)key
[x
];