Skip to content

Hash Functions

include/math/hash.h View source View on GitHub
uint32_t hash_djb2(const void *key, size_t len)
source

Dan Bernstein’s algorithm

uint32_t hash_sdbm(const void *key, size_t len)
source

SDBM database hash

uint32_t hash_fnv1a(const void *key, size_t len)
source

32-bit Fowler-Noll-Vo FNV-1a

uint64_t hash_fnv1a_64_update(
    uint64_t hash,
    const void *key,
    size_t len
)
source
uint64_t hash_fnv1a_64(const void *key, size_t len)
source
uint32_t hash_jenkins_qword(uint64_t key, uint32_t seed)
source
uint32_t hash_jenkins_one_at_a_time(const void *key, size_t len)
source
size_t hash_pointer(void *ptr)
source
uint32_t hash_murmur3_32(const void *key, size_t len, uint32_t seed)
source
uint32_t hash_elf(const void *key, size_t len)
source

Used in ELF file format, also called PJW hash

uint32_t hash_bkdr(const void *key, size_t len)
source

Brian Kernighan and Dennis Ritchiie

#define HASH_FNV1A_64_OFFSET_BASIS UINT64_C(14695981039346656037)
source
#define HASH_FNV1A_64_PRIME UINT64_C(1099511628211)
source
#define jhash_mix(a, b, c)
source
Expansion
#define jhash_mix(a, b, c) \
    { \
        a -= c; \
        a ^= ((c) << 4) | ((c) >> 28); \
        c += b; \
        b -= a; \
        b ^= ((a) << 6) | ((a) >> 26); \
        a += c; \
        c -= b; \
        c ^= ((b) << 8) | ((b) >> 24); \
        b += a; \
        a -= c; \
        a ^= ((c) << 16) | ((c) >> 16); \
        c += b; \
        b -= a; \
        b ^= ((a) << 19) | ((a) >> 13); \
        a += c; \
        c -= b; \
        c ^= ((b) << 4) | ((b) >> 28); \
        b += a; \
    }
#define jhash_final(a, b, c)
source
Expansion
#define jhash_final(a, b, c) \
    { \
        c ^= b; \
        c -= ((b) << 14) | ((b) >> 18); \
        a ^= c; \
        a -= ((c) << 11) | ((c) >> 21); \
        b ^= a; \
        b -= ((a) << 25) | ((a) >> 7); \
        c ^= b; \
        c -= ((b) << 16) | ((b) >> 16); \
        a ^= c; \
        a -= ((c) << 4) | ((c) >> 28); \
        b ^= a; \
        b -= ((a) << 14) | ((a) >> 18); \
        c ^= b; \
        c -= ((b) << 24) | ((b) >> 8); \
    }
#define HASH_MURMUR3_SEED_DEFAULT 104729
source