summaryrefslogtreecommitdiffstats
path: root/xxhash.h
diff options
context:
space:
mode:
authorYann Collet <yann.collet.73@gmail.com>2014-10-06 10:13:56 (GMT)
committerYann Collet <yann.collet.73@gmail.com>2014-10-06 10:13:56 (GMT)
commit2ab6f9a387de9d507e38ae63f6da0f9b9b9a58d8 (patch)
tree5eccaaa13bb7f2a56ccb54d37cc71176c786c724 /xxhash.h
parent72b51859e03c2a09b4e6f3a3d5d4783a8a99f6d4 (diff)
downloadlz4-2ab6f9a387de9d507e38ae63f6da0f9b9b9a58d8.zip
lz4-2ab6f9a387de9d507e38ae63f6da0f9b9b9a58d8.tar.gz
lz4-2ab6f9a387de9d507e38ae63f6da0f9b9b9a58d8.tar.bz2
Updated : xxHash to r37
Diffstat (limited to 'xxhash.h')
-rw-r--r--xxhash.h98
1 files changed, 43 insertions, 55 deletions
diff --git a/xxhash.h b/xxhash.h
index 4311485..55b4501 100644
--- a/xxhash.h
+++ b/xxhash.h
@@ -65,6 +65,12 @@ extern "C" {
/*****************************
+ Includes
+*****************************/
+#include <stddef.h> /* size_t */
+
+
+/*****************************
Type
*****************************/
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
@@ -75,18 +81,16 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
Simple Hash Functions
*****************************/
-unsigned int XXH32 (const void* input, unsigned int len, unsigned int seed);
-unsigned long long XXH64 (const void* input, unsigned int len, unsigned long long seed);
+unsigned int XXH32 (const void* input, size_t length, unsigned seed);
+unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed);
/*
XXH32() :
- Calculate the 32-bits hash of sequence of length "len" stored at memory address "input".
- The memory between input & input+len must be valid (allocated and read-accessible).
+ Calculate the 32-bits 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.
This function successfully passes all SMHasher tests.
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
- Note that "len" is type "int", which means it is limited to 2^31-1.
- If your data is larger, use the advanced functions below.
XXH64() :
Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
*/
@@ -96,70 +100,54 @@ XXH64() :
/*****************************
Advanced Hash Functions
*****************************/
-
-void* XXH32_init (unsigned int seed);
-XXH_errorcode XXH32_update (void* state, const void* input, unsigned int len);
-unsigned int XXH32_digest (void* state);
-
-void* XXH64_init (unsigned long long seed);
-XXH_errorcode XXH64_update (void* state, const void* input, unsigned int len);
-unsigned long long XXH64_digest (void* state);
+typedef struct { long long ll[ 6]; } XXH32_state_t;
+typedef struct { long long ll[11]; } XXH64_state_t;
/*
-These functions calculate the xxhash of an input provided in several small packets,
-as opposed to an input provided as a single block.
-
-It must be started with :
-void* XXHnn_init()
-The function returns a pointer which holds the state of calculation.
-If the pointer is NULL, allocation has failed, so no state can be tracked.
-
-The state pointer must be provided as "void* state" parameter for XXHnn_update().
-XXHnn_update() can be called as many times as necessary.
-The user must provide a valid (allocated) input.
-The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
-Note that "len" is type "int", which means it is limited to 2^31-1.
-If your data is larger, it is recommended to chunk your data into blocks
-of size for example 2^30 (1GB) to avoid any "int" overflow issue.
+These structures allow static allocation of XXH states.
+States must then be initialized using XXHnn_reset() before first use.
-Finally, you can end the calculation anytime, by using XXHnn_digest().
-This function returns the final nn-bits hash.
-You must provide the same "void* state" parameter created by XXHnn_init().
-Memory will be freed by XXHnn_digest().
+If you prefer dynamic allocation, please refer to functions below.
*/
+XXH32_state_t* XXH32_createState(void);
+XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
-int XXH32_sizeofState(void);
-XXH_errorcode XXH32_resetState(void* state, unsigned int seed);
+XXH64_state_t* XXH64_createState(void);
+XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
-#define XXH32_SIZEOFSTATE 48
-typedef struct { long long ll[(XXH32_SIZEOFSTATE+(sizeof(long long)-1))/sizeof(long long)]; } XXH32_stateSpace_t;
+/*
+These functions create and release memory for XXH state.
+States must then be initialized using XXHnn_reset() before first use.
+*/
-int XXH64_sizeofState(void);
-XXH_errorcode XXH64_resetState(void* state, unsigned long long seed);
-#define XXH64_SIZEOFSTATE 88
-typedef struct { long long ll[(XXH64_SIZEOFSTATE+(sizeof(long long)-1))/sizeof(long long)]; } XXH64_stateSpace_t;
+XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned seed);
+XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
+unsigned int XXH32_digest (const XXH32_state_t* statePtr);
+
+XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
+XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
+unsigned long long XXH64_digest (const XXH64_state_t* statePtr);
/*
-These functions allow user application to make its own allocation for state.
+These functions calculate the xxHash of an input provided in multiple smaller packets,
+as opposed to an input provided as a single block.
-XXHnn_sizeofState() is used to know how much space must be allocated for the xxHash nn-bits state.
-Note that the state must be aligned to access 'long long' fields. Memory must be allocated and referenced by a pointer.
-This pointer must then be provided as 'state' into XXHnn_resetState(), which initializes the state.
+XXH state space must first be allocated, using either static or dynamic method provided above.
-For static allocation purposes (such as allocation on stack, or freestanding systems without malloc()),
-use the structure XXHnn_stateSpace_t, which will ensure that memory space is large enough and correctly aligned to access 'long long' fields.
-*/
+Start a new hash by initializing state with a seed, using XXHnn_reset().
+Then, feed the hash state by calling XXHnn_update() as many times as necessary.
+Obviously, input must be valid, meaning allocated and read accessible.
+The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
-unsigned int XXH32_intermediateDigest (void* state);
-unsigned long long XXH64_intermediateDigest (void* state);
-/*
-These functions do the same as XXHnn_digest(), generating a nn-bit hash,
-but preserve memory context.
-This way, it becomes possible to generate intermediate hashes, and then continue feeding data with XXHnn_update().
-To free memory context, use XXHnn_digest(), or free().
+Finally, you can produce a hash anytime, by using XXHnn_digest().
+This function returns the final nn-bits hash.
+You can nonetheless continue feeding the hash state with more input,
+and therefore get some new hashes, by calling again XXHnn_digest().
+
+When you are done, don't forget to free XXH state space, using typically XXHnn_freeState().
*/