kusano 7d535a
/*
kusano 7d535a
xxHash - Fast Hash algorithm
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
kusano 7d535a
/**************************************
kusano 7d535a
*  Tuning parameters
kusano 7d535a
**************************************/
kusano 7d535a
/* Unaligned memory access is automatically enabled for "common" CPU, such as x86.
kusano 7d535a
 * For others CPU, the compiler will be more cautious, and insert extra code to ensure aligned access is respected.
kusano 7d535a
 * If you know your target CPU supports unaligned memory access, you want to force this option manually to improve performance.
kusano 7d535a
 * You can also enable this parameter if you know your input data will always be aligned (boundaries of 4, for U32).
kusano 7d535a
 */
kusano 7d535a
#if defined(__ARM_FEATURE_UNALIGNED) || defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
kusano 7d535a
#  define XXH_USE_UNALIGNED_ACCESS 1
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
/* XXH_ACCEPT_NULL_INPUT_POINTER :
kusano 7d535a
 * If the input pointer is a null pointer, xxHash default behavior is to trigger a memory access error, since it is a bad pointer.
kusano 7d535a
 * When this option is enabled, xxHash output for null input pointers will be the same as a null-length input.
kusano 7d535a
 * By default, this option is disabled. To enable it, uncomment below define :
kusano 7d535a
 */
kusano 7d535a
/* #define XXH_ACCEPT_NULL_INPUT_POINTER 1 */
kusano 7d535a
kusano 7d535a
/* XXH_FORCE_NATIVE_FORMAT :
kusano 7d535a
 * By default, xxHash library provides endian-independant Hash values, based on little-endian convention.
kusano 7d535a
 * Results are therefore identical for little-endian and big-endian CPU.
kusano 7d535a
 * This comes at a performance cost for big-endian CPU, since some swapping is required to emulate little-endian format.
kusano 7d535a
 * Should endian-independance be of no importance for your application, you may set the #define below to 1.
kusano 7d535a
 * It will improve speed for Big-endian CPU.
kusano 7d535a
 * This option has no impact on Little_Endian CPU.
kusano 7d535a
 */
kusano 7d535a
#define XXH_FORCE_NATIVE_FORMAT 0
kusano 7d535a
kusano 7d535a
kusano 7d535a
/**************************************
kusano 7d535a
*  Compiler Specific Options
kusano 7d535a
***************************************/
kusano 7d535a
#ifdef _MSC_VER    /* Visual Studio */
kusano 7d535a
#  pragma warning(disable : 4127)      /* disable: C4127: conditional expression is constant */
kusano 7d535a
#  define FORCE_INLINE static __forceinline
kusano 7d535a
#else
kusano 7d535a
#  if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L   /* C99 */
kusano 7d535a
#    ifdef __GNUC__
kusano 7d535a
#      define FORCE_INLINE static inline __attribute__((always_inline))
kusano 7d535a
#    else
kusano 7d535a
#      define FORCE_INLINE static inline
kusano 7d535a
#    endif
kusano 7d535a
#  else
kusano 7d535a
#    define FORCE_INLINE static
kusano 7d535a
#  endif /* __STDC_VERSION__ */
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/**************************************
kusano 7d535a
*  Includes & Memory related functions
kusano 7d535a
***************************************/
kusano 7d535a
#include "xxhash.h"
kusano 7d535a
/* Modify the local functions below should you wish to use some other memory routines */
kusano 7d535a
/* for malloc(), free() */
kusano 7d535a
#include <stdlib.h></stdlib.h>
kusano 7d535a
static void* XXH_malloc(size_t s) { return malloc(s); }
kusano 7d535a
static void  XXH_free  (void* p)  { free(p); }
kusano 7d535a
/* for memcpy() */
kusano 7d535a
#include <string.h></string.h>
kusano 7d535a
static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcpy(dest,src,size); }
kusano 7d535a
kusano 7d535a
kusano 7d535a
/**************************************
kusano 7d535a
*  Basic Types
kusano 7d535a
***************************************/
kusano 7d535a
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L   /* C99 */
kusano 7d535a
# include <stdint.h></stdint.h>
kusano 7d535a
  typedef uint8_t  BYTE;
kusano 7d535a
  typedef uint16_t U16;
kusano 7d535a
  typedef uint32_t U32;
kusano 7d535a
  typedef  int32_t S32;
kusano 7d535a
  typedef uint64_t U64;
kusano 7d535a
#else
kusano 7d535a
  typedef unsigned char      BYTE;
kusano 7d535a
  typedef unsigned short     U16;
kusano 7d535a
  typedef unsigned int       U32;
kusano 7d535a
  typedef   signed int       S32;
kusano 7d535a
  typedef unsigned long long U64;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
static U32 XXH_read32(const void* memPtr)
kusano 7d535a
{
kusano 7d535a
    U32 val32;
kusano 7d535a
    memcpy(&val32, memPtr, 4);
kusano 7d535a
    return val32;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
static U64 XXH_read64(const void* memPtr)
kusano 7d535a
{
kusano 7d535a
    U64 val64;
kusano 7d535a
    memcpy(&val64, memPtr, 8);
kusano 7d535a
    return val64;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
/******************************************
kusano 7d535a
*  Compiler-specific Functions and Macros
kusano 7d535a
******************************************/
kusano 7d535a
#define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
kusano 7d535a
kusano 7d535a
/* Note : although _rotl exists for minGW (GCC under windows), performance seems poor */
kusano 7d535a
#if defined(_MSC_VER)
kusano 7d535a
#  define XXH_rotl32(x,r) _rotl(x,r)
kusano 7d535a
#  define XXH_rotl64(x,r) _rotl64(x,r)
kusano 7d535a
#else
kusano 7d535a
#  define XXH_rotl32(x,r) ((x << r) | (x >> (32 - r)))
kusano 7d535a
#  define XXH_rotl64(x,r) ((x << r) | (x >> (64 - r)))
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
#if defined(_MSC_VER)     /* Visual Studio */
kusano 7d535a
#  define XXH_swap32 _byteswap_ulong
kusano 7d535a
#  define XXH_swap64 _byteswap_uint64
kusano 7d535a
#elif GCC_VERSION >= 403
kusano 7d535a
#  define XXH_swap32 __builtin_bswap32
kusano 7d535a
#  define XXH_swap64 __builtin_bswap64
kusano 7d535a
#else
kusano 7d535a
static U32 XXH_swap32 (U32 x)
kusano 7d535a
{
kusano 7d535a
    return  ((x << 24) & 0xff000000 ) |
kusano 7d535a
            ((x <<  8) & 0x00ff0000 ) |
kusano 7d535a
            ((x >>  8) & 0x0000ff00 ) |
kusano 7d535a
            ((x >> 24) & 0x000000ff );
kusano 7d535a
}
kusano 7d535a
static U64 XXH_swap64 (U64 x)
kusano 7d535a
{
kusano 7d535a
    return  ((x << 56) & 0xff00000000000000ULL) |
kusano 7d535a
            ((x << 40) & 0x00ff000000000000ULL) |
kusano 7d535a
            ((x << 24) & 0x0000ff0000000000ULL) |
kusano 7d535a
            ((x << 8)  & 0x000000ff00000000ULL) |
kusano 7d535a
            ((x >> 8)  & 0x00000000ff000000ULL) |
kusano 7d535a
            ((x >> 24) & 0x0000000000ff0000ULL) |
kusano 7d535a
            ((x >> 40) & 0x000000000000ff00ULL) |
kusano 7d535a
            ((x >> 56) & 0x00000000000000ffULL);
kusano 7d535a
}
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***************************************
kusano 7d535a
*  Architecture Macros
kusano 7d535a
***************************************/
kusano 7d535a
typedef enum { XXH_bigEndian=0, XXH_littleEndian=1 } XXH_endianess;
kusano 7d535a
#ifndef XXH_CPU_LITTLE_ENDIAN   /* XXH_CPU_LITTLE_ENDIAN can be defined externally, for example using a compiler switch */
kusano 7d535a
static const int one = 1;
kusano 7d535a
#   define XXH_CPU_LITTLE_ENDIAN   (*(const char*)(&one))
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Memory reads
kusano 7d535a
*****************************/
kusano 7d535a
typedef enum { XXH_aligned, XXH_unaligned } XXH_alignment;
kusano 7d535a
kusano 7d535a
FORCE_INLINE U32 XXH_readLE32_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
kusano 7d535a
{
kusano 7d535a
    if (align==XXH_unaligned)
kusano 7d535a
        return endian==XXH_littleEndian ? XXH_read32(ptr) : XXH_swap32(XXH_read32(ptr));
kusano 7d535a
    else
kusano 7d535a
        return endian==XXH_littleEndian ? *(const U32*)ptr : XXH_swap32(*(const U32*)ptr);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
FORCE_INLINE U32 XXH_readLE32(const void* ptr, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    return XXH_readLE32_align(ptr, endian, XXH_unaligned);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
FORCE_INLINE U64 XXH_readLE64_align(const void* ptr, XXH_endianess endian, XXH_alignment align)
kusano 7d535a
{
kusano 7d535a
    if (align==XXH_unaligned)
kusano 7d535a
        return endian==XXH_littleEndian ? XXH_read64(ptr) : XXH_swap64(XXH_read64(ptr));
kusano 7d535a
    else
kusano 7d535a
        return endian==XXH_littleEndian ? *(const U64*)ptr : XXH_swap64(*(const U64*)ptr);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
FORCE_INLINE U64 XXH_readLE64(const void* ptr, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    return XXH_readLE64_align(ptr, endian, XXH_unaligned);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***************************************
kusano 7d535a
*  Macros
kusano 7d535a
***************************************/
kusano 7d535a
#define XXH_STATIC_ASSERT(c)   { enum { XXH_static_assert = 1/(!!(c)) }; }    /* use only *after* variable declarations */
kusano 7d535a
kusano 7d535a
kusano 7d535a
/***************************************
kusano 7d535a
*  Constants
kusano 7d535a
***************************************/
kusano 7d535a
#define PRIME32_1   2654435761U
kusano 7d535a
#define PRIME32_2   2246822519U
kusano 7d535a
#define PRIME32_3   3266489917U
kusano 7d535a
#define PRIME32_4    668265263U
kusano 7d535a
#define PRIME32_5    374761393U
kusano 7d535a
kusano 7d535a
#define PRIME64_1 11400714785074694791ULL
kusano 7d535a
#define PRIME64_2 14029467366897019727ULL
kusano 7d535a
#define PRIME64_3  1609587929392839161ULL
kusano 7d535a
#define PRIME64_4  9650029242287828579ULL
kusano 7d535a
#define PRIME64_5  2870177450012600261ULL
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*****************************
kusano 7d535a
*  Simple Hash Functions
kusano 7d535a
*****************************/
kusano 7d535a
FORCE_INLINE U32 XXH32_endian_align(const void* input, size_t len, U32 seed, XXH_endianess endian, XXH_alignment align)
kusano 7d535a
{
kusano 7d535a
    const BYTE* p = (const BYTE*)input;
kusano 7d535a
    const BYTE* bEnd = p + len;
kusano 7d535a
    U32 h32;
kusano 7d535a
#define XXH_get32bits(p) XXH_readLE32_align(p, endian, align)
kusano 7d535a
kusano 7d535a
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
kusano 7d535a
    if (p==NULL)
kusano 7d535a
    {
kusano 7d535a
        len=0;
kusano 7d535a
        bEnd=p=(const BYTE*)(size_t)16;
kusano 7d535a
    }
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
    if (len>=16)
kusano 7d535a
    {
kusano 7d535a
        const BYTE* const limit = bEnd - 16;
kusano 7d535a
        U32 v1 = seed + PRIME32_1 + PRIME32_2;
kusano 7d535a
        U32 v2 = seed + PRIME32_2;
kusano 7d535a
        U32 v3 = seed + 0;
kusano 7d535a
        U32 v4 = seed - PRIME32_1;
kusano 7d535a
kusano 7d535a
        do
kusano 7d535a
        {
kusano 7d535a
            v1 += XXH_get32bits(p) * PRIME32_2;
kusano 7d535a
            v1 = XXH_rotl32(v1, 13);
kusano 7d535a
            v1 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v2 += XXH_get32bits(p) * PRIME32_2;
kusano 7d535a
            v2 = XXH_rotl32(v2, 13);
kusano 7d535a
            v2 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v3 += XXH_get32bits(p) * PRIME32_2;
kusano 7d535a
            v3 = XXH_rotl32(v3, 13);
kusano 7d535a
            v3 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v4 += XXH_get32bits(p) * PRIME32_2;
kusano 7d535a
            v4 = XXH_rotl32(v4, 13);
kusano 7d535a
            v4 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
        }
kusano 7d535a
        while (p<=limit);
kusano 7d535a
kusano 7d535a
        h32 = XXH_rotl32(v1, 1) + XXH_rotl32(v2, 7) + XXH_rotl32(v3, 12) + XXH_rotl32(v4, 18);
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
    {
kusano 7d535a
        h32  = seed + PRIME32_5;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h32 += (U32) len;
kusano 7d535a
kusano 7d535a
    while (p+4<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        h32 += XXH_get32bits(p) * PRIME32_3;
kusano 7d535a
        h32  = XXH_rotl32(h32, 17) * PRIME32_4 ;
kusano 7d535a
        p+=4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    while (p
kusano 7d535a
    {
kusano 7d535a
        h32 += (*p) * PRIME32_5;
kusano 7d535a
        h32 = XXH_rotl32(h32, 11) * PRIME32_1 ;
kusano 7d535a
        p++;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h32 ^= h32 >> 15;
kusano 7d535a
    h32 *= PRIME32_2;
kusano 7d535a
    h32 ^= h32 >> 13;
kusano 7d535a
    h32 *= PRIME32_3;
kusano 7d535a
    h32 ^= h32 >> 16;
kusano 7d535a
kusano 7d535a
    return h32;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
unsigned XXH32 (const void* input, size_t len, unsigned seed)
kusano 7d535a
{
kusano 7d535a
#if 0
kusano 7d535a
    /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
kusano 7d535a
    XXH32_state_t state;
kusano 7d535a
    XXH32_reset(&state, seed);
kusano 7d535a
    XXH32_update(&state, input, len);
kusano 7d535a
    return XXH32_digest(&state);
kusano 7d535a
#else
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
#  if !defined(XXH_USE_UNALIGNED_ACCESS)
kusano 7d535a
    if ((((size_t)input) & 3) == 0)   /* Input is 4-bytes aligned, leverage the speed benefit */
kusano 7d535a
    {
kusano 7d535a
        if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
            return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
kusano 7d535a
        else
kusano 7d535a
            return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
kusano 7d535a
    }
kusano 7d535a
#  endif
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
kusano 7d535a
    else
kusano 7d535a
        return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
kusano 7d535a
#endif
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
FORCE_INLINE U64 XXH64_endian_align(const void* input, size_t len, U64 seed, XXH_endianess endian, XXH_alignment align)
kusano 7d535a
{
kusano 7d535a
    const BYTE* p = (const BYTE*)input;
kusano 7d535a
    const BYTE* bEnd = p + len;
kusano 7d535a
    U64 h64;
kusano 7d535a
#define XXH_get64bits(p) XXH_readLE64_align(p, endian, align)
kusano 7d535a
kusano 7d535a
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
kusano 7d535a
    if (p==NULL)
kusano 7d535a
    {
kusano 7d535a
        len=0;
kusano 7d535a
        bEnd=p=(const BYTE*)(size_t)32;
kusano 7d535a
    }
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
    if (len>=32)
kusano 7d535a
    {
kusano 7d535a
        const BYTE* const limit = bEnd - 32;
kusano 7d535a
        U64 v1 = seed + PRIME64_1 + PRIME64_2;
kusano 7d535a
        U64 v2 = seed + PRIME64_2;
kusano 7d535a
        U64 v3 = seed + 0;
kusano 7d535a
        U64 v4 = seed - PRIME64_1;
kusano 7d535a
kusano 7d535a
        do
kusano 7d535a
        {
kusano 7d535a
            v1 += XXH_get64bits(p) * PRIME64_2;
kusano 7d535a
            p+=8;
kusano 7d535a
            v1 = XXH_rotl64(v1, 31);
kusano 7d535a
            v1 *= PRIME64_1;
kusano 7d535a
            v2 += XXH_get64bits(p) * PRIME64_2;
kusano 7d535a
            p+=8;
kusano 7d535a
            v2 = XXH_rotl64(v2, 31);
kusano 7d535a
            v2 *= PRIME64_1;
kusano 7d535a
            v3 += XXH_get64bits(p) * PRIME64_2;
kusano 7d535a
            p+=8;
kusano 7d535a
            v3 = XXH_rotl64(v3, 31);
kusano 7d535a
            v3 *= PRIME64_1;
kusano 7d535a
            v4 += XXH_get64bits(p) * PRIME64_2;
kusano 7d535a
            p+=8;
kusano 7d535a
            v4 = XXH_rotl64(v4, 31);
kusano 7d535a
            v4 *= PRIME64_1;
kusano 7d535a
        }
kusano 7d535a
        while (p<=limit);
kusano 7d535a
kusano 7d535a
        h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
kusano 7d535a
kusano 7d535a
        v1 *= PRIME64_2;
kusano 7d535a
        v1 = XXH_rotl64(v1, 31);
kusano 7d535a
        v1 *= PRIME64_1;
kusano 7d535a
        h64 ^= v1;
kusano 7d535a
        h64 = h64 * PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v2 *= PRIME64_2;
kusano 7d535a
        v2 = XXH_rotl64(v2, 31);
kusano 7d535a
        v2 *= PRIME64_1;
kusano 7d535a
        h64 ^= v2;
kusano 7d535a
        h64 = h64 * PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v3 *= PRIME64_2;
kusano 7d535a
        v3 = XXH_rotl64(v3, 31);
kusano 7d535a
        v3 *= PRIME64_1;
kusano 7d535a
        h64 ^= v3;
kusano 7d535a
        h64 = h64 * PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v4 *= PRIME64_2;
kusano 7d535a
        v4 = XXH_rotl64(v4, 31);
kusano 7d535a
        v4 *= PRIME64_1;
kusano 7d535a
        h64 ^= v4;
kusano 7d535a
        h64 = h64 * PRIME64_1 + PRIME64_4;
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
    {
kusano 7d535a
        h64  = seed + PRIME64_5;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h64 += (U64) len;
kusano 7d535a
kusano 7d535a
    while (p+8<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        U64 k1 = XXH_get64bits(p);
kusano 7d535a
        k1 *= PRIME64_2;
kusano 7d535a
        k1 = XXH_rotl64(k1,31);
kusano 7d535a
        k1 *= PRIME64_1;
kusano 7d535a
        h64 ^= k1;
kusano 7d535a
        h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
kusano 7d535a
        p+=8;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p+4<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        h64 ^= (U64)(XXH_get32bits(p)) * PRIME64_1;
kusano 7d535a
        h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
kusano 7d535a
        p+=4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    while (p
kusano 7d535a
    {
kusano 7d535a
        h64 ^= (*p) * PRIME64_5;
kusano 7d535a
        h64 = XXH_rotl64(h64, 11) * PRIME64_1;
kusano 7d535a
        p++;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h64 ^= h64 >> 33;
kusano 7d535a
    h64 *= PRIME64_2;
kusano 7d535a
    h64 ^= h64 >> 29;
kusano 7d535a
    h64 *= PRIME64_3;
kusano 7d535a
    h64 ^= h64 >> 32;
kusano 7d535a
kusano 7d535a
    return h64;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
unsigned long long XXH64 (const void* input, size_t len, unsigned long long seed)
kusano 7d535a
{
kusano 7d535a
#if 0
kusano 7d535a
    /* Simple version, good for code maintenance, but unfortunately slow for small inputs */
kusano 7d535a
    XXH64_state_t state;
kusano 7d535a
    XXH64_reset(&state, seed);
kusano 7d535a
    XXH64_update(&state, input, len);
kusano 7d535a
    return XXH64_digest(&state);
kusano 7d535a
#else
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
#  if !defined(XXH_USE_UNALIGNED_ACCESS)
kusano 7d535a
    if ((((size_t)input) & 7)==0)   /* Input is aligned, let's leverage the speed advantage */
kusano 7d535a
    {
kusano 7d535a
        if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
            return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned);
kusano 7d535a
        else
kusano 7d535a
            return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned);
kusano 7d535a
    }
kusano 7d535a
#  endif
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH64_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned);
kusano 7d535a
    else
kusano 7d535a
        return XXH64_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned);
kusano 7d535a
#endif
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
/****************************************************
kusano 7d535a
*  Advanced Hash Functions
kusano 7d535a
****************************************************/
kusano 7d535a
kusano 7d535a
/*** Allocation ***/
kusano 7d535a
typedef struct
kusano 7d535a
{
kusano 7d535a
    U64 total_len;
kusano 7d535a
    U32 seed;
kusano 7d535a
    U32 v1;
kusano 7d535a
    U32 v2;
kusano 7d535a
    U32 v3;
kusano 7d535a
    U32 v4;
kusano 7d535a
    U32 mem32[4];   /* defined as U32 for alignment */
kusano 7d535a
    U32 memsize;
kusano 7d535a
} XXH_istate32_t;
kusano 7d535a
kusano 7d535a
typedef struct
kusano 7d535a
{
kusano 7d535a
    U64 total_len;
kusano 7d535a
    U64 seed;
kusano 7d535a
    U64 v1;
kusano 7d535a
    U64 v2;
kusano 7d535a
    U64 v3;
kusano 7d535a
    U64 v4;
kusano 7d535a
    U64 mem64[4];   /* defined as U64 for alignment */
kusano 7d535a
    U32 memsize;
kusano 7d535a
} XXH_istate64_t;
kusano 7d535a
kusano 7d535a
kusano 7d535a
XXH32_state_t* XXH32_createState(void)
kusano 7d535a
{
kusano 7d535a
    XXH_STATIC_ASSERT(sizeof(XXH32_state_t) >= sizeof(XXH_istate32_t));   /* A compilation error here means XXH32_state_t is not large enough */
kusano 7d535a
    return (XXH32_state_t*)XXH_malloc(sizeof(XXH32_state_t));
kusano 7d535a
}
kusano 7d535a
XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr)
kusano 7d535a
{
kusano 7d535a
    XXH_free(statePtr);
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
XXH64_state_t* XXH64_createState(void)
kusano 7d535a
{
kusano 7d535a
    XXH_STATIC_ASSERT(sizeof(XXH64_state_t) >= sizeof(XXH_istate64_t));   /* A compilation error here means XXH64_state_t is not large enough */
kusano 7d535a
    return (XXH64_state_t*)XXH_malloc(sizeof(XXH64_state_t));
kusano 7d535a
}
kusano 7d535a
XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
kusano 7d535a
{
kusano 7d535a
    XXH_free(statePtr);
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
/*** Hash feed ***/
kusano 7d535a
kusano 7d535a
XXH_errorcode XXH32_reset(XXH32_state_t* state_in, U32 seed)
kusano 7d535a
{
kusano 7d535a
    XXH_istate32_t* state = (XXH_istate32_t*) state_in;
kusano 7d535a
    state->seed = seed;
kusano 7d535a
    state->v1 = seed + PRIME32_1 + PRIME32_2;
kusano 7d535a
    state->v2 = seed + PRIME32_2;
kusano 7d535a
    state->v3 = seed + 0;
kusano 7d535a
    state->v4 = seed - PRIME32_1;
kusano 7d535a
    state->total_len = 0;
kusano 7d535a
    state->memsize = 0;
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
XXH_errorcode XXH64_reset(XXH64_state_t* state_in, unsigned long long seed)
kusano 7d535a
{
kusano 7d535a
    XXH_istate64_t* state = (XXH_istate64_t*) state_in;
kusano 7d535a
    state->seed = seed;
kusano 7d535a
    state->v1 = seed + PRIME64_1 + PRIME64_2;
kusano 7d535a
    state->v2 = seed + PRIME64_2;
kusano 7d535a
    state->v3 = seed + 0;
kusano 7d535a
    state->v4 = seed - PRIME64_1;
kusano 7d535a
    state->total_len = 0;
kusano 7d535a
    state->memsize = 0;
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state_in, const void* input, size_t len, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    XXH_istate32_t* state = (XXH_istate32_t *) state_in;
kusano 7d535a
    const BYTE* p = (const BYTE*)input;
kusano 7d535a
    const BYTE* const bEnd = p + len;
kusano 7d535a
kusano 7d535a
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
kusano 7d535a
    if (input==NULL) return XXH_ERROR;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
    state->total_len += len;
kusano 7d535a
kusano 7d535a
    if (state->memsize + len < 16)   /* fill in tmp buffer */
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
kusano 7d535a
        state->memsize += (U32)len;
kusano 7d535a
        return XXH_OK;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (state->memsize)   /* some data left from previous update */
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, 16-state->memsize);
kusano 7d535a
        {
kusano 7d535a
            const U32* p32 = state->mem32;
kusano 7d535a
            state->v1 += XXH_readLE32(p32, endian) * PRIME32_2;
kusano 7d535a
            state->v1 = XXH_rotl32(state->v1, 13);
kusano 7d535a
            state->v1 *= PRIME32_1;
kusano 7d535a
            p32++;
kusano 7d535a
            state->v2 += XXH_readLE32(p32, endian) * PRIME32_2;
kusano 7d535a
            state->v2 = XXH_rotl32(state->v2, 13);
kusano 7d535a
            state->v2 *= PRIME32_1;
kusano 7d535a
            p32++;
kusano 7d535a
            state->v3 += XXH_readLE32(p32, endian) * PRIME32_2;
kusano 7d535a
            state->v3 = XXH_rotl32(state->v3, 13);
kusano 7d535a
            state->v3 *= PRIME32_1;
kusano 7d535a
            p32++;
kusano 7d535a
            state->v4 += XXH_readLE32(p32, endian) * PRIME32_2;
kusano 7d535a
            state->v4 = XXH_rotl32(state->v4, 13);
kusano 7d535a
            state->v4 *= PRIME32_1;
kusano 7d535a
            p32++;
kusano 7d535a
        }
kusano 7d535a
        p += 16-state->memsize;
kusano 7d535a
        state->memsize = 0;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p <= bEnd-16)
kusano 7d535a
    {
kusano 7d535a
        const BYTE* const limit = bEnd - 16;
kusano 7d535a
        U32 v1 = state->v1;
kusano 7d535a
        U32 v2 = state->v2;
kusano 7d535a
        U32 v3 = state->v3;
kusano 7d535a
        U32 v4 = state->v4;
kusano 7d535a
kusano 7d535a
        do
kusano 7d535a
        {
kusano 7d535a
            v1 += XXH_readLE32(p, endian) * PRIME32_2;
kusano 7d535a
            v1 = XXH_rotl32(v1, 13);
kusano 7d535a
            v1 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v2 += XXH_readLE32(p, endian) * PRIME32_2;
kusano 7d535a
            v2 = XXH_rotl32(v2, 13);
kusano 7d535a
            v2 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v3 += XXH_readLE32(p, endian) * PRIME32_2;
kusano 7d535a
            v3 = XXH_rotl32(v3, 13);
kusano 7d535a
            v3 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
            v4 += XXH_readLE32(p, endian) * PRIME32_2;
kusano 7d535a
            v4 = XXH_rotl32(v4, 13);
kusano 7d535a
            v4 *= PRIME32_1;
kusano 7d535a
            p+=4;
kusano 7d535a
        }
kusano 7d535a
        while (p<=limit);
kusano 7d535a
kusano 7d535a
        state->v1 = v1;
kusano 7d535a
        state->v2 = v2;
kusano 7d535a
        state->v3 = v3;
kusano 7d535a
        state->v4 = v4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p < bEnd)
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy(state->mem32, p, bEnd-p);
kusano 7d535a
        state->memsize = (int)(bEnd-p);
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
XXH_errorcode XXH32_update (XXH32_state_t* state_in, const void* input, size_t len)
kusano 7d535a
{
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH32_update_endian(state_in, input, len, XXH_littleEndian);
kusano 7d535a
    else
kusano 7d535a
        return XXH32_update_endian(state_in, input, len, XXH_bigEndian);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state_in, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    const XXH_istate32_t* state = (const XXH_istate32_t*) state_in;
kusano 7d535a
    const BYTE * p = (const BYTE*)state->mem32;
kusano 7d535a
    const BYTE* bEnd = (const BYTE*)(state->mem32) + state->memsize;
kusano 7d535a
    U32 h32;
kusano 7d535a
kusano 7d535a
    if (state->total_len >= 16)
kusano 7d535a
    {
kusano 7d535a
        h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
    {
kusano 7d535a
        h32  = state->seed + PRIME32_5;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h32 += (U32) state->total_len;
kusano 7d535a
kusano 7d535a
    while (p+4<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        h32 += XXH_readLE32(p, endian) * PRIME32_3;
kusano 7d535a
        h32  = XXH_rotl32(h32, 17) * PRIME32_4;
kusano 7d535a
        p+=4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    while (p
kusano 7d535a
    {
kusano 7d535a
        h32 += (*p) * PRIME32_5;
kusano 7d535a
        h32 = XXH_rotl32(h32, 11) * PRIME32_1;
kusano 7d535a
        p++;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h32 ^= h32 >> 15;
kusano 7d535a
    h32 *= PRIME32_2;
kusano 7d535a
    h32 ^= h32 >> 13;
kusano 7d535a
    h32 *= PRIME32_3;
kusano 7d535a
    h32 ^= h32 >> 16;
kusano 7d535a
kusano 7d535a
    return h32;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
U32 XXH32_digest (const XXH32_state_t* state_in)
kusano 7d535a
{
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH32_digest_endian(state_in, XXH_littleEndian);
kusano 7d535a
    else
kusano 7d535a
        return XXH32_digest_endian(state_in, XXH_bigEndian);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state_in, const void* input, size_t len, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    XXH_istate64_t * state = (XXH_istate64_t *) state_in;
kusano 7d535a
    const BYTE* p = (const BYTE*)input;
kusano 7d535a
    const BYTE* const bEnd = p + len;
kusano 7d535a
kusano 7d535a
#ifdef XXH_ACCEPT_NULL_INPUT_POINTER
kusano 7d535a
    if (input==NULL) return XXH_ERROR;
kusano 7d535a
#endif
kusano 7d535a
kusano 7d535a
    state->total_len += len;
kusano 7d535a
kusano 7d535a
    if (state->memsize + len < 32)   /* fill in tmp buffer */
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, len);
kusano 7d535a
        state->memsize += (U32)len;
kusano 7d535a
        return XXH_OK;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (state->memsize)   /* some data left from previous update */
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy(((BYTE*)state->mem64) + state->memsize, input, 32-state->memsize);
kusano 7d535a
        {
kusano 7d535a
            const U64* p64 = state->mem64;
kusano 7d535a
            state->v1 += XXH_readLE64(p64, endian) * PRIME64_2;
kusano 7d535a
            state->v1 = XXH_rotl64(state->v1, 31);
kusano 7d535a
            state->v1 *= PRIME64_1;
kusano 7d535a
            p64++;
kusano 7d535a
            state->v2 += XXH_readLE64(p64, endian) * PRIME64_2;
kusano 7d535a
            state->v2 = XXH_rotl64(state->v2, 31);
kusano 7d535a
            state->v2 *= PRIME64_1;
kusano 7d535a
            p64++;
kusano 7d535a
            state->v3 += XXH_readLE64(p64, endian) * PRIME64_2;
kusano 7d535a
            state->v3 = XXH_rotl64(state->v3, 31);
kusano 7d535a
            state->v3 *= PRIME64_1;
kusano 7d535a
            p64++;
kusano 7d535a
            state->v4 += XXH_readLE64(p64, endian) * PRIME64_2;
kusano 7d535a
            state->v4 = XXH_rotl64(state->v4, 31);
kusano 7d535a
            state->v4 *= PRIME64_1;
kusano 7d535a
            p64++;
kusano 7d535a
        }
kusano 7d535a
        p += 32-state->memsize;
kusano 7d535a
        state->memsize = 0;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p+32 <= bEnd)
kusano 7d535a
    {
kusano 7d535a
        const BYTE* const limit = bEnd - 32;
kusano 7d535a
        U64 v1 = state->v1;
kusano 7d535a
        U64 v2 = state->v2;
kusano 7d535a
        U64 v3 = state->v3;
kusano 7d535a
        U64 v4 = state->v4;
kusano 7d535a
kusano 7d535a
        do
kusano 7d535a
        {
kusano 7d535a
            v1 += XXH_readLE64(p, endian) * PRIME64_2;
kusano 7d535a
            v1 = XXH_rotl64(v1, 31);
kusano 7d535a
            v1 *= PRIME64_1;
kusano 7d535a
            p+=8;
kusano 7d535a
            v2 += XXH_readLE64(p, endian) * PRIME64_2;
kusano 7d535a
            v2 = XXH_rotl64(v2, 31);
kusano 7d535a
            v2 *= PRIME64_1;
kusano 7d535a
            p+=8;
kusano 7d535a
            v3 += XXH_readLE64(p, endian) * PRIME64_2;
kusano 7d535a
            v3 = XXH_rotl64(v3, 31);
kusano 7d535a
            v3 *= PRIME64_1;
kusano 7d535a
            p+=8;
kusano 7d535a
            v4 += XXH_readLE64(p, endian) * PRIME64_2;
kusano 7d535a
            v4 = XXH_rotl64(v4, 31);
kusano 7d535a
            v4 *= PRIME64_1;
kusano 7d535a
            p+=8;
kusano 7d535a
        }
kusano 7d535a
        while (p<=limit);
kusano 7d535a
kusano 7d535a
        state->v1 = v1;
kusano 7d535a
        state->v2 = v2;
kusano 7d535a
        state->v3 = v3;
kusano 7d535a
        state->v4 = v4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p < bEnd)
kusano 7d535a
    {
kusano 7d535a
        XXH_memcpy(state->mem64, p, bEnd-p);
kusano 7d535a
        state->memsize = (int)(bEnd-p);
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    return XXH_OK;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
XXH_errorcode XXH64_update (XXH64_state_t* state_in, const void* input, size_t len)
kusano 7d535a
{
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH64_update_endian(state_in, input, len, XXH_littleEndian);
kusano 7d535a
    else
kusano 7d535a
        return XXH64_update_endian(state_in, input, len, XXH_bigEndian);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
kusano 7d535a
FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state_in, XXH_endianess endian)
kusano 7d535a
{
kusano 7d535a
    const XXH_istate64_t * state = (const XXH_istate64_t *) state_in;
kusano 7d535a
    const BYTE * p = (const BYTE*)state->mem64;
kusano 7d535a
    const BYTE* bEnd = (const BYTE*)state->mem64 + state->memsize;
kusano 7d535a
    U64 h64;
kusano 7d535a
kusano 7d535a
    if (state->total_len >= 32)
kusano 7d535a
    {
kusano 7d535a
        U64 v1 = state->v1;
kusano 7d535a
        U64 v2 = state->v2;
kusano 7d535a
        U64 v3 = state->v3;
kusano 7d535a
        U64 v4 = state->v4;
kusano 7d535a
kusano 7d535a
        h64 = XXH_rotl64(v1, 1) + XXH_rotl64(v2, 7) + XXH_rotl64(v3, 12) + XXH_rotl64(v4, 18);
kusano 7d535a
kusano 7d535a
        v1 *= PRIME64_2;
kusano 7d535a
        v1 = XXH_rotl64(v1, 31);
kusano 7d535a
        v1 *= PRIME64_1;
kusano 7d535a
        h64 ^= v1;
kusano 7d535a
        h64 = h64*PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v2 *= PRIME64_2;
kusano 7d535a
        v2 = XXH_rotl64(v2, 31);
kusano 7d535a
        v2 *= PRIME64_1;
kusano 7d535a
        h64 ^= v2;
kusano 7d535a
        h64 = h64*PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v3 *= PRIME64_2;
kusano 7d535a
        v3 = XXH_rotl64(v3, 31);
kusano 7d535a
        v3 *= PRIME64_1;
kusano 7d535a
        h64 ^= v3;
kusano 7d535a
        h64 = h64*PRIME64_1 + PRIME64_4;
kusano 7d535a
kusano 7d535a
        v4 *= PRIME64_2;
kusano 7d535a
        v4 = XXH_rotl64(v4, 31);
kusano 7d535a
        v4 *= PRIME64_1;
kusano 7d535a
        h64 ^= v4;
kusano 7d535a
        h64 = h64*PRIME64_1 + PRIME64_4;
kusano 7d535a
    }
kusano 7d535a
    else
kusano 7d535a
    {
kusano 7d535a
        h64  = state->seed + PRIME64_5;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h64 += (U64) state->total_len;
kusano 7d535a
kusano 7d535a
    while (p+8<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        U64 k1 = XXH_readLE64(p, endian);
kusano 7d535a
        k1 *= PRIME64_2;
kusano 7d535a
        k1 = XXH_rotl64(k1,31);
kusano 7d535a
        k1 *= PRIME64_1;
kusano 7d535a
        h64 ^= k1;
kusano 7d535a
        h64 = XXH_rotl64(h64,27) * PRIME64_1 + PRIME64_4;
kusano 7d535a
        p+=8;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    if (p+4<=bEnd)
kusano 7d535a
    {
kusano 7d535a
        h64 ^= (U64)(XXH_readLE32(p, endian)) * PRIME64_1;
kusano 7d535a
        h64 = XXH_rotl64(h64, 23) * PRIME64_2 + PRIME64_3;
kusano 7d535a
        p+=4;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    while (p
kusano 7d535a
    {
kusano 7d535a
        h64 ^= (*p) * PRIME64_5;
kusano 7d535a
        h64 = XXH_rotl64(h64, 11) * PRIME64_1;
kusano 7d535a
        p++;
kusano 7d535a
    }
kusano 7d535a
kusano 7d535a
    h64 ^= h64 >> 33;
kusano 7d535a
    h64 *= PRIME64_2;
kusano 7d535a
    h64 ^= h64 >> 29;
kusano 7d535a
    h64 *= PRIME64_3;
kusano 7d535a
    h64 ^= h64 >> 32;
kusano 7d535a
kusano 7d535a
    return h64;
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
kusano 7d535a
unsigned long long XXH64_digest (const XXH64_state_t* state_in)
kusano 7d535a
{
kusano 7d535a
    XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN;
kusano 7d535a
kusano 7d535a
    if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT)
kusano 7d535a
        return XXH64_digest_endian(state_in, XXH_littleEndian);
kusano 7d535a
    else
kusano 7d535a
        return XXH64_digest_endian(state_in, XXH_bigEndian);
kusano 7d535a
}
kusano 7d535a
kusano 7d535a