csnip  0.1
Macros | Functions
Hash functions

Hash functions. More...

Macros

#define CSNIP_FNV32_INIT   ((uint32_t)0x811C9DC5ul)
 FNV32's initialization constant.
 
#define CSNIP_FNV64_INIT   ((uint64_t)0xCBF29CE484222325ull)
 FNV64's initialization constant.
 

Functions

uint32_t csnip_hash_fnv32_b (const void *buf, size_t sz, uint32_t h0)
 Compute FNV32 hash. More...
 
uint32_t csnip_hash_fnv32_s (const char *str, uint32_t h0)
 Compute FNV32 hash. More...
 
uint64_t csnip_hash_fnv64_b (const void *buf, size_t sz, uint64_t h0)
 Compute FNV64 hash. More...
 
uint64_t csnip_hash_fnv64_s (const char *str, uint64_t h0)
 Compute FNV64 hash. More...
 

Detailed Description

Defines good non-cryptographic hashing functions. Included are the 32 and 64 bit variants of the FNV-1a hash.

References: [1] https://tools.ietf.org/html/draft-eastlake-fnv-11 [2] http://isthe.com/chongo/tech/comp/fnv/

Fairly interesting reads on the topic: http://programmers.stackexchange.com/questions/49550/\ which-hashing-algorithm-is-best-for-uniqueness-and-speed

Function Documentation

◆ csnip_hash_fnv32_b()

uint32_t csnip_hash_fnv32_b ( const void *  buf,
size_t  sz,
uint32_t  h0 
)

This computes the FNV hash of a memory buffer.

Parameters
bufPointer to the buffer to hash
szLength of the buffer in bytes
h0Initial hashing value. If hashing just a single buffer, an arbitrary value can be used; the standard choice being CSNIP_FNV32_INIT. The hash of a concatenation of buffers can be obtained by using this value for chaining, i.e.,
h1 = csnip_hash_fnv32_b(buf1, sz1, \
        CSNIP_FNV32_INIT);
h = csnip_hash_fnv32_b(buf2, sz2, h1);
results in the same value of h as the computation
h = csnip_hash_fnv32_b(buf, sz, \
        CSNIP_FNV32_INIT);
assuming that buf is the concatenation of the buffers buf1 and buf2.

◆ csnip_hash_fnv32_s()

uint32_t csnip_hash_fnv32_s ( const char *  str,
uint32_t  h0 
)

Compute the FNV32 hash of a C string. The terminating '\0' is not itself included when the hash is computed.

Parameters
strC string to hash
h0initial hash value. A good default is to use CSNIP_FNV32_INIT. See csnip_hash_fnv32_b() about a way to hash a concatenation of strings.

◆ csnip_hash_fnv64_b()

uint64_t csnip_hash_fnv64_b ( const void *  buf,
size_t  sz,
uint64_t  h0 
)

Compute the FNV64 hash of a memory buffer.

Parameters
bufpointer to memory buffer to hash
szsize of the memory buffer to hash
h0Initial value. Use, e.g., CSNIP_FNV64_INIT. See the documentation of csnip_hash_fnv32_b() about hashing a concatenation of buffers.

◆ csnip_hash_fnv64_s()

uint64_t csnip_hash_fnv64_s ( const char *  str,
uint64_t  h0 
)

Compute the FNV64 hash of a C string.

Parameters
strstring to hash.
h0Initial value. Use, e.g., CSNIP_FNV64_INIT. See csnip_hash_fnv32_b() about hashing a concatenation of strings.