Blame src/xxhash.h

Packit 2997f0
/*
Packit 2997f0
   xxHash - Extremely Fast Hash algorithm
Packit 2997f0
   Header File
Packit 2997f0
   Copyright (C) 2012-2016, Yann Collet.
Packit 2997f0
Packit 2997f0
   BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
Packit 2997f0
Packit 2997f0
   Redistribution and use in source and binary forms, with or without
Packit 2997f0
   modification, are permitted provided that the following conditions are
Packit 2997f0
   met:
Packit 2997f0
Packit 2997f0
       * Redistributions of source code must retain the above copyright
Packit 2997f0
   notice, this list of conditions and the following disclaimer.
Packit 2997f0
       * Redistributions in binary form must reproduce the above
Packit 2997f0
   copyright notice, this list of conditions and the following disclaimer
Packit 2997f0
   in the documentation and/or other materials provided with the
Packit 2997f0
   distribution.
Packit 2997f0
Packit 2997f0
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit 2997f0
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit 2997f0
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit 2997f0
   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit 2997f0
   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit 2997f0
   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit 2997f0
   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit 2997f0
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit 2997f0
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit 2997f0
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 2997f0
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 2997f0
Packit 2997f0
   You can contact the author at :
Packit 2997f0
   - xxHash source repository : https://github.com/Cyan4973/xxHash
Packit 2997f0
*/
Packit 2997f0
Packit 2997f0
/* Notice extracted from xxHash homepage :
Packit 2997f0
Packit 2997f0
xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
Packit 2997f0
It also successfully passes all tests from the SMHasher suite.
Packit 2997f0
Packit 2997f0
Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
Packit 2997f0
Packit 2997f0
Name            Speed       Q.Score   Author
Packit 2997f0
xxHash          5.4 GB/s     10
Packit 2997f0
CrapWow         3.2 GB/s      2       Andrew
Packit 2997f0
MumurHash 3a    2.7 GB/s     10       Austin Appleby
Packit 2997f0
SpookyHash      2.0 GB/s     10       Bob Jenkins
Packit 2997f0
SBox            1.4 GB/s      9       Bret Mulvey
Packit 2997f0
Lookup3         1.2 GB/s      9       Bob Jenkins
Packit 2997f0
SuperFastHash   1.2 GB/s      1       Paul Hsieh
Packit 2997f0
CityHash64      1.05 GB/s    10       Pike & Alakuijala
Packit 2997f0
FNV             0.55 GB/s     5       Fowler, Noll, Vo
Packit 2997f0
CRC32           0.43 GB/s     9
Packit 2997f0
MD5-32          0.33 GB/s    10       Ronald L. Rivest
Packit 2997f0
SHA1-32         0.28 GB/s    10
Packit 2997f0
Packit 2997f0
Q.Score is a measure of quality of the hash function.
Packit 2997f0
It depends on successfully passing SMHasher test set.
Packit 2997f0
10 is a perfect score.
Packit 2997f0
Packit 2997f0
A 64-bits version, named XXH64, is available since r35.
Packit 2997f0
It offers much better speed, but for 64-bits applications only.
Packit 2997f0
Name     Speed on 64 bits    Speed on 32 bits
Packit 2997f0
XXH64       13.8 GB/s            1.9 GB/s
Packit 2997f0
XXH32        6.8 GB/s            6.0 GB/s
Packit 2997f0
*/
Packit 2997f0
Packit 2997f0
#ifndef XXHASH_H_5627135585666179
Packit 2997f0
#define XXHASH_H_5627135585666179 1
Packit 2997f0
Packit 2997f0
#if defined (__cplusplus)
Packit 2997f0
extern "C" {
Packit 2997f0
#endif
Packit 2997f0
Packit 2997f0
Packit 2997f0
/* ****************************
Packit 2997f0
*  Definitions
Packit 2997f0
******************************/
Packit 2997f0
#include <stddef.h>   /* size_t */
Packit 2997f0
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
Packit 2997f0
Packit 2997f0
Packit 2997f0
/* ****************************
Packit 2997f0
*  API modifier
Packit 2997f0
******************************/
Packit 2997f0
/** XXH_PRIVATE_API
Packit 2997f0
*   This is useful to include xxhash functions in `static` mode
Packit 2997f0
*   in order to inline them, and remove their symbol from the public list.
Packit 2997f0
*   Methodology :
Packit 2997f0
*     #define XXH_PRIVATE_API
Packit 2997f0
*     #include "xxhash.h"
Packit 2997f0
*   `xxhash.c` is automatically included.
Packit 2997f0
*   It's not useful to compile and link it as a separate module.
Packit 2997f0
*/
Packit 2997f0
#ifdef XXH_PRIVATE_API
Packit 2997f0
#  ifndef XXH_STATIC_LINKING_ONLY
Packit 2997f0
#    define XXH_STATIC_LINKING_ONLY
Packit 2997f0
#  endif
Packit 2997f0
#  if defined(__GNUC__)
Packit 2997f0
#    define XXH_PUBLIC_API static __inline __attribute__((unused))
Packit 2997f0
#  elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
Packit 2997f0
#    define XXH_PUBLIC_API static inline
Packit 2997f0
#  elif defined(_MSC_VER)
Packit 2997f0
#    define XXH_PUBLIC_API static __inline
Packit 2997f0
#  else
Packit 2997f0
#    define XXH_PUBLIC_API static   /* this version may generate warnings for unused static functions; disable the relevant warning */
Packit 2997f0
#  endif
Packit 2997f0
#else
Packit 2997f0
#  define XXH_PUBLIC_API   /* do nothing */
Packit 2997f0
#endif /* XXH_PRIVATE_API */
Packit 2997f0
Packit 2997f0
/*!XXH_NAMESPACE, aka Namespace Emulation :
Packit 2997f0
Packit 2997f0
If you want to include _and expose_ xxHash functions from within your own library,
Packit 2997f0
but also want to avoid symbol collisions with other libraries which may also include xxHash,
Packit 2997f0
Packit 2997f0
you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library
Packit 2997f0
with the value of XXH_NAMESPACE (therefore, avoid NULL and numeric values).
Packit 2997f0
Packit 2997f0
Note that no change is required within the calling program as long as it includes `xxhash.h` :
Packit 2997f0
regular symbol name will be automatically translated by this header.
Packit 2997f0
*/
Packit 2997f0
#ifdef XXH_NAMESPACE
Packit 2997f0
#  define XXH_CAT(A,B) A##B
Packit 2997f0
#  define XXH_NAME2(A,B) XXH_CAT(A,B)
Packit 2997f0
#  define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
Packit 2997f0
#  define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
Packit 2997f0
#  define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
Packit 2997f0
#  define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
Packit 2997f0
#  define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
Packit 2997f0
#  define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
Packit 2997f0
#  define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
Packit 2997f0
#  define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
Packit 2997f0
#  define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
Packit 2997f0
#  define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
Packit 2997f0
#  define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
Packit 2997f0
#  define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
Packit 2997f0
#  define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
Packit 2997f0
#  define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
Packit 2997f0
#  define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
Packit 2997f0
#  define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
Packit 2997f0
#  define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
Packit 2997f0
#  define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
Packit 2997f0
#  define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
Packit 2997f0
#endif
Packit 2997f0
Packit 2997f0
Packit 2997f0
/* *************************************
Packit 2997f0
*  Version
Packit 2997f0
***************************************/
Packit 2997f0
#define XXH_VERSION_MAJOR    0
Packit 2997f0
#define XXH_VERSION_MINOR    6
Packit 2997f0
#define XXH_VERSION_RELEASE  2
Packit 2997f0
#define XXH_VERSION_NUMBER  (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
Packit 2997f0
XXH_PUBLIC_API unsigned XXH_versionNumber (void);
Packit 2997f0
Packit 2997f0
Packit 2997f0
/*-**********************************************************************
Packit 2997f0
*  32-bits hash
Packit 2997f0
************************************************************************/
Packit 2997f0
typedef unsigned int       XXH32_hash_t;
Packit 2997f0
Packit 2997f0
/*! XXH32() :
Packit 2997f0
    Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
Packit 2997f0
    The memory between input & input+length must be valid (allocated and read-accessible).
Packit 2997f0
    "seed" can be used to alter the result predictably.
Packit 2997f0
    Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s */
Packit 2997f0
XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
Packit 2997f0
Packit 2997f0
/*======   Streaming   ======*/
Packit 2997f0
typedef struct XXH32_state_s XXH32_state_t;   /* incomplete type */
Packit 2997f0
XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode  XXH32_freeState(XXH32_state_t* statePtr);
Packit 2997f0
XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* dst_state, const XXH32_state_t* src_state);
Packit 2997f0
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode XXH32_reset  (XXH32_state_t* statePtr, unsigned int seed);
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
Packit 2997f0
XXH_PUBLIC_API XXH32_hash_t  XXH32_digest (const XXH32_state_t* statePtr);
Packit 2997f0
Packit 2997f0
/*
Packit 2997f0
These functions generate the xxHash of an input provided in multiple segments.
Packit 2997f0
Note that, for small input, they are slower than single-call functions, due to state management.
Packit 2997f0
For small input, prefer `XXH32()` and `XXH64()` .
Packit 2997f0
Packit 2997f0
XXH state must first be allocated, using XXH*_createState() .
Packit 2997f0
Packit 2997f0
Start a new hash by initializing state with a seed, using XXH*_reset().
Packit 2997f0
Packit 2997f0
Then, feed the hash state by calling XXH*_update() as many times as necessary.
Packit 2997f0
Obviously, input must be allocated and read accessible.
Packit 2997f0
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
Packit 2997f0
Packit 2997f0
Finally, a hash value can be produced anytime, by using XXH*_digest().
Packit 2997f0
This function returns the nn-bits hash as an int or long long.
Packit 2997f0
Packit 2997f0
It's still possible to continue inserting input into the hash state after a digest,
Packit 2997f0
and generate some new hashes later on, by calling again XXH*_digest().
Packit 2997f0
Packit 2997f0
When done, free XXH state space if it was allocated dynamically.
Packit 2997f0
*/
Packit 2997f0
Packit 2997f0
/*======   Canonical representation   ======*/
Packit 2997f0
Packit 2997f0
typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
Packit 2997f0
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash);
Packit 2997f0
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
Packit 2997f0
Packit 2997f0
/* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
Packit 2997f0
*  The canonical representation uses human-readable write convention, aka big-endian (large digits first).
Packit 2997f0
*  These functions allow transformation of hash result into and from its canonical format.
Packit 2997f0
*  This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
Packit 2997f0
*/
Packit 2997f0
Packit 2997f0
Packit 2997f0
#ifndef XXH_NO_LONG_LONG
Packit 2997f0
/*-**********************************************************************
Packit 2997f0
*  64-bits hash
Packit 2997f0
************************************************************************/
Packit 2997f0
typedef unsigned long long XXH64_hash_t;
Packit 2997f0
Packit 2997f0
/*! XXH64() :
Packit 2997f0
    Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
Packit 2997f0
    "seed" can be used to alter the result predictably.
Packit 2997f0
    This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
Packit 2997f0
*/
Packit 2997f0
XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
Packit 2997f0
Packit 2997f0
/*======   Streaming   ======*/
Packit 2997f0
typedef struct XXH64_state_s XXH64_state_t;   /* incomplete type */
Packit 2997f0
XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode  XXH64_freeState(XXH64_state_t* statePtr);
Packit 2997f0
XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* dst_state, const XXH64_state_t* src_state);
Packit 2997f0
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode XXH64_reset  (XXH64_state_t* statePtr, unsigned long long seed);
Packit 2997f0
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
Packit 2997f0
XXH_PUBLIC_API XXH64_hash_t  XXH64_digest (const XXH64_state_t* statePtr);
Packit 2997f0
Packit 2997f0
/*======   Canonical representation   ======*/
Packit 2997f0
typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
Packit 2997f0
XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
Packit 2997f0
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
Packit 2997f0
#endif  /* XXH_NO_LONG_LONG */
Packit 2997f0
Packit 2997f0
Packit 2997f0
#ifdef XXH_STATIC_LINKING_ONLY
Packit 2997f0
Packit 2997f0
/* ================================================================================================
Packit 2997f0
   This section contains definitions which are not guaranteed to remain stable.
Packit 2997f0
   They may change in future versions, becoming incompatible with a different version of the library.
Packit 2997f0
   They shall only be used with static linking.
Packit 2997f0
   Never use these definitions in association with dynamic linking !
Packit 2997f0
=================================================================================================== */
Packit 2997f0
Packit 2997f0
/* These definitions are only meant to allow allocation of XXH state
Packit 2997f0
   statically, on stack, or in a struct for example.
Packit 2997f0
   Do not use members directly. */
Packit 2997f0
Packit 2997f0
   struct XXH32_state_s {
Packit 2997f0
       unsigned total_len_32;
Packit 2997f0
       unsigned large_len;
Packit 2997f0
       unsigned v1;
Packit 2997f0
       unsigned v2;
Packit 2997f0
       unsigned v3;
Packit 2997f0
       unsigned v4;
Packit 2997f0
       unsigned mem32[4];   /* buffer defined as U32 for alignment */
Packit 2997f0
       unsigned memsize;
Packit 2997f0
       unsigned reserved;   /* never read nor write, will be removed in a future version */
Packit 2997f0
   };   /* typedef'd to XXH32_state_t */
Packit 2997f0
Packit 2997f0
#ifndef XXH_NO_LONG_LONG
Packit 2997f0
   struct XXH64_state_s {
Packit 2997f0
       unsigned long long total_len;
Packit 2997f0
       unsigned long long v1;
Packit 2997f0
       unsigned long long v2;
Packit 2997f0
       unsigned long long v3;
Packit 2997f0
       unsigned long long v4;
Packit 2997f0
       unsigned long long mem64[4];   /* buffer defined as U64 for alignment */
Packit 2997f0
       unsigned memsize;
Packit 2997f0
       unsigned reserved[2];          /* never read nor write, will be removed in a future version */
Packit 2997f0
   };   /* typedef'd to XXH64_state_t */
Packit 2997f0
#endif
Packit 2997f0
Packit 2997f0
#  ifdef XXH_PRIVATE_API
Packit 2997f0
#    include "xxhash.c"   /* include xxhash function bodies as `static`, for inlining */
Packit 2997f0
#  endif
Packit 2997f0
Packit 2997f0
#endif /* XXH_STATIC_LINKING_ONLY */
Packit 2997f0
Packit 2997f0
Packit 2997f0
#if defined (__cplusplus)
Packit 2997f0
}
Packit 2997f0
#endif
Packit 2997f0
Packit 2997f0
#endif /* XXHASH_H_5627135585666179 */