Macros | Typedefs | Enumerations | Functions | Variables
xxhash.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "xxhash.h"
Include dependency graph for xxhash.c:

Go to the source code of this file.

Macros

#define FORCE_INLINE   static
 
#define MEM_MODULE
 
#define PROCESS1
 
#define PROCESS1_64
 
#define PROCESS4
 
#define PROCESS4_64
 
#define PROCESS8_64
 
#define XXH_ACCEPT_NULL_INPUT_POINTER   0
 
#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()
 
#define XXH_FORCE_ALIGN_CHECK   1
 
#define XXH_FORCE_NATIVE_FORMAT   0
 
#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)
 
#define XXH_get32bits(p)   XXH_readLE32_align(p, endian, align)
 
#define XXH_get64bits(p)   XXH_readLE64_align(p, endian, align)
 
#define XXH_rotl32(x, r)   ((x << r) | (x >> (32 - r)))
 
#define XXH_rotl64(x, r)   ((x << r) | (x >> (64 - r)))
 
#define XXH_STATIC_ASSERT(c)   { enum { XXH_sa = 1/(int)(!!(c)) }; } /* use after variable declarations */
 
#define XXH_STATIC_LINKING_ONLY
 

Typedefs

typedef unsigned char BYTE
 
typedef unsigned short U16
 
typedef unsigned int U32
 
typedef unsigned long long U64
 

Enumerations

enum  XXH_alignment { XXH_aligned, XXH_unaligned }
 
enum  XXH_endianess { XXH_bigEndian =0, XXH_littleEndian =1 }
 

Functions

XXH_PUBLIC_API unsigned int XXH32 (const void *input, size_t len, unsigned int seed)
 
static U32 XXH32_avalanche (U32 h32)
 
XXH_PUBLIC_API void XXH32_canonicalFromHash (XXH32_canonical_t *dst, XXH32_hash_t hash)
 
XXH_PUBLIC_API void XXH32_copyState (XXH32_state_t *dstState, const XXH32_state_t *srcState)
 
XXH_PUBLIC_API XXH32_state_tXXH32_createState (void)
 
XXH_PUBLIC_API unsigned int XXH32_digest (const XXH32_state_t *state_in)
 
FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t *state, XXH_endianess endian)
 
FORCE_INLINE U32 XXH32_endian_align (const void *input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
 
static U32 XXH32_finalize (U32 h32, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
 
XXH_PUBLIC_API XXH_errorcode XXH32_freeState (XXH32_state_t *statePtr)
 
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical (const XXH32_canonical_t *src)
 
XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t *statePtr, unsigned int seed)
 
static U32 XXH32_round (U32 seed, U32 input)
 
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t *state_in, const void *input, size_t len)
 
FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t *state, const void *input, size_t len, XXH_endianess endian)
 
XXH_PUBLIC_API unsigned long long XXH64 (const void *input, size_t len, unsigned long long seed)
 
static U64 XXH64_avalanche (U64 h64)
 
XXH_PUBLIC_API void XXH64_canonicalFromHash (XXH64_canonical_t *dst, XXH64_hash_t hash)
 
XXH_PUBLIC_API void XXH64_copyState (XXH64_state_t *dstState, const XXH64_state_t *srcState)
 
XXH_PUBLIC_API XXH64_state_tXXH64_createState (void)
 
XXH_PUBLIC_API unsigned long long XXH64_digest (const XXH64_state_t *state_in)
 
FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t *state, XXH_endianess endian)
 
FORCE_INLINE U64 XXH64_endian_align (const void *input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
 
static U64 XXH64_finalize (U64 h64, const void *ptr, size_t len, XXH_endianess endian, XXH_alignment align)
 
XXH_PUBLIC_API XXH_errorcode XXH64_freeState (XXH64_state_t *statePtr)
 
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical (const XXH64_canonical_t *src)
 
static U64 XXH64_mergeRound (U64 acc, U64 val)
 
XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t *statePtr, unsigned long long seed)
 
static U64 XXH64_round (U64 acc, U64 input)
 
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t *state_in, const void *input, size_t len)
 
FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t *state, const void *input, size_t len, XXH_endianess endian)
 
static void XXH_free (void *p)
 
static int XXH_isLittleEndian (void)
 
static void * XXH_malloc (size_t s)
 
static void * XXH_memcpy (void *dest, const void *src, size_t size)
 
static U32 XXH_read32 (const void *memPtr)
 
static U64 XXH_read64 (const void *memPtr)
 
static U32 XXH_readBE32 (const void *ptr)
 
static U64 XXH_readBE64 (const void *ptr)
 
FORCE_INLINE U32 XXH_readLE32 (const void *ptr, XXH_endianess endian)
 
FORCE_INLINE U32 XXH_readLE32_align (const void *ptr, XXH_endianess endian, XXH_alignment align)
 
FORCE_INLINE U64 XXH_readLE64 (const void *ptr, XXH_endianess endian)
 
FORCE_INLINE U64 XXH_readLE64_align (const void *ptr, XXH_endianess endian, XXH_alignment align)
 
static U32 XXH_swap32 (U32 x)
 
static U64 XXH_swap64 (U64 x)
 
XXH_PUBLIC_API unsigned XXH_versionNumber (void)
 

Variables

static const U32 PRIME32_1 = 2654435761U
 
static const U32 PRIME32_2 = 2246822519U
 
static const U32 PRIME32_3 = 3266489917U
 
static const U32 PRIME32_4 = 668265263U
 
static const U32 PRIME32_5 = 374761393U
 
static const U64 PRIME64_1 = 11400714785074694791ULL
 
static const U64 PRIME64_2 = 14029467366897019727ULL
 
static const U64 PRIME64_3 = 1609587929392839161ULL
 
static const U64 PRIME64_4 = 9650029242287828579ULL
 
static const U64 PRIME64_5 = 2870177450012600261ULL
 

Macro Definition Documentation

◆ FORCE_INLINE

#define FORCE_INLINE   static

Definition at line 134 of file xxhash.c.

◆ MEM_MODULE

#define MEM_MODULE

Definition at line 587 of file xxhash.c.

◆ PROCESS1

#define PROCESS1
Value:
h32 += (*p++) * PRIME32_5; \
h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
static const U32 PRIME32_5
Definition: xxhash.c:267
static const U32 PRIME32_1
Definition: xxhash.c:263
#define XXH_rotl32(x, r)
Definition: xxhash.c:194

◆ PROCESS1_64

#define PROCESS1_64
Value:
h64 ^= (*p++) * PRIME64_5; \
h64 = XXH_rotl64(h64, 11) * PRIME64_1;
#define XXH_rotl64(x, r)
Definition: xxhash.c:195
static const U64 PRIME64_1
Definition: xxhash.c:666
static const U64 PRIME64_5
Definition: xxhash.c:670

◆ PROCESS4

#define PROCESS4
Value:
h32 += XXH_get32bits(p) * PRIME32_3; \
p+=4; \
h32 = XXH_rotl32(h32, 17) * PRIME32_4 ;
static const U32 PRIME32_3
Definition: xxhash.c:265
#define XXH_rotl32(x, r)
Definition: xxhash.c:194
#define XXH_get32bits(p)
Definition: xxhash.c:288
static const U32 PRIME32_4
Definition: xxhash.c:266

◆ PROCESS4_64

#define PROCESS4_64
Value:
h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1; \
p+=4; \
h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
#define XXH_rotl64(x, r)
Definition: xxhash.c:195
static const U64 PRIME64_2
Definition: xxhash.c:667
#define XXH_get32bits(p)
Definition: xxhash.c:288
static const U64 PRIME64_1
Definition: xxhash.c:666
static const U64 PRIME64_3
Definition: xxhash.c:668
unsigned long long U64
Definition: xxhash.c:595

◆ PROCESS8_64

#define PROCESS8_64
Value:
{ \
U64 const k1 = XXH64_round(0, XXH_get64bits(p)); \
p+=8; \
h64 ^= k1; \
h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4; \
}
#define XXH_rotl64(x, r)
Definition: xxhash.c:195
static U64 XXH64_round(U64 acc, U64 input)
Definition: xxhash.c:672
#define XXH_get64bits(p)
Definition: xxhash.c:699
static const U64 PRIME64_4
Definition: xxhash.c:669
static const U64 PRIME64_1
Definition: xxhash.c:666

◆ XXH_ACCEPT_NULL_INPUT_POINTER

#define XXH_ACCEPT_NULL_INPUT_POINTER   0

XXH_FORCE_MEMORY_ACCESS : By default, access to unaligned memory is controlled by memcpy(), which is safe and portable. Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. The below switch allow to select different access method for improved performance. Method 0 (default) : use memcpy(). Safe and portable. Method 1 : __packed statement. It depends on compiler extension (ie, not portable). This method is safe if your compiler supports it, and generally as fast or faster than memcpy. Method 2 : direct access. This method doesn't depend on compiler but violate C standard. It can generate buggy code on targets which do not support unaligned memory accesses. But in some circumstances, it's the only known way to get the most performance (ie GCC + ARMv6) See http://stackoverflow.com/a/32095106/646947 for details. Prefer these methods in priority order (0 > 1 > 2)

XXH_ACCEPT_NULL_INPUT_POINTER : If input pointer is NULL, xxHash default behavior is to dereference it, triggering a segfault. When this macro is enabled, xxHash actively checks input for null pointer. It it is, result for null input pointers is the same as a null-length input.

Definition at line 71 of file xxhash.c.

◆ XXH_CPU_LITTLE_ENDIAN

#define XXH_CPU_LITTLE_ENDIAN   XXH_isLittleEndian()

Definition at line 225 of file xxhash.c.

◆ XXH_FORCE_ALIGN_CHECK

#define XXH_FORCE_ALIGN_CHECK   1

XXH_FORCE_ALIGN_CHECK : This is a minor performance trick, only useful with lots of very small keys. It means : check for aligned/unaligned input. The check costs one initial branch per hash; set it to 0 when the input is guaranteed to be aligned, or when alignment doesn't matter for performance.

Definition at line 97 of file xxhash.c.

◆ XXH_FORCE_NATIVE_FORMAT

#define XXH_FORCE_NATIVE_FORMAT   0

XXH_FORCE_NATIVE_FORMAT : By default, xxHash library provides endian-independent Hash values, based on little-endian convention. Results are therefore identical for little-endian and big-endian CPU. This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format. Should endian-independence be of no importance for your application, you may set the #define below to 1, to improve speed for Big-endian CPU. This option has no impact on Little_Endian CPU.

Definition at line 83 of file xxhash.c.

◆ XXH_GCC_VERSION

#define XXH_GCC_VERSION   (__GNUC__ * 100 + __GNUC_MINOR__)

Definition at line 187 of file xxhash.c.

◆ XXH_get32bits

#define XXH_get32bits (   p)    XXH_readLE32_align(p, endian, align)

Definition at line 288 of file xxhash.c.

◆ XXH_get64bits

#define XXH_get64bits (   p)    XXH_readLE64_align(p, endian, align)

Definition at line 699 of file xxhash.c.

◆ XXH_rotl32

#define XXH_rotl32 (   x,
 
)    ((x << r) | (x >> (32 - r)))

Definition at line 194 of file xxhash.c.

◆ XXH_rotl64

#define XXH_rotl64 (   x,
 
)    ((x << r) | (x >> (64 - r)))

Definition at line 195 of file xxhash.c.

◆ XXH_STATIC_ASSERT

#define XXH_STATIC_ASSERT (   c)    { enum { XXH_sa = 1/(int)(!!(c)) }; } /* use after variable declarations */

Definition at line 256 of file xxhash.c.

◆ XXH_STATIC_LINKING_ONLY

#define XXH_STATIC_LINKING_ONLY

Definition at line 116 of file xxhash.c.

Typedef Documentation

◆ BYTE

typedef unsigned char BYTE

Definition at line 151 of file xxhash.c.

◆ U16

typedef unsigned short U16

Definition at line 152 of file xxhash.c.

◆ U32

typedef unsigned int U32

Definition at line 153 of file xxhash.c.

◆ U64

typedef unsigned long long U64

Definition at line 595 of file xxhash.c.

Enumeration Type Documentation

◆ XXH_alignment

Enumerator
XXH_aligned 
XXH_unaligned 

Definition at line 232 of file xxhash.c.

◆ XXH_endianess

Enumerator
XXH_bigEndian 
XXH_littleEndian 

Definition at line 216 of file xxhash.c.

Function Documentation

◆ XXH32()

XXH_PUBLIC_API unsigned int XXH32 ( const void *  input,
size_t  length,
unsigned int  seed 
)

XXH32() : Calculate the 32-bit hash of sequence "length" bytes stored at memory address "input". The memory between input & input+length must be valid (allocated and read-accessible). "seed" can be used to alter the result predictably. Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s

Definition at line 392 of file xxhash.c.

◆ XXH32_avalanche()

static U32 XXH32_avalanche ( U32  h32)
static

Definition at line 278 of file xxhash.c.

◆ XXH32_canonicalFromHash()

XXH_PUBLIC_API void XXH32_canonicalFromHash ( XXH32_canonical_t dst,
XXH32_hash_t  hash 
)

Default XXH result types are basic unsigned 32 and 64 bits. The canonical representation follows human-readable write convention, aka big-endian (large digits first). These functions allow transformation of hash result into and from its canonical format. This way, hash values can be written into a file or buffer, remaining comparable across different systems.

Definition at line 565 of file xxhash.c.

◆ XXH32_copyState()

XXH_PUBLIC_API void XXH32_copyState ( XXH32_state_t dstState,
const XXH32_state_t srcState 
)

Definition at line 432 of file xxhash.c.

◆ XXH32_createState()

XXH_PUBLIC_API XXH32_state_t* XXH32_createState ( void  )

Definition at line 422 of file xxhash.c.

◆ XXH32_digest()

XXH_PUBLIC_API unsigned int XXH32_digest ( const XXH32_state_t state_in)

Definition at line 546 of file xxhash.c.

◆ XXH32_digest_endian()

FORCE_INLINE U32 XXH32_digest_endian ( const XXH32_state_t state,
XXH_endianess  endian 
)

Definition at line 527 of file xxhash.c.

◆ XXH32_endian_align()

FORCE_INLINE U32 XXH32_endian_align ( const void *  input,
size_t  len,
U32  seed,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 352 of file xxhash.c.

◆ XXH32_finalize()

static U32 XXH32_finalize ( U32  h32,
const void *  ptr,
size_t  len,
XXH_endianess  endian,
XXH_alignment  align 
)
static

Definition at line 291 of file xxhash.c.

◆ XXH32_freeState()

XXH_PUBLIC_API XXH_errorcode XXH32_freeState ( XXH32_state_t statePtr)

Definition at line 426 of file xxhash.c.

◆ XXH32_hashFromCanonical()

XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical ( const XXH32_canonical_t src)

Definition at line 572 of file xxhash.c.

◆ XXH32_reset()

XXH_PUBLIC_API XXH_errorcode XXH32_reset ( XXH32_state_t statePtr,
unsigned int  seed 
)

Definition at line 437 of file xxhash.c.

◆ XXH32_round()

static U32 XXH32_round ( U32  seed,
U32  input 
)
static

Definition at line 269 of file xxhash.c.

◆ XXH32_update()

XXH_PUBLIC_API XXH_errorcode XXH32_update ( XXH32_state_t state_in,
const void *  input,
size_t  len 
)

Definition at line 515 of file xxhash.c.

◆ XXH32_update_endian()

FORCE_INLINE XXH_errorcode XXH32_update_endian ( XXH32_state_t state,
const void *  input,
size_t  len,
XXH_endianess  endian 
)

Definition at line 452 of file xxhash.c.

◆ XXH64()

XXH_PUBLIC_API unsigned long long XXH64 ( const void *  input,
size_t  length,
unsigned long long  seed 
)

XXH64() : Calculate the 64-bit hash of sequence of length "len" stored at memory address "input". "seed" can be used to alter the result predictably. This function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark).

Definition at line 855 of file xxhash.c.

◆ XXH64_avalanche()

static U64 XXH64_avalanche ( U64  h64)
static

Definition at line 688 of file xxhash.c.

◆ XXH64_canonicalFromHash()

XXH_PUBLIC_API void XXH64_canonicalFromHash ( XXH64_canonical_t dst,
XXH64_hash_t  hash 
)

Definition at line 1018 of file xxhash.c.

◆ XXH64_copyState()

XXH_PUBLIC_API void XXH64_copyState ( XXH64_state_t dstState,
const XXH64_state_t srcState 
)

Definition at line 893 of file xxhash.c.

◆ XXH64_createState()

XXH_PUBLIC_API XXH64_state_t* XXH64_createState ( void  )

Definition at line 883 of file xxhash.c.

◆ XXH64_digest()

XXH_PUBLIC_API unsigned long long XXH64_digest ( const XXH64_state_t state_in)

Definition at line 1005 of file xxhash.c.

◆ XXH64_digest_endian()

FORCE_INLINE U64 XXH64_digest_endian ( const XXH64_state_t state,
XXH_endianess  endian 
)

Definition at line 981 of file xxhash.c.

◆ XXH64_endian_align()

FORCE_INLINE U64 XXH64_endian_align ( const void *  input,
size_t  len,
U64  seed,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 811 of file xxhash.c.

◆ XXH64_finalize()

static U64 XXH64_finalize ( U64  h64,
const void *  ptr,
size_t  len,
XXH_endianess  endian,
XXH_alignment  align 
)
static

Definition at line 702 of file xxhash.c.

◆ XXH64_freeState()

XXH_PUBLIC_API XXH_errorcode XXH64_freeState ( XXH64_state_t statePtr)

Definition at line 887 of file xxhash.c.

◆ XXH64_hashFromCanonical()

XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical ( const XXH64_canonical_t src)

Definition at line 1025 of file xxhash.c.

◆ XXH64_mergeRound()

static U64 XXH64_mergeRound ( U64  acc,
U64  val 
)
static

Definition at line 680 of file xxhash.c.

◆ XXH64_reset()

XXH_PUBLIC_API XXH_errorcode XXH64_reset ( XXH64_state_t statePtr,
unsigned long long  seed 
)

Definition at line 898 of file xxhash.c.

◆ XXH64_round()

static U64 XXH64_round ( U64  acc,
U64  input 
)
static

Definition at line 672 of file xxhash.c.

◆ XXH64_update()

XXH_PUBLIC_API XXH_errorcode XXH64_update ( XXH64_state_t state_in,
const void *  input,
size_t  len 
)

Definition at line 971 of file xxhash.c.

◆ XXH64_update_endian()

FORCE_INLINE XXH_errorcode XXH64_update_endian ( XXH64_state_t state,
const void *  input,
size_t  len,
XXH_endianess  endian 
)

Definition at line 912 of file xxhash.c.

◆ XXH_free()

static void XXH_free ( void *  p)
static

Definition at line 109 of file xxhash.c.

◆ XXH_isLittleEndian()

static int XXH_isLittleEndian ( void  )
static

Definition at line 220 of file xxhash.c.

◆ XXH_malloc()

static void* XXH_malloc ( size_t  s)
static

Modify the local functions below should you wish to use some other memory routines for malloc(), free()

Definition at line 108 of file xxhash.c.

◆ XXH_memcpy()

static void* XXH_memcpy ( void *  dest,
const void *  src,
size_t  size 
)
static

and for memcpy()

Definition at line 112 of file xxhash.c.

◆ XXH_read32()

static U32 XXH_read32 ( const void *  memPtr)
static

Definition at line 174 of file xxhash.c.

◆ XXH_read64()

static U64 XXH_read64 ( const void *  memPtr)
static

Definition at line 618 of file xxhash.c.

◆ XXH_readBE32()

static U32 XXH_readBE32 ( const void *  ptr)
static

Definition at line 247 of file xxhash.c.

◆ XXH_readBE64()

static U64 XXH_readBE64 ( const void *  ptr)
static

Definition at line 658 of file xxhash.c.

◆ XXH_readLE32()

FORCE_INLINE U32 XXH_readLE32 ( const void *  ptr,
XXH_endianess  endian 
)

Definition at line 242 of file xxhash.c.

◆ XXH_readLE32_align()

FORCE_INLINE U32 XXH_readLE32_align ( const void *  ptr,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 234 of file xxhash.c.

◆ XXH_readLE64()

FORCE_INLINE U64 XXH_readLE64 ( const void *  ptr,
XXH_endianess  endian 
)

Definition at line 653 of file xxhash.c.

◆ XXH_readLE64_align()

FORCE_INLINE U64 XXH_readLE64_align ( const void *  ptr,
XXH_endianess  endian,
XXH_alignment  align 
)

Definition at line 645 of file xxhash.c.

◆ XXH_swap32()

static U32 XXH_swap32 ( U32  x)
static

Definition at line 203 of file xxhash.c.

◆ XXH_swap64()

static U64 XXH_swap64 ( U64  x)
static

Definition at line 632 of file xxhash.c.

◆ XXH_versionNumber()

XXH_PUBLIC_API unsigned XXH_versionNumber ( void  )

Definition at line 257 of file xxhash.c.

Variable Documentation

◆ PRIME32_1

const U32 PRIME32_1 = 2654435761U
static

Definition at line 263 of file xxhash.c.

◆ PRIME32_2

const U32 PRIME32_2 = 2246822519U
static

Definition at line 264 of file xxhash.c.

◆ PRIME32_3

const U32 PRIME32_3 = 3266489917U
static

Definition at line 265 of file xxhash.c.

◆ PRIME32_4

const U32 PRIME32_4 = 668265263U
static

Definition at line 266 of file xxhash.c.

◆ PRIME32_5

const U32 PRIME32_5 = 374761393U
static

Definition at line 267 of file xxhash.c.

◆ PRIME64_1

const U64 PRIME64_1 = 11400714785074694791ULL
static

Definition at line 666 of file xxhash.c.

◆ PRIME64_2

const U64 PRIME64_2 = 14029467366897019727ULL
static

Definition at line 667 of file xxhash.c.

◆ PRIME64_3

const U64 PRIME64_3 = 1609587929392839161ULL
static

Definition at line 668 of file xxhash.c.

◆ PRIME64_4

const U64 PRIME64_4 = 9650029242287828579ULL
static

Definition at line 669 of file xxhash.c.

◆ PRIME64_5

const U64 PRIME64_5 = 2870177450012600261ULL
static

Definition at line 670 of file xxhash.c.



plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Jun 19 2023 03:12:54