Lumiera  0.pre.03
»edit your freedom«
hash-fnv.h File Reference

Go to the source code of this file.

Description

Fowler-Noll-Vo Hashes.

FNV is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Phong Vo.

Definition in file hash-fnv.h.

#include <stdlib.h>
#include <inttypes.h>

Macros

#define HASH_FNV32_BASE   ((uint32_t)2166136261UL)
 
#define HASH_FNV32_PRIME   ((uint32_t)16777619UL)
 
#define HASH_FNV64_BASE   ((uint64_t)14695981039346656037ULL)
 
#define HASH_FNV64_PRIME   ((uint64_t)1099511628211ULL)
 

Functions

uint32_t hash_fnv32_retry (uint64_t hash, uint32_t limit)
 reduce hash to be within 0 to limit-1. More...
 
uint32_t hash_fnv32_xorfold (uint32_t hash, int bits)
 reduce a hash value to n bits. More...
 
uint32_t hash_fnv32a_buf (const void *buf, size_t len, uint32_t hval)
 FNV-1a 32 bit hash over a buffer. More...
 
uint32_t hash_fnv32a_strn (const char *str, size_t len, uint32_t hval)
 FNV-1a 32 bit hash over a zero terminated string. More...
 
uint64_t hash_fnv64_retry (uint64_t hash, uint64_t limit)
 reduce hash to be within 0 to limit-1. More...
 
uint64_t hash_fnv64_xorfold (uint64_t hash, int bits)
 reduce a hash value to n bits. More...
 
uint64_t hash_fnv64a_buf (const void *buf, size_t len, uint64_t hval)
 FNV-1a 64 bit hash over a buffer. More...
 
uint64_t hash_fnv64a_strn (const char *str, size_t len, uint64_t hval)
 FNV-1a 64 bit hash over a zero terminated string. More...
 

Function Documentation

◆ hash_fnv64a_buf()

uint64_t hash_fnv64a_buf ( const void *  buf,
size_t  len,
uint64_t  hval 
)

FNV-1a 64 bit hash over a buffer.

Parameters
bufstart of the buffer
lensize of the buffer
hvalprevious hash value when incremental hashing or HASH_FNV64_BASE when starting a new hash
Returns
new hash value

Definition at line 37 of file hash-fnv.c.

◆ hash_fnv64a_strn()

uint64_t hash_fnv64a_strn ( const char *  str,
size_t  len,
uint64_t  hval 
)

FNV-1a 64 bit hash over a zero terminated string.

Parameters
strstart of the buffer
lenmaximum size to be processed
hvalprevious hash value when incremental hashing or HASH_FNV64_BASE when starting a new hash
Returns
new hash value

Definition at line 68 of file hash-fnv.c.

◆ hash_fnv32a_buf()

uint32_t hash_fnv32a_buf ( const void *  buf,
size_t  len,
uint32_t  hval 
)

FNV-1a 32 bit hash over a buffer.

Parameters
bufstart of the buffer
lensize of the buffer
hvalprevious hash value when incremental hashing or HASH_FNV32_BASE when starting a new hash
Returns
new hash value

Definition at line 53 of file hash-fnv.c.

◆ hash_fnv32a_strn()

uint32_t hash_fnv32a_strn ( const char *  str,
size_t  len,
uint32_t  hval 
)

FNV-1a 32 bit hash over a zero terminated string.

Parameters
strstart of the buffer
lenmaximum size to be processed
hvalprevious hash value when incremental hashing or HASH_FNV32_BASE when starting a new hash
Returns
new hash value

Definition at line 84 of file hash-fnv.c.

◆ hash_fnv64_xorfold()

uint64_t hash_fnv64_xorfold ( uint64_t  hash,
int  bits 
)

reduce a hash value to n bits.

Uses the xor folding method to stash a hash value together, this preserves unbiased hash distribution

Parameters
hashresult from one of the 64 bit hash functions above
bitsnumber of significat bits for the result
Returns
hashvalue with no more than 'bits' significant bits

Definition at line 100 of file hash-fnv.c.

◆ hash_fnv32_xorfold()

uint32_t hash_fnv32_xorfold ( uint32_t  hash,
int  bits 
)

reduce a hash value to n bits.

Uses the xor folding method to stash a hash value together, this preserves unbiased hash distribution

Parameters
hashresult from one of the 32 bit hash functions above
bitsnumber of significat bits for the result
Returns
hashvalue with no more than 'bits' significant bits

Definition at line 119 of file hash-fnv.c.

◆ hash_fnv64_retry()

uint64_t hash_fnv64_retry ( uint64_t  hash,
uint64_t  limit 
)

reduce hash to be within 0 to limit-1.

Uses the retry method to limit a hash value, this preserves unbiased hash distribution.

Parameters
hashresult from one of the 64 bit hash functions above
limitupper limit plus one for the result
Returns
hashvalue in the range from 0 to limit-1

Definition at line 138 of file hash-fnv.c.

◆ hash_fnv32_retry()

uint32_t hash_fnv32_retry ( uint64_t  hash,
uint32_t  limit 
)

reduce hash to be within 0 to limit-1.

Uses the retry method to limit a hash value, this preserves unbiased hash distribution.

Parameters
hashresult from one of the 32 bit hash functions above
limitupper limit plus one for the result
Returns
hashvalue in the range from 0 to limit-1

Definition at line 150 of file hash-fnv.c.