xxHash  0.8.2
Extremely fast non-cryptographic hash function
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
xxhash.h File Reference
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

Go to the source code of this file.

Data Structures

struct  XXH32_canonical_t
 Canonical (big endian) representation of XXH32_hash_t. More...
 
struct  XXH64_canonical_t
 Canonical (big endian) representation of XXH64_hash_t. More...
 
struct  XXH128_hash_t
 The return value from 128-bit hashes. More...
 
struct  XXH128_canonical_t
 
struct  XXH32_state_s
 
struct  XXH64_state_s
 
struct  XXH3_state_s
 

Macros

#define XXH_STATIC_LINKING_ONLY
 Gives access to internal state declaration, required for static allocation. More...
 
#define XXH_IMPLEMENTATION
 Gives access to internal definitions. More...
 
#define XXH_INLINE_ALL
 Exposes the implementation and marks all functions as inline. More...
 
#define XXH_PRIVATE_API
 Exposes the implementation without marking functions as inline.
 
#define XXH_NAMESPACE   /* YOUR NAME HERE */
 Emulate a namespace by transparently prefixing all symbols. More...
 
#define XXHASH_H_5627135585666179   1
 
#define XXH_PUBLIC_API   /* do nothing */
 Marks a global symbol.
 
#define XXH_PUBLIC_API   /* do nothing */
 Marks a global symbol.
 
#define XXH_CONSTF   /* disable */
 
#define XXH_PUREF
 
#define XXH_MALLOCF
 
#define XXH_VERSION_MAJOR   0
 
#define XXH_VERSION_MINOR   8
 
#define XXH_VERSION_RELEASE   3
 
#define XXH_VERSION_NUMBER   (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
 Version number, encoded as two digits each.
 
#define XXH_SCALAR   0
 Possible values for XXH_VECTOR. More...
 
#define XXH_SSE2   1
 
#define XXH_AVX2   2
 
#define XXH_AVX512   3
 
#define XXH_NEON   4
 
#define XXH_VSX   5
 
#define XXH_SVE   6
 
#define XXH_LSX   7
 
#define XXH3_SECRET_SIZE_MIN   136
 
#define XXHASH_H_STATIC_13879238742
 
#define XXH_ALIGN(n)   /* disabled */
 
#define XXH_ALIGN_MEMBER(align, type)   XXH_ALIGN(align) type
 
#define XXH3_INTERNALBUFFER_SIZE   256
 The size of the internal XXH3 buffer. More...
 
#define XXH3_SECRET_DEFAULT_SIZE   192
 
#define XXH3_INITSTATE(XXH3_state_ptr)
 Initializes a stack-allocated XXH3_state_s. More...
 
#define XXH3_MIDSIZE_MAX   240
 Maximum size of "short" key in bytes.
 
#define XXH_IMPLEM_13a8737387
 
#define XXH_NO_LONG_LONG
 Define this to disable 64-bit code. More...
 
#define XXH_FORCE_MEMORY_ACCESS   0
 Controls how unaligned memory is accessed. More...
 
#define XXH_SIZE_OPT   0
 Controls how much xxHash optimizes for size. More...
 
#define XXH_FORCE_ALIGN_CHECK   0
 If defined to non-zero, adds a special path for aligned inputs (XXH32() and XXH64() only). More...
 
#define XXH_NO_INLINE_HINTS   0
 When non-zero, sets all functions to static. More...
 
#define XXH3_INLINE_SECRET   0
 Determines whether to inline the XXH3 withSecret code. More...
 
#define XXH32_ENDJMP   0
 Whether to use a jump for XXH32_finalize. More...
 
#define XXH_OLD_NAMES
 
#define XXH_NO_STREAM
 Disables the streaming API. More...
 
#define XXH_FORCE_INLINE   static
 
#define XXH_NO_INLINE   static
 
#define XXH_STATIC   static
 
#define XXH3_WITH_SECRET_INLINE   XXH_NO_INLINE
 
#define XXH_RESTRICT   /* disable */
 
#define XXH_DEBUGLEVEL   0
 Sets the debugging level. More...
 
#define XXH_ASSERT(c)   XXH_ASSUME(c)
 
#define XXH_STATIC_ASSERT_WITH_MESSAGE(c, m)   do { struct xxh_sa { char x[(c) ? 1 : -1]; }; } while(0)
 
#define XXH_STATIC_ASSERT(c)   XXH_STATIC_ASSERT_WITH_MESSAGE((c),#c)
 
#define XXH_COMPILER_GUARD(var)   ((void)0)
 
#define XXH_COMPILER_GUARD_CLANG_NEON(var)   ((void)0)
 
#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()
 Whether the target is little endian. More...
 
#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define XXH_HAS_BUILTIN(x)   0
 
#define XXH_UNREACHABLE()
 
#define XXH_ASSUME(c)   if (!(c)) { XXH_UNREACHABLE(); }
 
#define XXH_rotl32(x, r)   (((x) << (r)) | ((x) >> (32 - (r))))
 
#define XXH_rotl64(x, r)   (((x) << (r)) | ((x) >> (64 - (r))))
 
#define XXH_PRIME32_1   0x9E3779B1U
 
#define XXH_PRIME32_2   0x85EBCA77U
 
#define XXH_PRIME32_3   0xC2B2AE3DU
 
#define XXH_PRIME32_4   0x27D4EB2FU
 
#define XXH_PRIME32_5   0x165667B1U
 
#define XXH_get32bits(p)   XXH_readLE32_align(p, align)
 
#define XXH_PROCESS1
 
#define XXH_PROCESS4
 
#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
 
#define XXH_get64bits(p)   XXH_readLE64_align(p, align)
 
#define XXH_likely(x)   (x)
 
#define XXH_unlikely(x)   (x)
 
#define XXH_HAS_INCLUDE(x)   0
 
#define XXH_VECTOR   XXH_SCALAR
 Overrides the vectorization implementation chosen for XXH3. More...
 
#define XXH_ACC_ALIGN   8
 Selects the minimum alignment for XXH3's accumulators. More...
 
#define XXH_SEC_ALIGN   8
 
#define XXH_ALIASING   /* nothing */
 
#define XXH_PREFETCH(ptr)   (void)(ptr) /* disabled */
 
#define XXH_SECRET_DEFAULT_SIZE   192 /* minimum XXH3_SECRET_SIZE_MIN */
 
#define XXH3_MIDSIZE_STARTOFFSET   3
 
#define XXH3_MIDSIZE_LASTOFFSET   17
 
#define XXH_STRIPE_LEN   64
 
#define XXH_SECRET_CONSUME_RATE   8 /* nb of secret bytes consumed at each accumulation */
 
#define XXH_ACC_NB   (XXH_STRIPE_LEN / sizeof(xxh_u64))
 
#define XXH_PREFETCH_DIST   384
 
#define XXH3_ACCUMULATE_TEMPLATE(name)
 
#define XXH3_accumulate_512   XXH3_accumulate_512_scalar
 
#define XXH3_accumulate   XXH3_accumulate_scalar
 
#define XXH3_scrambleAcc   XXH3_scrambleAcc_scalar
 
#define XXH3_initCustomSecret   XXH3_initCustomSecret_scalar
 
#define XXH_SECRET_LASTACC_START   7 /* not aligned on 8, last secret is different from acc & scrambler */
 
#define XXH_SECRET_MERGEACCS_START   11
 
#define XXH3_INIT_ACC
 
#define XXH3_STREAM_USE_STACK   1
 
#define XXH3_INTERNALBUFFER_STRIPES   (XXH3_INTERNALBUFFER_SIZE / XXH_STRIPE_LEN)
 
#define XXH_MIN(x, y)   (((x) > (y)) ? (y) : (x))
 

Typedefs

typedef uint32_t XXH32_hash_t
 An unsigned 32-bit integer. More...
 
typedef struct XXH32_state_s XXH32_state_t
 The opaque state struct for the XXH32 streaming API. More...
 
typedef struct XXH64_state_s XXH64_state_t
 The opaque state struct for the XXH64 streaming API. More...
 
typedef struct XXH3_state_s XXH3_state_t
 The opaque state struct for the XXH3 streaming API. More...
 
typedef unsigned char xxh_u8
 
typedef XXH32_hash_t xxh_u32
 
typedef long long xxh_i64
 
typedef void(* XXH3_f_accumulate) (xxh_u64 *restrict, const xxh_u8 *restrict, const xxh_u8 *restrict, size_t)
 
typedef void(* XXH3_f_scrambleAcc) (void *restrict, const void *)
 
typedef void(* XXH3_f_initCustomSecret) (void *restrict, xxh_u64)
 
typedef XXH64_hash_t(* XXH3_hashLong64_f) (const void *restrict, size_t, XXH64_hash_t, const xxh_u8 *restrict, size_t)
 
typedef XXH128_hash_t(* XXH3_hashLong128_f) (const void *restrict, size_t, XXH64_hash_t, const void *restrict, size_t)
 
typedef uint64_t XXH64_hash_t
 An unsigned 64-bit integer. More...
 

Enumerations

enum  XXH_errorcode { XXH_OK = 0 , XXH_ERROR }
 Exit code for the streaming API. More...
 
enum  XXH_alignment { XXH_aligned , XXH_unaligned }
 

Functions

unsigned XXH_versionNumber (void)
 Obtains the xxHash version. More...
 
XXH32_hash_t XXH32 (const void *input, size_t length, XXH32_hash_t seed)
 Calculates the 32-bit hash of input using xxHash32. More...
 
XXH32_state_tXXH32_createState (void)
 Allocates an XXH32_state_t. More...
 
XXH_errorcode XXH32_freeState (XXH32_state_t *statePtr)
 Frees an XXH32_state_t. More...
 
void XXH32_copyState (XXH32_state_t *dst_state, const XXH32_state_t *src_state)
 Copies one XXH32_state_t to another. More...
 
XXH_errorcode XXH32_reset (XXH32_state_t *statePtr, XXH32_hash_t seed)
 Resets an XXH32_state_t to begin a new hash. More...
 
XXH_errorcode XXH32_update (XXH32_state_t *statePtr, const void *input, size_t length)
 Consumes a block of input to an XXH32_state_t. More...
 
XXH32_hash_t XXH32_digest (const XXH32_state_t *statePtr)
 Returns the calculated hash value from an XXH32_state_t. More...
 
void XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash)
 Converts an XXH32_hash_t to a big endian XXH32_canonical_t. More...
 
XXH32_hash_t XXH32_hashFromCanonical (const XXH32_canonical_t *src)
 Converts an XXH32_canonical_t to a native XXH32_hash_t. More...
 
XXH64_hash_t XXH64 (const void *input, size_t length, XXH64_hash_t seed)
 Calculates the 64-bit hash of input using xxHash64. More...
 
XXH64_state_tXXH64_createState (void)
 Allocates an XXH64_state_t. More...
 
XXH_errorcode XXH64_freeState (XXH64_state_t *statePtr)
 Frees an XXH64_state_t. More...
 
void XXH64_copyState (XXH64_state_t *dst_state, const XXH64_state_t *src_state)
 Copies one XXH64_state_t to another. More...
 
XXH_errorcode XXH64_reset (XXH64_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH64_state_t to begin a new hash. More...
 
XXH_errorcode XXH64_update (XXH64_state_t *statePtr, const void *input, size_t length)
 Consumes a block of input to an XXH64_state_t. More...
 
XXH64_hash_t XXH64_digest (const XXH64_state_t *statePtr)
 Returns the calculated hash value from an XXH64_state_t. More...
 
void XXH64_canonicalFromHash (XXH64_canonical_t *dst, XXH64_hash_t hash)
 Converts an XXH64_hash_t to a big endian XXH64_canonical_t. More...
 
XXH64_hash_t XXH64_hashFromCanonical (const XXH64_canonical_t *src)
 Converts an XXH64_canonical_t to a native XXH64_hash_t. More...
 
XXH64_hash_t XXH3_64bits (const void *input, size_t length)
 Calculates 64-bit unseeded variant of XXH3 hash of input. More...
 
XXH64_hash_t XXH3_64bits_withSeed (const void *input, size_t length, XXH64_hash_t seed)
 Calculates 64-bit seeded variant of XXH3 hash of input. More...
 
XXH64_hash_t XXH3_64bits_withSecret (const void *data, size_t len, const void *secret, size_t secretSize)
 Calculates 64-bit variant of XXH3 with a custom "secret". More...
 
XXH3_state_tXXH3_createState (void)
 Allocate an XXH3_state_t. More...
 
XXH_errorcode XXH3_freeState (XXH3_state_t *statePtr)
 Frees an XXH3_state_t. More...
 
void XXH3_copyState (XXH3_state_t *dst_state, const XXH3_state_t *src_state)
 Copies one XXH3_state_t to another. More...
 
XXH_errorcode XXH3_64bits_reset (XXH3_state_t *statePtr)
 Resets an XXH3_state_t to begin a new hash. More...
 
XXH_errorcode XXH3_64bits_reset_withSeed (XXH3_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH3_state_t with 64-bit seed to begin a new hash. More...
 
XXH_errorcode XXH3_64bits_reset_withSecret (XXH3_state_t *statePtr, const void *secret, size_t secretSize)
 Resets an XXH3_state_t with secret data to begin a new hash. More...
 
XXH_errorcode XXH3_64bits_update (XXH3_state_t *statePtr, const void *input, size_t length)
 Consumes a block of input to an XXH3_state_t. More...
 
XXH64_hash_t XXH3_64bits_digest (const XXH3_state_t *statePtr)
 Returns the calculated XXH3 64-bit hash value from an XXH3_state_t. More...
 
XXH128_hash_t XXH3_128bits (const void *data, size_t len)
 Calculates 128-bit unseeded variant of XXH3 of data. More...
 
XXH128_hash_t XXH3_128bits_withSeed (const void *data, size_t len, XXH64_hash_t seed)
 Calculates 128-bit seeded variant of XXH3 hash of data. More...
 
XXH128_hash_t XXH3_128bits_withSecret (const void *data, size_t len, const void *secret, size_t secretSize)
 Calculates 128-bit variant of XXH3 with a custom "secret". More...
 
XXH_errorcode XXH3_128bits_reset (XXH3_state_t *statePtr)
 Resets an XXH3_state_t to begin a new hash. More...
 
XXH_errorcode XXH3_128bits_reset_withSeed (XXH3_state_t *statePtr, XXH64_hash_t seed)
 Resets an XXH3_state_t with 64-bit seed to begin a new hash. More...
 
XXH_errorcode XXH3_128bits_reset_withSecret (XXH3_state_t *statePtr, const void *secret, size_t secretSize)
 Resets an XXH3_state_t with secret data to begin a new hash. More...
 
XXH_errorcode XXH3_128bits_update (XXH3_state_t *statePtr, const void *input, size_t length)
 Consumes a block of input to an XXH3_state_t. More...
 
XXH128_hash_t XXH3_128bits_digest (const XXH3_state_t *statePtr)
 Returns the calculated XXH3 128-bit hash value from an XXH3_state_t. More...
 
int XXH128_isEqual (XXH128_hash_t h1, XXH128_hash_t h2)
 Check equality of two XXH128_hash_t values. More...
 
int XXH128_cmp (const void *h128_1, const void *h128_2)
 Compares two XXH128_hash_t. More...
 
void XXH128_canonicalFromHash (XXH128_canonical_t *dst, XXH128_hash_t hash)
 Converts an XXH128_hash_t to a big endian XXH128_canonical_t. More...
 
XXH128_hash_t XXH128_hashFromCanonical (const XXH128_canonical_t *src)
 Converts an XXH128_canonical_t to a native XXH128_hash_t. More...
 
XXH128_hash_t XXH128 (const void *data, size_t len, XXH64_hash_t seed)
 Calculates the 128-bit hash of data using XXH3. More...
 
XXH_errorcode XXH3_generateSecret (void *secretBuffer, size_t secretSize, const void *customSeed, size_t customSeedSize)
 Derive a high-entropy secret from any user-defined content, named customSeed. More...
 
void XXH3_generateSecret_fromSeed (void *secretBuffer, XXH64_hash_t seed)
 Generate the same secret as the _withSeed() variants. More...
 
XXH64_hash_t XXH3_64bits_withSecretandSeed (const void *data, size_t len, const void *secret, size_t secretSize, XXH64_hash_t seed)
 Calculates 64/128-bit seeded variant of XXH3 hash of data. More...
 
XXH128_hash_t XXH3_128bits_withSecretandSeed (const void *input, size_t length, const void *secret, size_t secretSize, XXH64_hash_t seed64)
 Calculates 128-bit seeded variant of XXH3 hash of data. More...
 
XXH_errorcode XXH3_64bits_reset_withSecretandSeed (XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64)
 Resets an XXH3_state_t with secret data to begin a new hash. More...
 
XXH_errorcode XXH3_128bits_reset_withSecretandSeed (XXH3_state_t *statePtr, const void *secret, size_t secretSize, XXH64_hash_t seed64)
 Resets an XXH3_state_t with secret data to begin a new hash. More...
 
XXH_STATIC xxh_u64 XXH64_finalize (xxh_u64 hash, const xxh_u8 *ptr, size_t len, XXH_alignment align)
 
 XXH_ASSERT ((((size_t) acc) &(XXH_ACC_ALIGN-1))==0)
 
 XXH_ASSERT (lane< XXH_ACC_NB)
 
XXH3_WITH_SECRET_INLINE XXH64_hash_t XXH3_hashLong_64b_withSecret (const void *restrict input, size_t len, XXH64_hash_t seed64, const xxh_u8 *restrict secret, size_t secretLen)
 
XXH3_WITH_SECRET_INLINE XXH128_hash_t XXH3_hashLong_128b_withSecret (const void *restrict input, size_t len, XXH64_hash_t seed64, const void *restrict secret, size_t secretLen)
 

Variables

static void const *restrict secret
 
static void const *restrict size_t lane
 
const xxh_u8 *const xsecret = (const xxh_u8*) secret
 
xxh_u64 acc64 = xacc[lane]
 
acc64 * xacc [lane] = acc64
 
typedef XXH64_hash_t xxh_u64
 

Detailed Description

xxHash prototypes and implementation

Macro Definition Documentation

◆ XXH3_INTERNALBUFFER_SIZE

#define XXH3_INTERNALBUFFER_SIZE   256

The size of the internal XXH3 buffer.

This is the optimal update size for incremental hashing.

See also
XXH3_64b_update(), XXH3_128b_update().

◆ XXH3_INITSTATE

#define XXH3_INITSTATE (   XXH3_state_ptr)
Value:
do { \
XXH3_state_t* tmp_xxh3_state_ptr = (XXH3_state_ptr); \
tmp_xxh3_state_ptr->seed = 0; \
tmp_xxh3_state_ptr->extSecret = NULL; \
} while(0)

Initializes a stack-allocated XXH3_state_s.

When the XXH3_state_t structure is merely emplaced on stack, it should be initialized with XXH3_INITSTATE() or a memset() in case its first reset uses XXH3_NNbits_reset_withSeed(). This init can be omitted if the first reset uses default or _withSecret mode. This operation isn't necessary when the state is created with XXH3_createState(). Note that this doesn't prepare the state for a streaming operation, it's still necessary to use XXH3_NNbits_reset*() afterwards.

◆ XXH_PROCESS1

#define XXH_PROCESS1
Value:
do { \
hash += (*ptr++) * XXH_PRIME32_5; \
hash = XXH_rotl32(hash, 11) * XXH_PRIME32_1; \
} while (0)
#define XXH_PRIME32_1
Definition: xxhash.h:2903
#define XXH_PRIME32_5
Definition: xxhash.h:2907

◆ XXH_PROCESS4

#define XXH_PROCESS4
Value:
do { \
hash += XXH_get32bits(ptr) * XXH_PRIME32_3; \
ptr += 4; \
hash = XXH_rotl32(hash, 17) * XXH_PRIME32_4; \
} while (0)
#define XXH_PRIME32_4
Definition: xxhash.h:2906
#define XXH_PRIME32_3
Definition: xxhash.h:2905