kusano 7d535a
/*
kusano 7d535a
   xxHash - Extremely Fast Hash algorithm
kusano 7d535a
   Header File
kusano 7d535a
   Copyright (C) 2012-2015, Yann Collet.
kusano 7d535a
kusano 7d535a
   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
kusano 7d535a
kusano 7d535a
   Redistribution and use in source and binary forms, with or without
kusano 7d535a
   modification, are permitted provided that the following conditions are
kusano 7d535a
   met:
kusano 7d535a
kusano 7d535a
       * Redistributions of source code must retain the above copyright
kusano 7d535a
   notice, this list of conditions and the following disclaimer.
kusano 7d535a
       * Redistributions in binary form must reproduce the above
kusano 7d535a
   copyright notice, this list of conditions and the following disclaimer
kusano 7d535a
   in the documentation and/or other materials provided with the
kusano 7d535a
   distribution.
kusano 7d535a
kusano 7d535a
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
kusano 7d535a
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
kusano 7d535a
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
kusano 7d535a
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
kusano 7d535a
   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
kusano 7d535a
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
kusano 7d535a
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
kusano 7d535a
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
kusano 7d535a
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
kusano 7d535a
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
kusano 7d535a
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
kusano 7d535a
kusano 7d535a
   You can contact the author at :
kusano 7d535a
   - xxHash source repository : https://github.com/Cyan4973/xxHash
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
/* Notice extracted from xxHash homepage :
kusano 7d535a
kusano 7d535a
xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
kusano 7d535a
It also successfully passes all tests from the SMHasher suite.
kusano 7d535a
kusano 7d535a
Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
kusano 7d535a
kusano 7d535a
Name            Speed       Q.Score   Author
kusano 7d535a
xxHash          5.4 GB/s     10
kusano 7d535a
CrapWow         3.2 GB/s      2       Andrew
kusano 7d535a
MumurHash 3a    2.7 GB/s     10       Austin Appleby
kusano 7d535a
SpookyHash      2.0 GB/s     10       Bob Jenkins
kusano 7d535a
SBox            1.4 GB/s      9       Bret Mulvey
kusano 7d535a
Lookup3         1.2 GB/s      9       Bob Jenkins
kusano 7d535a
SuperFastHash   1.2 GB/s      1       Paul Hsieh
kusano 7d535a
CityHash64      1.05 GB/s    10       Pike & Alakuijala
kusano 7d535a
FNV             0.55 GB/s     5       Fowler, Noll, Vo
kusano 7d535a
CRC32           0.43 GB/s     9
kusano 7d535a
MD5-32          0.33 GB/s    10       Ronald L. Rivest
kusano 7d535a
SHA1-32         0.28 GB/s    10
kusano 7d535a
kusano 7d535a
Q.Score is a measure of quality of the hash function.
kusano 7d535a
It depends on successfully passing SMHasher test set.
kusano 7d535a
10 is a perfect score.
kusano 7d535a
kusano 7d535a
A 64-bits version, named XXH64, is available since r35.
kusano 7d535a
It offers much better speed, but for 64-bits applications only.
kusano 7d535a
Name     Speed on 64 bits    Speed on 32 bits
kusano 7d535a
XXH64       13.8 GB/s            1.9 GB/s
kusano 7d535a
XXH32        6.8 GB/s            6.0 GB/s
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
#pragma once
kusano 7d535a
kusano 7d535a
#if defined (__cplusplus)
kusano 7d535a
extern "C" {
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Definitions
kusano 7d535a
*****************************/
kusano 7d535a
#include <stddef.h>   /* size_t */</stddef.h>
kusano 7d535a
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Namespace Emulation
kusano 7d535a
*****************************/
kusano 7d535a
/* Motivations :
kusano 7d535a
kusano 7d535a
If you need to include xxHash into your library,
kusano 7d535a
but wish to avoid xxHash symbols to be present on your library interface
kusano 7d535a
in an effort to avoid potential name collision if another library also includes xxHash,
kusano 7d535a
kusano 7d535a
you can use XXH_NAMESPACE, which will automatically prefix any symbol from xxHash
kusano 7d535a
with the value of XXH_NAMESPACE (so avoid to keep it NULL, and avoid numeric values).
kusano 7d535a
kusano 7d535a
Note that no change is required within the calling program :
kusano 7d535a
it can still call xxHash functions using their regular name.
kusano 7d535a
They will be automatically translated by this header.
kusano 7d535a
*/
kusano 7d535a
#ifdef XXH_NAMESPACE
kusano 7d535a
#  define XXH_CAT(A,B) A##B
kusano 7d535a
#  define XXH_NAME2(A,B) XXH_CAT(A,B)
kusano 7d535a
#  define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
kusano 7d535a
#  define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
kusano 7d535a
#  define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
kusano 7d535a
#  define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
kusano 7d535a
#  define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
kusano 7d535a
#  define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
kusano 7d535a
#  define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
kusano 7d535a
#  define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
kusano 7d535a
#  define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
kusano 7d535a
#  define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
kusano 7d535a
#  define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
kusano 7d535a
#  define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Simple Hash Functions
kusano 7d535a
*****************************/
kusano 7d535a
kusano 7d535a
unsigned int       XXH32 (const void* input, size_t length, unsigned seed);
kusano 7d535a
unsigned long long XXH64 (const void* input, size_t length, unsigned long long seed);
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
XXH32() :
kusano 7d535a
    Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
kusano 7d535a
    The memory between input & input+length must be valid (allocated and read-accessible).
kusano 7d535a
    "seed" can be used to alter the result predictably.
kusano 7d535a
    This function successfully passes all SMHasher tests.
kusano 7d535a
    Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
kusano 7d535a
XXH64() :
kusano 7d535a
    Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
kusano 7d535a
    Faster on 64-bits systems. Slower on 32-bits systems.
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Advanced Hash Functions
kusano 7d535a
*****************************/
kusano 7d535a
typedef struct { long long ll[ 6]; } XXH32_state_t;
kusano 7d535a
typedef struct { long long ll[11]; } XXH64_state_t;
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
These structures allow static allocation of XXH states.
kusano 7d535a
States must then be initialized using XXHnn_reset() before first use.
kusano 7d535a
kusano 7d535a
If you prefer dynamic allocation, please refer to functions below.
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
XXH32_state_t* XXH32_createState(void);
kusano 7d535a
XXH_errorcode  XXH32_freeState(XXH32_state_t* statePtr);
kusano 7d535a
kusano 7d535a
XXH64_state_t* XXH64_createState(void);
kusano 7d535a
XXH_errorcode  XXH64_freeState(XXH64_state_t* statePtr);
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
These functions create and release memory for XXH state.
kusano 7d535a
States must then be initialized using XXHnn_reset() before first use.
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
kusano 7d535a
XXH_errorcode XXH32_reset  (XXH32_state_t* statePtr, unsigned seed);
kusano 7d535a
XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
kusano 7d535a
unsigned int  XXH32_digest (const XXH32_state_t* statePtr);
kusano 7d535a
kusano 7d535a
XXH_errorcode      XXH64_reset  (XXH64_state_t* statePtr, unsigned long long seed);
kusano 7d535a
XXH_errorcode      XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
kusano 7d535a
unsigned long long XXH64_digest (const XXH64_state_t* statePtr);
kusano 7d535a
kusano 7d535a
/*
kusano 7d535a
These functions calculate the xxHash of an input provided in multiple smaller packets,
kusano 7d535a
as opposed to an input provided as a single block.
kusano 7d535a
kusano 7d535a
XXH state space must first be allocated, using either static or dynamic method provided above.
kusano 7d535a
kusano 7d535a
Start a new hash by initializing state with a seed, using XXHnn_reset().
kusano 7d535a
kusano 7d535a
Then, feed the hash state by calling XXHnn_update() as many times as necessary.
kusano 7d535a
Obviously, input must be valid, meaning allocated and read accessible.
kusano 7d535a
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
kusano 7d535a
kusano 7d535a
Finally, you can produce a hash anytime, by using XXHnn_digest().
kusano 7d535a
This function returns the final nn-bits hash.
kusano 7d535a
You can nonetheless continue feeding the hash state with more input,
kusano 7d535a
and therefore get some new hashes, by calling again XXHnn_digest().
kusano 7d535a
kusano 7d535a
When you are done, don't forget to free XXH state space, using typically XXHnn_freeState().
kusano 7d535a
*/
kusano 7d535a
kusano 7d535a
kusano 7d535a
#if defined (__cplusplus)
kusano 7d535a
}
kusano 7d535a
#endif