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
, void *context
__attribute__((unused
)))
19 /* Thanks to pierre@demartines.com for the pointer */
20 uint64_t hash
= FNV_64_INIT
;
22 for (size_t x
= 0; x
< key_length
; x
++)
25 hash
^= (uint64_t)key
[x
];
28 return (uint32_t)hash
;
31 uint32_t hashkit_fnv1a_64(const char *key
, size_t key_length
, void *context
__attribute__((unused
)))
33 uint32_t hash
= (uint32_t) FNV_64_INIT
;
35 for (size_t x
= 0; x
< key_length
; x
++)
37 uint32_t val
= (uint32_t)key
[x
];
39 hash
*= (uint32_t) FNV_64_PRIME
;
45 uint32_t hashkit_fnv1_32(const char *key
, size_t key_length
, void *context
__attribute__((unused
)))
47 uint32_t hash
= FNV_32_INIT
;
49 for (size_t x
= 0; x
< key_length
; x
++)
51 uint32_t val
= (uint32_t)key
[x
];
59 uint32_t hashkit_fnv1a_32(const char *key
, size_t key_length
, void *context
__attribute__((unused
)))
61 uint32_t hash
= FNV_32_INIT
;
63 for (size_t x
= 0; x
< key_length
; x
++)
65 uint32_t val
= (uint32_t)key
[x
];