xxHash 0.8.2
Extremely fast non-cryptographic hash function
|
Data Structures | |
struct | XXH32_canonical_t |
Canonical (big endian) representation of XXH32_hash_t. More... | |
Typedefs | |
typedef struct XXH32_state_s | XXH32_state_t |
The opaque state struct for the XXH32 streaming API. | |
Functions | |
XXH32_hash_t | XXH32 (const void *input, size_t length, XXH32_hash_t seed) |
Calculates the 32-bit hash of input using xxHash32. | |
XXH32_state_t * | XXH32_createState (void) |
Allocates an XXH32_state_t. | |
XXH_errorcode | XXH32_freeState (XXH32_state_t *statePtr) |
Frees an XXH32_state_t. | |
void | XXH32_copyState (XXH32_state_t *dst_state, const XXH32_state_t *src_state) |
Copies one XXH32_state_t to another. | |
XXH_errorcode | XXH32_reset (XXH32_state_t *statePtr, XXH32_hash_t seed) |
Resets an XXH32_state_t to begin a new hash. | |
XXH_errorcode | XXH32_update (XXH32_state_t *statePtr, const void *input, size_t length) |
Consumes a block of input to an XXH32_state_t. | |
XXH32_hash_t | XXH32_digest (const XXH32_state_t *statePtr) |
Returns the calculated hash value from an XXH32_state_t. | |
void | XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash) |
Converts an XXH32_hash_t to a big endian XXH32_canonical_t. | |
XXH32_hash_t | XXH32_hashFromCanonical (const XXH32_canonical_t *src) |
Converts an XXH32_canonical_t to a native XXH32_hash_t. | |
Contains functions used in the classic 32-bit xxHash algorithm.
struct XXH32_state_s XXH32_state_t |
The opaque state struct for the XXH32 streaming API.
Streaming functions generate the xxHash value from an incremental input. This method is slower than single-call functions, due to state management. For small inputs, prefer XXH32()
and XXH64()
, which are better optimized.
An XXH state must first be allocated using XXH*_createState()
.
Start a new hash by initializing the state with a seed using XXH*_reset()
.
Then, feed the hash state by calling XXH*_update()
as many times as necessary.
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
Finally, a hash value can be produced anytime, by using XXH*_digest()
. This function returns the nn-bits hash as an int or long long.
It's still possible to continue inserting input into the hash state after a digest, and generate new hash values later on by invoking XXH*_digest()
.
When done, release the state using XXH*_freeState()
.
XXH32_hash_t XXH32 | ( | const void * | input, |
size_t | length, | ||
XXH32_hash_t | seed | ||
) |
Calculates the 32-bit hash of input
using xxHash32.
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark): 5.4 GB/s
See Single Shot Example for an example.
input | The block of data to be hashed, at least length bytes in size. |
length | The length of input , in bytes. |
seed | The 32-bit seed to alter the hash's output predictably. |
input
and input
+ length
must be valid, readable, contiguous memory. However, if length
is 0
, input
may be NULL
. In C++, this also must be TriviallyCopyable.XXH32_state_t * XXH32_createState | ( | void | ) |
Allocates an XXH32_state_t.
Must be freed with XXH32_freeState().
NULL
on failure. XXH_errorcode XXH32_freeState | ( | XXH32_state_t * | statePtr | ) |
Frees an XXH32_state_t.
Must be allocated with XXH32_createState().
statePtr | A pointer to an XXH32_state_t allocated with XXH32_createState(). |
void XXH32_copyState | ( | XXH32_state_t * | dst_state, |
const XXH32_state_t * | src_state | ||
) |
Copies one XXH32_state_t to another.
dst_state | The state to copy to. |
src_state | The state to copy from. |
dst_state
and src_state
must not be NULL
and must not overlap. XXH_errorcode XXH32_reset | ( | XXH32_state_t * | statePtr, |
XXH32_hash_t | seed | ||
) |
Resets an XXH32_state_t to begin a new hash.
This function resets and seeds a state. Call it before XXH32_update().
statePtr | The state struct to reset. |
seed | The 32-bit seed to alter the hash result predictably. |
statePtr
must not be NULL
.XXH_errorcode XXH32_update | ( | XXH32_state_t * | statePtr, |
const void * | input, | ||
size_t | length | ||
) |
Consumes a block of input
to an XXH32_state_t.
Call this to incrementally consume blocks of data.
statePtr | The state struct to update. |
input | The block of data to be hashed, at least length bytes in size. |
length | The length of input , in bytes. |
statePtr
must not be NULL
. input
and input
+ length
must be valid, readable, contiguous memory. However, if length
is 0
, input
may be NULL
. In C++, this also must be TriviallyCopyable.XXH32_hash_t XXH32_digest | ( | const XXH32_state_t * | statePtr | ) |
Returns the calculated hash value from an XXH32_state_t.
statePtr
, so you can update, digest, and update again.statePtr | The state struct to calculate the hash from. |
statePtr
must not be NULL
.void XXH32_canonicalFromHash | ( | XXH32_canonical_t * | dst, |
XXH32_hash_t | hash | ||
) |
Converts an XXH32_hash_t to a big endian XXH32_canonical_t.
dst | The XXH32_canonical_t pointer to be stored to. |
hash | The XXH32_hash_t to be converted. |
dst
must not be NULL
.The default return values from XXH functions are unsigned 32 and 64 bit integers.
The canonical representation uses big endian convention, the same convention as human-readable numbers (large digits first).
This way, hash values can be written into a file or buffer, remaining comparable across different systems.
The following functions allow transformation of hash values to and from their canonical format.
XXH32_hash_t XXH32_hashFromCanonical | ( | const XXH32_canonical_t * | src | ) |
Converts an XXH32_canonical_t to a native XXH32_hash_t.
src | The XXH32_canonical_t to convert. |
src
must not be NULL
.