module
XXH32 familyContains functions used in the classic 32-bit xxHash algorithm.
Classes
- struct XXH32_canonical_t
- Canonical (big endian) representation of XXH32_hash_t.
Typedefs
- using XXH32_state_t = struct XXH32_state_s
- The opaque state struct for the XXH32 streaming API.
Functions
- auto XXH32(const void* input, size_t length, XXH32_hash_t seed) -> XXH_PUBLIC_API XXH32_hash_t
- Calculates the 32-bit hash of
input
using xxHash32. -
auto XXH32_createState(void) -> XXH_PUBLIC_API XXH32_
state_ t* - Allocates an XXH32_
state_ t. -
auto XXH32_freeState(XXH32_
state_ t* statePtr) -> XXH_PUBLIC_API XXH_errorcode - Frees an XXH32_
state_ t. -
auto XXH32_copyState(XXH32_
state_ t* dst_state, const XXH32_ state_ t* src_state) -> XXH_PUBLIC_API void - Copies one XXH32_
state_ t to another. -
auto XXH32_reset(XXH32_
state_ t* statePtr, XXH32_hash_t seed) -> XXH_PUBLIC_API XXH_errorcode - Resets an XXH32_
state_ t to begin a new hash. -
auto XXH32_update(XXH32_
state_ t* statePtr, const void* input, size_t length) -> XXH_PUBLIC_API XXH_errorcode - Consumes a block of
input
to an XXH32_state_ t. -
auto XXH32_digest(const XXH32_
state_ t* statePtr) -> XXH_PUBLIC_API XXH32_hash_t - Returns the calculated hash value from an XXH32_
state_ t. -
auto XXH32_canonicalFromHash(XXH32_
canonical_ t* dst, XXH32_hash_t hash) -> XXH_PUBLIC_API void - Converts an XXH32_hash_t to a big endian XXH32_
canonical_ t. -
auto XXH32_hashFromCanonical(const XXH32_
canonical_ t* src) -> XXH_PUBLIC_API XXH32_hash_t - Converts an XXH32_
canonical_ t to a native XXH32_hash_t.
Typedef documentation
typedef struct XXH32_state_s XXH32_state_t
#include <eckit/contrib/xxhash/xxhash.h>
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()
.
Example code for incrementally hashing a file:
#include <stdio.h> #include <xxhash.h> #define BUFFER_SIZE 256 // Note: XXH64 and XXH3 use the same interface. XXH32_hash_t hashFile(FILE* stream) { XXH32_state_t* state; unsigned char buf[BUFFER_SIZE]; size_t amt; XXH32_hash_t hash; state = XXH32_createState(); // Create a state assert(state != NULL); // Error check here XXH32_reset(state, 0xbaad5eed); // Reset state with our seed while ((amt = fread(buf, 1, sizeof(buf), stream)) != 0) { XXH32_update(state, buf, amt); // Hash the file in chunks } hash = XXH32_digest(state); // Finalize the hash XXH32_freeState(state); // Clean up return hash; }
Function documentation
XXH_PUBLIC_API XXH32_hash_t XXH32(const void* input,
size_t length,
XXH32_hash_t seed)
#include <eckit/contrib/xxhash/xxhash.h>
Calculates the 32-bit hash of input
using xxHash32.
Parameters | |
---|---|
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. |
Returns | The calculated 32-bit hash value. |
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark): 5.4 GB/s
XXH_PUBLIC_API XXH32_ state_ t* XXH32_createState(void)
#include <eckit/contrib/xxhash/xxhash.h>
Allocates an XXH32_
Returns | An allocated XXH32_state_t on success, NULL on failure. |
---|
Must be freed with XXH32_
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_ state_ t* statePtr)
#include <eckit/contrib/xxhash/xxhash.h>
Frees an XXH32_
Parameters | |
---|---|
statePtr | A pointer to an XXH32_ |
Returns | XXH_OK. |
Must be allocated with XXH32_
XXH_PUBLIC_API void XXH32_copyState(XXH32_ state_ t* dst_state,
const XXH32_ state_ t* src_state)
#include <eckit/contrib/xxhash/xxhash.h>
Copies one XXH32_
Parameters | |
---|---|
dst_state | The state to copy to. |
src_state | The state to copy from. |
XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_ state_ t* statePtr,
XXH32_hash_t seed)
#include <eckit/contrib/xxhash/xxhash.h>
Resets an XXH32_
Parameters | |
---|---|
statePtr | The state struct to reset. |
seed | The 32-bit seed to alter the hash result predictably. |
Returns | XXH_OK on success, XXH_ERROR on failure. |
This function resets and seeds a state. Call it before XXH32_
XXH_PUBLIC_API XXH_errorcode XXH32_update(XXH32_ state_ t* statePtr,
const void* input,
size_t length)
#include <eckit/contrib/xxhash/xxhash.h>
Consumes a block of input
to an XXH32_
Parameters | |
---|---|
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. |
Returns | XXH_OK on success, XXH_ERROR on failure. |
Call this to incrementally consume blocks of data.
XXH_PUBLIC_API XXH32_hash_t XXH32_digest(const XXH32_ state_ t* statePtr)
#include <eckit/contrib/xxhash/xxhash.h>
Returns the calculated hash value from an XXH32_
Parameters | |
---|---|
statePtr | The state struct to calculate the hash from. |
Returns | The calculated xxHash32 value from that state. |
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_ canonical_ t* dst,
XXH32_hash_t hash)
#include <eckit/contrib/xxhash/xxhash.h>
Converts an XXH32_hash_t to a big endian XXH32_
Parameters | |
---|---|
dst | The XXH32_ |
hash | The XXH32_hash_t to be converted. |
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_ canonical_ t* src)
#include <eckit/contrib/xxhash/xxhash.h>
Converts an XXH32_
Parameters | |
---|---|
src | The XXH32_ |
Returns | The converted hash. |