### Example: Using XXH3_generateSecret and XXH3_64bits_withSecret Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html This example hashes a command-line argument using a secret derived from another argument. It includes the necessary headers, defines XXH_STATIC_LINKING_ONLY to expose the unstable API, and prints the resulting 64-bit hash in hexadecimal. The secret is generated with XXH3_generateSecret and used with XXH3_64bits_withSecret. ```c #include #include #include #define XXH_STATIC_LINKING_ONLY // expose unstable API #include "xxhash.h" // Hashes argv[2] using the entropy from argv[1]. int main(int argc, char* argv[]) { char secret[XXH3_SECRET_SIZE_MIN]; if (argv != 3) { return 1; } XXH3_generateSecret(secret, sizeof(secret), argv[1], strlen(argv[1])); XXH64_hash_t h = XXH3_64bits_withSecret( argv[2], strlen(argv[2]), secret, sizeof(secret) ); printf("%016llx\n", (unsigned long long) h); } ``` -------------------------------- ### C++ std::string hash class using XXH3_generateSecret_fromSeed Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Example C++ std::string hash class using XXH3_generateSecret_fromSeed to cache the seeded secret for faster hashing. Requires XXH_STATIC_LINKING_ONLY to expose the unstable API. The HashSlow class seeds each time with XXH3_64bits_withSeed, while HashFast generates the secret once and reuses it with XXH3_64bits_withSecret. ```cpp #include #define XXH_STATIC_LINKING_ONLY // expose unstable API #include "xxhash.h" // Slow, seeds each time class HashSlow { XXH64_hash_t seed; public: HashSlow(XXH64_hash_t s) : seed{s} {} size_t operator()(const std::string& x) const { return size_t{XXH3_64bits_withSeed(x.c_str(), x.length(), seed)}; } }; // Fast, caches the seeded secret for future uses. class HashFast { unsigned char secret[XXH3_SECRET_DEFAULT_SIZE]; public: HashFast(XXH64_hash_t s) { XXH3_generateSecret_fromSeed(secret, seed); } size_t operator()(const std::string& x) const { return size_t{ XXH3_64bits_withSecret(x.c_str(), x.length(), secret, sizeof(secret)) }; } }; ``` -------------------------------- ### XXH32_freeState function definition (partial) Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Starts the definition of XXH32_freeState, which frees a previously created state. The code is truncated in the source at the point shown. ```c XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr) { ``` -------------------------------- ### XXH_NAMESPACE Source: https://xxhash.com/doc/v0.8.4/group__public.html Macro to emulate a namespace by prefixing all public symbols. ```APIDOC ## [MACRO] XXH_NAMESPACE ### Description Emulate a namespace by transparently prefixing all symbols. If you want to include and expose xxHash functions from within your own library, but also want to avoid symbol collisions with other libraries which may also include xxHash, you can use XXH_NAMESPACE to automatically prefix any public symbol from xxhash library with the value of XXH_NAMESPACE (therefore, avoid empty or numeric values). ### Macro XXH_NAMESPACE ### Parameters - **YOUR NAME HERE** (string) - Required - The namespace prefix to apply to all public symbols. ### Usage Example ```c #define XXH_NAMESPACE MY_NAMESPACE_ #include "xxhash.h" ``` ``` -------------------------------- ### XXH3_digest_long start Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Beginning of XXH3_digest_long, which processes the final stripe for long inputs. Declares a local buffer for the last stripe and a pointer to it. ```c XXH_FORCE_INLINE void XXH3_digest_long (XXH64_hash_t* acc, const XXH3_state_t* state, const unsigned char* secret) { xxh_u8 lastStripe[XXH_STRIPE_LEN]; const xxh_u8* lastStripePtr; ``` -------------------------------- ### XXH_INLINE_ALL Source: https://xxhash.com/doc/v0.8.4/group__public.html Exposes the implementation and marks all functions as inline. ```APIDOC ## XXH_INLINE_ALL ### Description Exposes the implementation and marks all functions as `inline`. Use these build macros to inline xxhash into the target unit. Inlining improves performance on small inputs, especially when the length is expressed as a compile-time constant. It also keeps xxHash symbols private to the unit, so they are not exported. ### Usage ```c #define XXH_INLINE_ALL #include "xxhash.h" ``` ### Note Do not compile and link xxhash.o as a separate object, as it is not useful. ``` -------------------------------- ### XXH64_initAccs: initialize accumulators Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Initializes the accumulator array for XXH64 with the seed and prime constants. The snippet is truncated in the source; it shows the first three accumulator assignments. ```c XXH_FORCE_INLINE void XXH64_initAccs(xxh_u64 *acc, xxh_u64 seed) { XXH_ASSERT(acc != NULL); acc[0] = seed + XXH_PRIME64_1 + XXH_PRIME64_2; acc[1] = seed + XXH_PRIME64_2; acc[2] = seed + 0; ``` -------------------------------- ### XXH_IMPLEMENTATION Source: https://xxhash.com/doc/v0.8.4/group__public.html Gives access to internal definitions. ```APIDOC ## XXH_IMPLEMENTATION ### Description Gives access to internal definitions. ### Usage ```c #define XXH_STATIC_LINKING_ONLY #define XXH_IMPLEMENTATION #include "xxhash.h" ``` ``` -------------------------------- ### Print and convert XXH32 canonical hashes Source: https://xxhash.com/doc/v0.8.4/index.html Includes two functions: printXxh32 prints an XXH32_hash_t as lowercase hexadecimal using XXH32_canonicalFromHash, and convertCanonicalToXxh32 converts an XXH32_canonical_t back to a native hash using XXH32_hashFromCanonical. Requires including stdio.h and xxhash.h. ```c #include #include "xxhash.h" // Example for a function which prints XXH32_hash_t in human readable format void printXxh32(XXH32_hash_t hash) { XXH32_canonical_t cano; XXH32_canonicalFromHash(&cano, hash); size_t i; for(i = 0; i < sizeof(cano.digest); ++i) { printf("%02x", cano.digest[i]); } printf("\n"); } // Example for a function which converts XXH32_canonical_t to XXH32_hash_t XXH32_hash_t convertCanonicalToXxh32(XXH32_canonical_t cano) { XXH32_hash_t hash = XXH32_hashFromCanonical(&cano); return hash; } ``` -------------------------------- ### XXH3_64bits_update prototype Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Prototype/declaration of XXH3_64bits_update shown in the source as a one-line signature with ellipsis. ```c XXH3_64bits_update(XXH_NOESCAPE XXH3_state_t* state, XXH_NOESCAPE const void* input, size_t len) {…} ``` -------------------------------- ### Create XXH3 state with aligned allocation Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Implementation of XXH3_createState, which allocates a state with 64-byte alignment, initializes it, and returns the pointer or NULL on failure. ```C XXH_PUBLIC_API XXH3_state_t* XXH3_createState(void) { XXH3_state_t* const state = (XXH3_state_t*)XXH_alignedMalloc(sizeof(XXH3_state_t), 64); if (state==NULL) return NULL; XXH3_INITSTATE(state); return state; } ``` -------------------------------- ### XXH64_createState Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Allocates an XXH64_state_t. ```APIDOC ## XXH64_createState ### Description Allocates an XXH64_state_t. ### Function Signature XXH64_state_t* XXH64_createState(void) ### Parameters None. ### Return Value - **XXH64_state_t*** - A pointer to the allocated state, or NULL on failure. ``` -------------------------------- ### XXH64_update Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Consumes a block of `input` to an XXH64_state_t. ```APIDOC ## XXH64_update ### Description Consumes a block of `input` to an XXH64_state_t. ### Function Signature XXH_errorcode XXH64_update(XXH64_state_t *statePtr, const void *input, size_t length) ### Parameters - **statePtr** (XXH64_state_t*) - Required - The state to update. - **input** (const void*) - Required - The input data to consume. - **length** (size_t) - Required - The length of the input data. ### Return Value - **XXH_errorcode** - Error code indicating success or failure. ``` -------------------------------- ### XXH64_update Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Consumes a block of `input` to an XXH64_state_t. ```APIDOC ## XXH64_update ### Description Consumes a block of `input` to an XXH64_state_t. ### Method XXH64_update ### Signature XXH_errorcode XXH64_update(XXH64_state_t *statePtr, const void *input, size_t length) ### Parameters - **statePtr** (XXH64_state_t*) - Required - The state struct to update. - **input** (const void*) - Required - The block of data to be hashed, at least `length` bytes in size. - **length** (size_t) - Required - The length of `input`, in bytes. ### Returns - XXH_OK on success. - XXH_ERROR on failure. ### Precondition `statePtr` must not be `NULL`. The memory between `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_. ### Note Call this to incrementally consume blocks of data. ### See Also - Streaming Example ``` -------------------------------- ### XXH3_64bits_reset_withSeed() Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Resets an XXH3_state_t with a 64-bit seed to begin a new hash. This function must be called before XXH3_64bits_update(). ```APIDOC ## XXH3_64bits_reset_withSeed() ### Description Resets an XXH3_state_t with 64-bit seed to begin a new hash. ### Parameters - **statePtr** (XXH3_state_t *) - Required - The state struct to reset. - **seed** (XXH64_hash_t) - Required - The 64-bit seed to alter the hash result predictably. ### Precondition - `statePtr` must not be `NULL`. ### Returns - XXH_OK on success. - XXH_ERROR on failure. ### Note - This function resets `statePtr` and generate a secret from `seed`. - Call this function before XXH3_64bits_update(). - Digest will be equivalent to `XXH3_64bits_withSeed()`. ### See also - Streaming Example ``` -------------------------------- ### XXH3_128bits_withSeed() Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Documentation for the XXH3_128bits_withSeed function, which calculates a 128-bit seeded variant of the XXH3 hash. ```APIDOC ## XXH3_128bits_withSeed() ### Description Calculates the 128-bit seeded variant of the XXH3 hash of `data`. This variant generates a custom secret on the fly based on the default secret altered using the `seed` value. While this operation is decently fast, note that it's not completely free. ### Method Function ### Signature ```c XXH128_hash_t XXH3_128bits_withSeed(const void *data, size_t len, XXH64_hash_t seed); ``` ### Parameters - **data** (const void*) - Required - The block of data to be hashed, at least `len` bytes in size. - **len** (size_t) - Required - The length of `data`, in bytes. - **seed** (XXH64_hash_t) - Required - The 64-bit seed to alter the hash result predictably. ### Returns - **XXH128_hash_t** - The calculated 128-bit variant of XXH3 value. ### Notes - `seed == 0` produces the same results as `XXH3_64bits()`. - This variant generates a custom secret on the fly based on default secret altered using the `seed` value. ### See Also - `XXH3_128bits()` - `XXH3_128bits_withSecret()` - Single Shot Example ``` -------------------------------- ### XXH32_createState() Source: https://xxhash.com/doc/v0.8.4/group___x_x_h32__family.html Allocates an XXH32_state_t. ```APIDOC ## XXH32_createState() ### Description Allocates an XXH32_state_t. ### Method Function ### Signature ```c XXH32_state_t *XXH32_createState(void) ``` ### Returns An allocated pointer of XXH32_state_t on success. `NULL` on failure. ### Note Must be freed with XXH32_freeState(). ### See Also Streaming Example ``` -------------------------------- ### XXH64 Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html One-shot XXH64 hash function. ```APIDOC ## XXH64 ### Description Computes the 64-bit XXH64 hash of the input data with a given seed. ### Function Signature `XXH_PUBLIC_API XXH_PUREF XXH64_hash_t XXH64(XXH_NOESCAPE const void* input, size_t length, XXH64_hash_t seed);` ### Parameters - **input** (const void*) - Required - Pointer to the data to hash. - **length** (size_t) - Required - Length of the input data in bytes. - **seed** (XXH64_hash_t) - Required - Seed value for the hash. ### Return Value - **XXH64_hash_t** - The 64-bit hash value. ``` -------------------------------- ### Streaming XXH3_64bits hash of a FILE Source: https://xxhash.com/doc/v0.8.4/index.html Streaming hashing of a file with XXH3_64bits(). Must allocate the state with XXH3_createState and free it with XXH3_freeState; do not use malloc/new or free(). Update can be called repeatedly, and digest can be called multiple times without resetting. Slower than single-shot; prefer XXH32/XXH64 for small inputs. ```c #include #include #include "xxhash.h" // Example for a function which hashes a FILE incrementally with XXH3_64bits(). XXH64_hash_t hashFile(FILE* f) { // Allocate a state struct. Do not just use malloc() or new. XXH3_state_t* state = XXH3_createState(); assert(state != NULL && "Out of memory!"); // Reset the state to start a new hashing session. XXH3_64bits_reset(state); char buffer[4096]; size_t count; // Read the file in chunks while ((count = fread(buffer, 1, sizeof(buffer), f)) != 0) { // Run update() as many times as necessary to process the data XXH3_64bits_update(state, buffer, count); } // Retrieve the finalized hash. This will not change the state. XXH64_hash_t result = XXH3_64bits_digest(state); // Free the state. Do not use free(). XXH3_freeState(state); return result; } ``` -------------------------------- ### XXH3 Hash Functions Source: https://xxhash.com/doc/v0.8.4/xxhash_8h.html This code snippet provides structured API documentation for the XXH3 hash functions, including reset, update, digest, and one-shot variants for both 64-bit and 128-bit hashes, as well as utility functions for secret generation and hash comparison. ```APIDOC ## XXH3_64bits_reset ### Description Resets an XXH3_state_t to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_64bits_reset(XXH3_state_t *statePtr) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_64bits_reset_withSeed ### Description Resets an XXH3_state_t with 64-bit seed to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_64bits_reset_withSeed(XXH3_state_t *statePtr, XXH64_hash_t seed) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **seed** (XXH64_hash_t) - Required - Seed value for the hash. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_64bits_reset_withSecret ### Description Resets an XXH3_state_t with secret data to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_64bits_reset_withSecret(XXH3_state_t *statePtr, const void *secret, size_t secretSize) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_64bits_update ### Description Consumes a block of `input` to an XXH3_state_t. ### Method Function ### Signature XXH_errorcode XXH3_64bits_update(XXH3_state_t *statePtr, const void *input, size_t length) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to update. - **input** (const void*) - Required - Input data to hash. - **length** (size_t) - Required - Length of the input data. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_64bits_digest ### Description Returns the calculated XXH3 64-bit hash value from an XXH3_state_t. ### Method Function ### Signature XXH64_hash_t XXH3_64bits_digest(const XXH3_state_t *statePtr) ### Parameters - **statePtr** (const XXH3_state_t*) - Required - Pointer to the state to digest. ### Return Value XXH64_hash_t - The calculated 64-bit hash value. ``` ```APIDOC ## XXH3_128bits ### Description Calculates 128-bit unseeded variant of XXH3 of `data`. ### Method Function ### Signature XXH128_hash_t XXH3_128bits(const void *data, size_t len) ### Parameters - **data** (const void*) - Required - Input data to hash. - **len** (size_t) - Required - Length of the input data. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH3_128bits_withSeed ### Description Calculates 128-bit seeded variant of XXH3 hash of `data`. ### Method Function ### Signature XXH128_hash_t XXH3_128bits_withSeed(const void *data, size_t len, XXH64_hash_t seed) ### Parameters - **data** (const void*) - Required - Input data to hash. - **len** (size_t) - Required - Length of the input data. - **seed** (XXH64_hash_t) - Required - Seed value for the hash. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH3_128bits_withSecret ### Description Calculates 128-bit variant of XXH3 with a custom "secret". ### Method Function ### Signature XXH128_hash_t XXH3_128bits_withSecret(const void *data, size_t len, const void *secret, size_t secretSize) ### Parameters - **data** (const void*) - Required - Input data to hash. - **len** (size_t) - Required - Length of the input data. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH3_128bits_reset ### Description Resets an XXH3_state_t to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_128bits_reset(XXH3_state_t *statePtr) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_128bits_reset_withSeed ### Description Resets an XXH3_state_t with 64-bit seed to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_128bits_reset_withSeed(XXH3_state_t *statePtr, XXH64_hash_t seed) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **seed** (XXH64_hash_t) - Required - Seed value for the hash. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_128bits_reset_withSecret ### Description Resets an XXH3_state_t with secret data to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_128bits_reset_withSecret(XXH3_state_t *statePtr, const void *secret, size_t secretSize) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_128bits_update ### Description Consumes a block of `input` to an XXH3_state_t. ### Method Function ### Signature XXH_errorcode XXH3_128bits_update(XXH3_state_t *statePtr, const void *input, size_t length) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to update. - **input** (const void*) - Required - Input data to hash. - **length** (size_t) - Required - Length of the input data. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_128bits_digest ### Description Returns the calculated XXH3 128-bit hash value from an XXH3_state_t. ### Method Function ### Signature XXH128_hash_t XXH3_128bits_digest(const XXH3_state_t *statePtr) ### Parameters - **statePtr** (const XXH3_state_t*) - Required - Pointer to the state to digest. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH128_isEqual ### Description Check equality of two XXH128_hash_t values. ### Method Function ### Signature int XXH128_isEqual(XXH128_hash_t h1, XXH128_hash_t h2) ### Parameters - **h1** (XXH128_hash_t) - Required - First hash value. - **h2** (XXH128_hash_t) - Required - Second hash value. ### Return Value int - Non-zero if equal, zero otherwise. ``` ```APIDOC ## XXH128_cmp ### Description Compares two XXH128_hash_t. ### Method Function ### Signature int XXH128_cmp(const void *h128_1, const void *h128_2) ### Parameters - **h128_1** (const void*) - Required - Pointer to first hash. - **h128_2** (const void*) - Required - Pointer to second hash. ### Return Value int - Comparison result (negative, zero, or positive). ``` ```APIDOC ## XXH128_canonicalFromHash ### Description Converts an XXH128_hash_t to a big endian XXH128_canonical_t. ### Method Function ### Signature void XXH128_canonicalFromHash(XXH128_canonical_t *dst, XXH128_hash_t hash) ### Parameters - **dst** (XXH128_canonical_t*) - Required - Destination for canonical representation. - **hash** (XXH128_hash_t) - Required - Hash value to convert. ### Return Value void - No return value. ``` ```APIDOC ## XXH128_hashFromCanonical ### Description Converts an XXH128_canonical_t to a native XXH128_hash_t. ### Method Function ### Signature XXH128_hash_t XXH128_hashFromCanonical(const XXH128_canonical_t *src) ### Parameters - **src** (const XXH128_canonical_t*) - Required - Canonical representation to convert. ### Return Value XXH128_hash_t - The native hash value. ``` ```APIDOC ## XXH128 ### Description Calculates the 128-bit hash of `data` using XXH3. ### Method Function ### Signature XXH128_hash_t XXH128(const void *data, size_t len, XXH64_hash_t seed) ### Parameters - **data** (const void*) - Required - Input data to hash. - **len** (size_t) - Required - Length of the input data. - **seed** (XXH64_hash_t) - Required - Seed value for the hash. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH3_generateSecret ### Description Derive a high-entropy secret from any user-defined content, named customSeed. ### Method Function ### Signature XXH_errorcode XXH3_generateSecret(void *secretBuffer, size_t secretSize, const void *customSeed, size_t customSeedSize) ### Parameters - **secretBuffer** (void*) - Required - Buffer to store the generated secret. - **secretSize** (size_t) - Required - Size of the secret buffer. - **customSeed** (const void*) - Required - User-defined content to derive the secret. - **customSeedSize** (size_t) - Required - Size of the custom seed. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_generateSecret_fromSeed ### Description Generate the same secret as the _withSeed() variants. ### Method Function ### Signature void XXH3_generateSecret_fromSeed(void *secretBuffer, XXH64_hash_t seed) ### Parameters - **secretBuffer** (void*) - Required - Buffer to store the generated secret. - **seed** (XXH64_hash_t) - Required - Seed value. ### Return Value void - No return value. ``` ```APIDOC ## XXH3_64bits_withSecretandSeed ### Description Calculates 64/128-bit seeded variant of XXH3 hash of `data`. ### Method Function ### Signature XXH64_hash_t XXH3_64bits_withSecretandSeed(const void *data, size_t len, const void *secret, size_t secretSize, XXH64_hash_t seed) ### Parameters - **data** (const void*) - Required - Input data to hash. - **len** (size_t) - Required - Length of the input data. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. - **seed** (XXH64_hash_t) - Required - Seed value. ### Return Value XXH64_hash_t - The calculated 64-bit hash value. ``` ```APIDOC ## XXH3_128bits_withSecretandSeed ### Description Calculates 128-bit seeded variant of XXH3 hash of `data`. ### Method Function ### Signature XXH128_hash_t XXH3_128bits_withSecretandSeed(const void *input, size_t length, const void *secret, size_t secretSize, XXH64_hash_t seed64) ### Parameters - **input** (const void*) - Required - Input data to hash. - **length** (size_t) - Required - Length of the input data. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. - **seed64** (XXH64_hash_t) - Required - Seed value. ### Return Value XXH128_hash_t - The calculated 128-bit hash value. ``` ```APIDOC ## XXH3_64bits_reset_withSecretandSeed ### Description Resets an XXH3_state_t with secret data to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_64bits_reset_withSecretandSeed(XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. - **seed64** (XXH64_hash_t) - Required - Seed value. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` ```APIDOC ## XXH3_128bits_reset_withSecretandSeed ### Description Resets an XXH3_state_t with secret data to begin a new hash. ### Method Function ### Signature XXH_errorcode XXH3_128bits_reset_withSecretandSeed(XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64) ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to reset. - **secret** (const void*) - Required - Secret data used for hashing. - **secretSize** (size_t) - Required - Size of the secret data. - **seed64** (XXH64_hash_t) - Required - Seed value. ### Return Value XXH_errorcode - Error code indicating success or failure. ``` -------------------------------- ### XXH64 Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Calculates the 64-bit hash of `input` using xxHash64. ```APIDOC ## XXH64 ### Description Calculates the 64-bit hash of `input` using xxHash64. ### Function Signature XXH64_hash_t XXH64(const void *input, size_t length, XXH64_hash_t seed) ### Parameters - **input** (const void*) - Required - The input data to hash. - **length** (size_t) - Required - The length of the input data. - **seed** (XXH64_hash_t) - Required - The seed value for the hash. ### Return Value - **XXH64_hash_t** - The 64-bit hash value. ``` -------------------------------- ### XXH64 prime constants and old names Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Defines the five XXH64 prime constants as macros (so they can be used as initializers) and provides old-style names when XXH_OLD_NAMES is defined. ```c #define XXH_PRIME64_1 0x9E3779B185EBCA87ULL #define XXH_PRIME64_2 0xC2B2AE3D27D4EB4FULL #define XXH_PRIME64_3 0x165667B19E3779F9ULL #define XXH_PRIME64_4 0x85EBCA77C2B2AE63ULL #define XXH_PRIME64_5 0x27D4EB2F165667C5ULL ``` ```c #ifdef XXH_OLD_NAMES # define PRIME64_1 XXH_PRIME64_1 # define PRIME64_2 XXH_PRIME64_2 # define PRIME64_3 XXH_PRIME64_3 # define PRIME64_4 XXH_PRIME64_4 # define PRIME64_5 XXH_PRIME64_5 #endif ``` -------------------------------- ### XXH3_64bits_update Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Updates the XXH3 64-bit streaming state with new input data. ```APIDOC ## XXH3_64bits_update ### Description Updates the XXH3 64-bit streaming state with new input data. ### Method Function call ### Signature `XXH_PUBLIC_API XXH_errorcode XXH3_64bits_update (XXH_NOESCAPE XXH3_state_t* statePtr, XXH_NOESCAPE const void* input, size_t length);` ### Parameters - **statePtr** (XXH3_state_t*) - Required - Pointer to the state to update. - **input** (const void*) - Required - Pointer to the input data. - **length** (size_t) - Required - Length of the input data. ### Return Value - **XXH_errorcode** - Error code indicating success or failure. ``` -------------------------------- ### Single-shot XXH32 hash of a null-terminated string Source: https://xxhash.com/doc/v0.8.4/index.html Single-shot hashing of a null-terminated string with XXH32(). Requires the input range to be valid, readable memory; NULL pointer is allowed only when length is zero. Replacement of XXH32 with XXH64 or XXH3 variants is a trivial substitution. ```c #include #include "xxhash.h" // Example for a function which hashes a null terminated string with XXH32(). XXH32_hash_t hash_string(const char* string, XXH32_hash_t seed) { // NULL pointers are only valid if the length is zero size_t length = (string == NULL) ? 0 : strlen(string); return XXH32(string, length, seed); } ``` -------------------------------- ### XXH64_reset Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Resets an XXH64_state_t to begin a new hash. ```APIDOC ## XXH64_reset ### Description Resets an XXH64_state_t to begin a new hash. ### Function Signature XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, XXH64_hash_t seed) ### Parameters - **statePtr** (XXH64_state_t*) - Required - The state to reset. - **seed** (XXH64_hash_t) - Required - The seed value for the new hash. ### Return Value - **XXH_errorcode** - Error code indicating success or failure. ``` -------------------------------- ### XXH64_reset Source: https://xxhash.com/doc/v0.8.4/group___x_x_h64__family.html Resets an XXH64_state_t to begin a new hash. ```APIDOC ## XXH64_reset ### Description Resets an XXH64_state_t to begin a new hash. ### Method XXH64_reset ### Signature XXH_errorcode XXH64_reset(XXH64_state_t *statePtr, XXH64_hash_t seed) ### Parameters - **statePtr** (XXH64_state_t*) - Required - The state struct to reset. - **seed** (XXH64_hash_t) - Required - The 64-bit seed to alter the hash result predictably. ### Returns - XXH_OK on success. - XXH_ERROR on failure. ### Precondition `statePtr` must not be `NULL`. ### Note This function resets and seeds a state. Call it before XXH64_update(). ### See Also - Streaming Example ``` -------------------------------- ### XXH3_64bits_reset_withSeed Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Resets an XXH3_state_t with a 64-bit seed to begin a new hash. ```APIDOC ## XXH3_64bits_reset_withSeed ### Description Resets an XXH3_state_t with 64-bit seed to begin a new hash. ### Function Signature `XXH_errorcode XXH3_64bits_reset_withSeed(XXH3_state_t *statePtr, XXH64_hash_t seed)` ### Parameters - **statePtr** (XXH3_state_t*) - Pointer to the state to reset. - **seed** (XXH64_hash_t) - The seed value. ### Returns - **XXH_errorcode** - Error code indicating success or failure. ``` -------------------------------- ### XXH32_createState Source: https://xxhash.com/doc/v0.8.4/xxhash_8h.html Creates a new XXH32 streaming state. ```APIDOC ## XXH32_createState ### Description Allocates an XXH32_state_t. ### Method Function ### Signature `XXH32_state_t *XXH32_createState(void)` ### Parameters None. ### Returns - **XXH32_state_t*** - Pointer to the newly allocated state, or NULL on failure. ``` -------------------------------- ### Copy XXH3 state with memcpy Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Implementation of XXH3_copyState, which copies the source state to the destination using XXH_memcpy. ```C XXH_PUBLIC_API void XXH3_copyState(XXH_NOESCAPE XXH3_state_t* dst_state, XXH_NOESCAPE const XXH3_state_t* src_state) { XXH_memcpy(dst_state, src_state, sizeof(*dst_state)); } ``` -------------------------------- ### XXH3_len_9to16_128b: Hash 9-16 byte inputs Source: https://xxhash.com/doc/v0.8.4/xxhash_8h_source.html Internal function for hashing inputs of length 9 to 16 bytes. Uses bitflip values, a 128x64 multiply, and platform-specific optimizations for 32-bit and 64-bit to produce a 128-bit hash. ```c XXH_FORCE_INLINE XXH_PUREF XXH128_hash_t XXH3_len_9to16_128b(const xxh_u8* input, size_t len, const xxh_u8* secret, XXH64_hash_t seed) { XXH_ASSERT(input != NULL); XXH_ASSERT(secret != NULL); XXH_ASSERT(9 <= len && len <= 16); { xxh_u64 const bitflipl = (XXH_readLE64(secret+32) ^ XXH_readLE64(secret+40)) - seed; xxh_u64 const bitfliph = (XXH_readLE64(secret+48) ^ XXH_readLE64(secret+56)) + seed; xxh_u64 const input_lo = XXH_readLE64(input); xxh_u64 input_hi = XXH_readLE64(input + len - 8); XXH128_hash_t m128 = XXH_mult64to128(input_lo ^ input_hi ^ bitflipl, XXH_PRIME64_1); /* * Put len in the middle of m128 to ensure that the length gets mixed to * both the low and high bits in the 128x64 multiply below. */ m128.low64 += (xxh_u64)(len - 1) << 54; input_hi ^= bitfliph; /* * Add the high 32 bits of input_hi to the high 32 bits of m128, then * add the long product of the low 32 bits of input_hi and XXH_PRIME32_2 to * the high 64 bits of m128. * * The best approach to this operation is different on 32-bit and 64-bit. */ if (sizeof(void *) < sizeof(xxh_u64)) { /* 32-bit */ /* * 32-bit optimized version, which is more readable. * * On 32-bit, it removes an ADC and delays a dependency between the two * halves of m128.high64, but it generates an extra mask on 64-bit. */ m128.high64 += (input_hi & 0xFFFFFFFF00000000ULL) + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2); } else { /* * 64-bit optimized (albeit more confusing) version. * * Uses some properties of addition and multiplication to remove the mask: * * Let: * a = input_hi.lo = (input_hi & 0x00000000FFFFFFFF) * b = input_hi.hi = (input_hi & 0xFFFFFFFF00000000) * c = XXH_PRIME32_2 * * a + (b * c) * Inverse Property: x + y - x == y * a + (b * (1 + c - 1)) * Distributive Property: x * (y + z) == (x * y) + (x * z) * a + (b * 1) + (b * (c - 1)) * Identity Property: x * 1 == x * a + b + (b * (c - 1)) * * Substitute a, b, and c: * input_hi.hi + input_hi.lo + ((xxh_u64)input_hi.lo * (XXH_PRIME32_2 - 1)) * * Since input_hi.hi + input_hi.lo == input_hi, we get this: * input_hi + ((xxh_u64)input_hi.lo * (XXH_PRIME32_2 - 1)) */ m128.high64 += input_hi + XXH_mult32to64((xxh_u32)input_hi, XXH_PRIME32_2 - 1); } /* m128 ^= XXH_swap64(m128 >> 64); */ m128.low64 ^= XXH_swap64(m128.high64); { /* 128x64 multiply: h128 = m128 * XXH_PRIME64_2; */ XXH128_hash_t h128 = XXH_mult64to128(m128.low64, XXH_PRIME64_2); h128.high64 += m128.high64 * XXH_PRIME64_2; h128.low64 = XXH3_avalanche(h128.low64); h128.high64 = XXH3_avalanche(h128.high64); return h128; } } } ``` -------------------------------- ### XXH3_64bits_withSeed() Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Calculates the 64-bit seeded variant of the XXH3 hash of the input data. The seed alters the hash result predictably, and a seed of 0 produces the same results as XXH3_64bits(). ```APIDOC ## XXH3_64bits_withSeed() ### Description Calculates the 64-bit seeded variant of the XXH3 hash of `input`. The seed alters the hash result predictably, and a seed of 0 produces the same results as XXH3_64bits(). ### Function Signature ```c XXH64_hash_t XXH3_64bits_withSeed(const void *input, size_t length, XXH64_hash_t seed); ``` ### Parameters - **input** (const void*) - The block of data to be hashed, at least `length` bytes in size. If `length` is 0, `input` may be NULL. - **length** (size_t) - The length of `input`, in bytes. - **seed** (XXH64_hash_t) - The 64-bit seed to alter the hash result predictably. ### Preconditions The memory between `input` and `input` + `length` must be valid, readable, contiguous memory. If `length` is 0, `input` may be NULL. In C++, the data must also be _TriviallyCopyable_. ### Returns The calculated 64-bit XXH3 hash value. ### Notes - `seed == 0` produces the same results as `XXH3_64bits()`. - This variant generates a custom secret on the fly based on the default secret altered using the `seed` value. While this operation is decently fast, it is not completely free. ### See Also - Single Shot Example for an example. ``` -------------------------------- ### XXH3_64bits_update Source: https://xxhash.com/doc/v0.8.4/group___x_x_h3__family.html Consumes a block of input to an XXH3_state_t. ```APIDOC ## XXH3_64bits_update ### Description Consumes a block of `input` to an XXH3_state_t. ### Function Signature `XXH_errorcode XXH3_64bits_update(XXH3_state_t *statePtr, const void *input, size_t length)` ### Parameters - **statePtr** (XXH3_state_t*) - Pointer to the state. - **input** (const void*) - Pointer to the data to consume. - **length** (size_t) - Length of the data in bytes. ### Returns - **XXH_errorcode** - Error code indicating success or failure. ```