extzstd 0.0.3.CONCEPT-x86-mingw32 → 0.1-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/LICENSE +6 -6
  4. data/README.md +35 -22
  5. data/contrib/zstd/LICENSE +13 -9
  6. data/contrib/zstd/README.md +37 -44
  7. data/contrib/zstd/common/entropy_common.c +33 -39
  8. data/contrib/zstd/common/error_private.c +43 -0
  9. data/contrib/zstd/common/error_private.h +11 -60
  10. data/contrib/zstd/common/fse.h +11 -5
  11. data/contrib/zstd/common/fse_decompress.c +14 -16
  12. data/contrib/zstd/common/huf.h +1 -1
  13. data/contrib/zstd/common/mem.h +36 -43
  14. data/contrib/zstd/common/xxhash.c +31 -18
  15. data/contrib/zstd/common/xxhash.h +71 -35
  16. data/contrib/zstd/common/zbuff.h +29 -35
  17. data/contrib/zstd/common/zstd_common.c +24 -32
  18. data/contrib/zstd/common/zstd_errors.h +60 -0
  19. data/contrib/zstd/common/zstd_internal.h +109 -80
  20. data/contrib/zstd/compress/fse_compress.c +9 -6
  21. data/contrib/zstd/compress/huf_compress.c +30 -74
  22. data/contrib/zstd/compress/zbuff_compress.c +43 -51
  23. data/contrib/zstd/compress/zstd_compress.c +953 -763
  24. data/contrib/zstd/compress/zstd_opt.h +115 -261
  25. data/contrib/zstd/decompress/huf_decompress.c +29 -40
  26. data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
  27. data/contrib/zstd/decompress/zstd_decompress.c +976 -496
  28. data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
  29. data/contrib/zstd/dictBuilder/zdict.c +194 -229
  30. data/contrib/zstd/dictBuilder/zdict.h +66 -68
  31. data/contrib/zstd/legacy/zstd_legacy.h +168 -49
  32. data/contrib/zstd/legacy/zstd_v01.c +95 -178
  33. data/contrib/zstd/legacy/zstd_v01.h +12 -32
  34. data/contrib/zstd/legacy/zstd_v02.c +48 -274
  35. data/contrib/zstd/legacy/zstd_v02.h +12 -32
  36. data/contrib/zstd/legacy/zstd_v03.c +48 -274
  37. data/contrib/zstd/legacy/zstd_v03.h +12 -32
  38. data/contrib/zstd/legacy/zstd_v04.c +63 -320
  39. data/contrib/zstd/legacy/zstd_v04.h +13 -33
  40. data/contrib/zstd/legacy/zstd_v05.c +80 -345
  41. data/contrib/zstd/legacy/zstd_v05.h +9 -31
  42. data/contrib/zstd/legacy/zstd_v06.c +48 -458
  43. data/contrib/zstd/legacy/zstd_v06.h +41 -67
  44. data/contrib/zstd/legacy/zstd_v07.c +4544 -0
  45. data/contrib/zstd/legacy/zstd_v07.h +173 -0
  46. data/contrib/zstd/zstd.h +640 -0
  47. data/ext/extconf.rb +7 -3
  48. data/ext/extzstd.c +263 -106
  49. data/ext/extzstd.h +8 -6
  50. data/ext/extzstd_nogvls.h +0 -117
  51. data/ext/extzstd_stream.c +347 -0
  52. data/ext/zstd_common.c +8 -0
  53. data/ext/zstd_compress.c +6 -0
  54. data/ext/zstd_decompress.c +5 -0
  55. data/ext/zstd_dictbuilder.c +5 -0
  56. data/ext/zstd_legacy_v07.c +1 -0
  57. data/gemstub.rb +18 -16
  58. data/lib/2.1/extzstd.so +0 -0
  59. data/lib/2.2/extzstd.so +0 -0
  60. data/lib/2.3/extzstd.so +0 -0
  61. data/lib/extzstd/version.rb +1 -1
  62. data/lib/extzstd.rb +77 -43
  63. data/test/test_basic.rb +11 -6
  64. metadata +23 -11
  65. data/contrib/zstd/common/error_public.h +0 -77
  66. data/contrib/zstd/common/zstd.h +0 -475
  67. data/ext/extzstd_buffered.c +0 -265
  68. data/ext/zstd_amalgam.c +0 -18
  69. data/lib/2.0/extzstd.so +0 -0
@@ -42,12 +42,15 @@
42
42
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
43
43
  # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
44
44
  #else
45
- # ifdef __GNUC__
46
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
47
- # define FORCE_INLINE static inline __attribute__((always_inline))
45
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
46
+ # ifdef __GNUC__
47
+ # define FORCE_INLINE static inline __attribute__((always_inline))
48
+ # else
49
+ # define FORCE_INLINE static inline
50
+ # endif
48
51
  # else
49
- # define FORCE_INLINE static inline
50
- # endif
52
+ # define FORCE_INLINE static
53
+ # endif /* __STDC_VERSION__ */
51
54
  #endif
52
55
 
53
56
 
@@ -68,6 +71,9 @@
68
71
  #define FSE_isError ERR_isError
69
72
  #define FSE_STATIC_ASSERT(c) { enum { FSE_static_assert = 1/(int)(!!(c)) }; } /* use only *after* variable declarations */
70
73
 
74
+ /* check and forward error code */
75
+ #define CHECK_F(f) { size_t const e = f; if (FSE_isError(e)) return e; }
76
+
71
77
 
72
78
  /* **************************************************************
73
79
  * Complex types
@@ -152,7 +158,6 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
152
158
  position = (position + step) & tableMask;
153
159
  while (position > highThreshold) position = (position + step) & tableMask; /* lowprob area */
154
160
  } }
155
-
156
161
  if (position!=0) return ERROR(GENERIC); /* position must reach all cells once, otherwise normalizedCounter is incorrect */
157
162
  }
158
163
 
@@ -169,7 +174,6 @@ size_t FSE_buildDTable(FSE_DTable* dt, const short* normalizedCounter, unsigned
169
174
  }
170
175
 
171
176
 
172
-
173
177
  #ifndef FSE_COMMONDEFS_ONLY
174
178
 
175
179
  /*-*******************************************************
@@ -234,8 +238,7 @@ FORCE_INLINE size_t FSE_decompress_usingDTable_generic(
234
238
  FSE_DState_t state2;
235
239
 
236
240
  /* Init */
237
- { size_t const errorCode = BIT_initDStream(&bitD, cSrc, cSrcSize); /* replaced last arg by maxCompressed Size */
238
- if (FSE_isError(errorCode)) return errorCode; }
241
+ CHECK_F(BIT_initDStream(&bitD, cSrc, cSrcSize));
239
242
 
240
243
  FSE_initDState(&state1, &bitD, dt);
241
244
  FSE_initDState(&state2, &bitD, dt);
@@ -243,7 +246,7 @@ FORCE_INLINE size_t FSE_decompress_usingDTable_generic(
243
246
  #define FSE_GETSYMBOL(statePtr) fast ? FSE_decodeSymbolFast(statePtr, &bitD) : FSE_decodeSymbol(statePtr, &bitD)
244
247
 
245
248
  /* 4 symbols per loop */
246
- for ( ; (BIT_reloadDStream(&bitD)==BIT_DStream_unfinished) && (op<olimit) ; op+=4) {
249
+ for ( ; (BIT_reloadDStream(&bitD)==BIT_DStream_unfinished) & (op<olimit) ; op+=4) {
247
250
  op[0] = FSE_GETSYMBOL(&state1);
248
251
 
249
252
  if (FSE_MAX_TABLELOG*2+7 > sizeof(bitD.bitContainer)*8) /* This test must be static */
@@ -266,18 +269,14 @@ FORCE_INLINE size_t FSE_decompress_usingDTable_generic(
266
269
  /* note : BIT_reloadDStream(&bitD) >= FSE_DStream_partiallyFilled; Ends at exactly BIT_DStream_completed */
267
270
  while (1) {
268
271
  if (op>(omax-2)) return ERROR(dstSize_tooSmall);
269
-
270
272
  *op++ = FSE_GETSYMBOL(&state1);
271
-
272
273
  if (BIT_reloadDStream(&bitD)==BIT_DStream_overflow) {
273
274
  *op++ = FSE_GETSYMBOL(&state2);
274
275
  break;
275
276
  }
276
277
 
277
278
  if (op>(omax-2)) return ERROR(dstSize_tooSmall);
278
-
279
279
  *op++ = FSE_GETSYMBOL(&state2);
280
-
281
280
  if (BIT_reloadDStream(&bitD)==BIT_DStream_overflow) {
282
281
  *op++ = FSE_GETSYMBOL(&state1);
283
282
  break;
@@ -320,8 +319,7 @@ size_t FSE_decompress(void* dst, size_t maxDstSize, const void* cSrc, size_t cSr
320
319
  cSrcSize -= NCountLength;
321
320
  }
322
321
 
323
- { size_t const errorCode = FSE_buildDTable (dt, counting, maxSymbolValue, tableLog);
324
- if (FSE_isError(errorCode)) return errorCode; }
322
+ CHECK_F( FSE_buildDTable (dt, counting, maxSymbolValue, tableLog) );
325
323
 
326
324
  return FSE_decompress_usingDTable (dst, maxDstSize, ip, cSrcSize, dt); /* always return, even if it is an error code */
327
325
  }
@@ -100,7 +100,7 @@ size_t HUF_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize
100
100
  /* *** Constants *** */
101
101
  #define HUF_TABLELOG_ABSOLUTEMAX 16 /* absolute limit of HUF_MAX_TABLELOG. Beyond that value, code does not work */
102
102
  #define HUF_TABLELOG_MAX 12 /* max configured tableLog (for static allocation); can be modified up to HUF_ABSOLUTEMAX_TABLELOG */
103
- #define HUF_TABLELOG_DEFAULT HUF_TABLELOG_MAX /* tableLog by default, when not specified */
103
+ #define HUF_TABLELOG_DEFAULT 11 /* tableLog by default, when not specified */
104
104
  #define HUF_SYMBOLVALUE_MAX 255
105
105
  #if (HUF_TABLELOG_MAX > HUF_TABLELOG_ABSOLUTEMAX)
106
106
  # error "HUF_TABLELOG_MAX is too large !"
@@ -1,37 +1,12 @@
1
- /* ******************************************************************
2
- mem.h
3
- low-level memory access routines
4
- Copyright (C) 2013-2015, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
-
12
- * Redistributions of source code must retain the above copyright
13
- notice, this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the following disclaimer
16
- in the documentation and/or other materials provided with the
17
- distribution.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- You can contact the author at :
32
- - FSE source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
34
- ****************************************************************** */
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
35
10
  #ifndef MEM_H_MODULE
36
11
  #define MEM_H_MODULE
37
12
 
@@ -44,19 +19,17 @@ extern "C" {
44
19
  ******************************************/
45
20
  #include <stddef.h> /* size_t, ptrdiff_t */
46
21
  #include <string.h> /* memcpy */
47
- #if defined(_MSC_VER) /* Visual Studio */
48
- # include <stdlib.h> /* _byteswap_ulong */
49
- #endif
50
22
 
51
23
 
52
24
  /*-****************************************
53
25
  * Compiler specifics
54
26
  ******************************************/
55
- #if defined(_MSC_VER)
56
- # include <intrin.h> /* _byteswap_ */
27
+ #if defined(_MSC_VER) /* Visual Studio */
28
+ # include <stdlib.h> /* _byteswap_ulong */
29
+ # include <intrin.h> /* _byteswap_* */
57
30
  #endif
58
31
  #if defined(__GNUC__)
59
- # define MEM_STATIC static __attribute__((unused))
32
+ # define MEM_STATIC static __inline __attribute__((unused))
60
33
  #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
61
34
  # define MEM_STATIC static inline
62
35
  #elif defined(_MSC_VER)
@@ -65,6 +38,10 @@ extern "C" {
65
38
  # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
66
39
  #endif
67
40
 
41
+ /* code only tested on 32 and 64 bits systems */
42
+ #define MEM_STATIC_ASSERT(c) { enum { XXH_static_assert = 1/(int)(!!(c)) }; }
43
+ MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); }
44
+
68
45
 
69
46
  /*-**************************************************************
70
47
  * Basic Types
@@ -108,7 +85,7 @@ extern "C" {
108
85
  #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
109
86
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
110
87
  # define MEM_FORCE_MEMORY_ACCESS 2
111
- # elif defined(__INTEL_COMPILER) || \
88
+ # elif defined(__INTEL_COMPILER) /*|| defined(_MSC_VER)*/ || \
112
89
  (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
113
90
  # define MEM_FORCE_MEMORY_ACCESS 1
114
91
  # endif
@@ -140,7 +117,13 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; }
140
117
 
141
118
  /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */
142
119
  /* currently only defined for gcc and icc */
143
- typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
120
+ #if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32))
121
+ __pragma( pack(push, 1) )
122
+ typedef union { U16 u16; U32 u32; U64 u64; size_t st; } unalign;
123
+ __pragma( pack(pop) )
124
+ #else
125
+ typedef union { U16 u16; U32 u32; U64 u64; size_t st; } __attribute__((packed)) unalign;
126
+ #endif
144
127
 
145
128
  MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign*)ptr)->u16; }
146
129
  MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign*)ptr)->u32; }
@@ -256,6 +239,17 @@ MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val)
256
239
  }
257
240
  }
258
241
 
242
+ MEM_STATIC U32 MEM_readLE24(const void* memPtr)
243
+ {
244
+ return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16);
245
+ }
246
+
247
+ MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val)
248
+ {
249
+ MEM_writeLE16(memPtr, (U16)val);
250
+ ((BYTE*)memPtr)[2] = (BYTE)(val>>16);
251
+ }
252
+
259
253
  MEM_STATIC U32 MEM_readLE32(const void* memPtr)
260
254
  {
261
255
  if (MEM_isLittleEndian())
@@ -374,4 +368,3 @@ MEM_STATIC U32 MEM_readMINMATCH(const void* memPtr, U32 length)
374
368
  #endif
375
369
 
376
370
  #endif /* MEM_H_MODULE */
377
-
@@ -52,7 +52,7 @@
52
52
  #ifndef XXH_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
53
53
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
54
54
  # define XXH_FORCE_MEMORY_ACCESS 2
55
- # elif defined(__INTEL_COMPILER) || \
55
+ # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
56
56
  (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
57
57
  # define XXH_FORCE_MEMORY_ACCESS 1
58
58
  # endif
@@ -115,7 +115,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
115
115
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
116
116
  # define FORCE_INLINE static __forceinline
117
117
  #else
118
- # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
118
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
119
119
  # ifdef __GNUC__
120
120
  # define FORCE_INLINE static inline __attribute__((always_inline))
121
121
  # else
@@ -132,7 +132,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
132
132
  ***************************************/
133
133
  #ifndef MEM_MODULE
134
134
  # define MEM_MODULE
135
- # if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
135
+ # if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) )
136
136
  # include <stdint.h>
137
137
  typedef uint8_t BYTE;
138
138
  typedef uint16_t U16;
@@ -144,7 +144,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
144
144
  typedef unsigned short U16;
145
145
  typedef unsigned int U32;
146
146
  typedef signed int S32;
147
- typedef unsigned long long U64;
147
+ typedef unsigned long long U64; /* if your compiler doesn't support unsigned long long, replace by another 64-bit type here. Note that xxhash.h will also need to be updated. */
148
148
  # endif
149
149
  #endif
150
150
 
@@ -307,6 +307,20 @@ static const U64 PRIME64_5 = 2870177450012600261ULL;
307
307
  XXH_PUBLIC_API unsigned XXH_versionNumber (void) { return XXH_VERSION_NUMBER; }
308
308
 
309
309
 
310
+ /* **************************
311
+ * Utils
312
+ ****************************/
313
+ XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dstState, const XXH32_state_t* restrict srcState)
314
+ {
315
+ memcpy(dstState, srcState, sizeof(*dstState));
316
+ }
317
+
318
+ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dstState, const XXH64_state_t* restrict srcState)
319
+ {
320
+ memcpy(dstState, srcState, sizeof(*dstState));
321
+ }
322
+
323
+
310
324
  /* ***************************
311
325
  * Simple Hash Functions
312
326
  *****************************/
@@ -545,8 +559,7 @@ XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr)
545
559
  XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int seed)
546
560
  {
547
561
  XXH32_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
548
- memset(&state, 0, sizeof(state));
549
- state.seed = seed;
562
+ memset(&state, 0, sizeof(state)-4); /* do not write into reserved, for future removal */
550
563
  state.v1 = seed + PRIME32_1 + PRIME32_2;
551
564
  state.v2 = seed + PRIME32_2;
552
565
  state.v3 = seed + 0;
@@ -559,8 +572,7 @@ XXH_PUBLIC_API XXH_errorcode XXH32_reset(XXH32_state_t* statePtr, unsigned int s
559
572
  XXH_PUBLIC_API XXH_errorcode XXH64_reset(XXH64_state_t* statePtr, unsigned long long seed)
560
573
  {
561
574
  XXH64_state_t state; /* using a local state to memcpy() in order to avoid strict-aliasing warnings */
562
- memset(&state, 0, sizeof(state));
563
- state.seed = seed;
575
+ memset(&state, 0, sizeof(state)-8); /* do not write into reserved, for future removal */
564
576
  state.v1 = seed + PRIME64_1 + PRIME64_2;
565
577
  state.v2 = seed + PRIME64_2;
566
578
  state.v3 = seed + 0;
@@ -579,11 +591,12 @@ FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void
579
591
  if (input==NULL) return XXH_ERROR;
580
592
  #endif
581
593
 
582
- state->total_len += len;
594
+ state->total_len_32 += (unsigned)len;
595
+ state->large_len |= (len>=16) | (state->total_len_32>=16);
583
596
 
584
597
  if (state->memsize + len < 16) { /* fill in tmp buffer */
585
598
  XXH_memcpy((BYTE*)(state->mem32) + state->memsize, input, len);
586
- state->memsize += (U32)len;
599
+ state->memsize += (unsigned)len;
587
600
  return XXH_OK;
588
601
  }
589
602
 
@@ -620,8 +633,8 @@ FORCE_INLINE XXH_errorcode XXH32_update_endian (XXH32_state_t* state, const void
620
633
  }
621
634
 
622
635
  if (p < bEnd) {
623
- XXH_memcpy(state->mem32, p, bEnd-p);
624
- state->memsize = (int)(bEnd-p);
636
+ XXH_memcpy(state->mem32, p, (size_t)(bEnd-p));
637
+ state->memsize = (unsigned)(bEnd-p);
625
638
  }
626
639
 
627
640
  return XXH_OK;
@@ -645,13 +658,13 @@ FORCE_INLINE U32 XXH32_digest_endian (const XXH32_state_t* state, XXH_endianess
645
658
  const BYTE* const bEnd = (const BYTE*)(state->mem32) + state->memsize;
646
659
  U32 h32;
647
660
 
648
- if (state->total_len >= 16) {
661
+ if (state->large_len) {
649
662
  h32 = XXH_rotl32(state->v1, 1) + XXH_rotl32(state->v2, 7) + XXH_rotl32(state->v3, 12) + XXH_rotl32(state->v4, 18);
650
663
  } else {
651
- h32 = state->seed + PRIME32_5;
664
+ h32 = state->v3 /* == seed */ + PRIME32_5;
652
665
  }
653
666
 
654
- h32 += (U32) state->total_len;
667
+ h32 += state->total_len_32;
655
668
 
656
669
  while (p+4<=bEnd) {
657
670
  h32 += XXH_readLE32(p, endian) * PRIME32_3;
@@ -737,8 +750,8 @@ FORCE_INLINE XXH_errorcode XXH64_update_endian (XXH64_state_t* state, const void
737
750
  }
738
751
 
739
752
  if (p < bEnd) {
740
- XXH_memcpy(state->mem64, p, bEnd-p);
741
- state->memsize = (int)(bEnd-p);
753
+ XXH_memcpy(state->mem64, p, (size_t)(bEnd-p));
754
+ state->memsize = (unsigned)(bEnd-p);
742
755
  }
743
756
 
744
757
  return XXH_OK;
@@ -774,7 +787,7 @@ FORCE_INLINE U64 XXH64_digest_endian (const XXH64_state_t* state, XXH_endianess
774
787
  h64 = XXH64_mergeRound(h64, v3);
775
788
  h64 = XXH64_mergeRound(h64, v4);
776
789
  } else {
777
- h64 = state->seed + PRIME64_5;
790
+ h64 = state->v3 + PRIME64_5;
778
791
  }
779
792
 
780
793
  h64 += (U64) state->total_len;
@@ -71,6 +71,10 @@ XXH32 6.8 GB/s 6.0 GB/s
71
71
  extern "C" {
72
72
  #endif
73
73
 
74
+ #ifndef XXH_NAMESPACE
75
+ # define XXH_NAMESPACE ZSTD_ /* Zstandard specific */
76
+ #endif
77
+
74
78
 
75
79
  /* ****************************
76
80
  * Definitions
@@ -82,18 +86,21 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
82
86
  /* ****************************
83
87
  * API modifier
84
88
  ******************************/
85
- /*!XXH_PRIVATE_API
86
- * Transforms all publics symbols within `xxhash.c` into private ones.
87
- * Methodology :
88
- * instead of : #include "xxhash.h"
89
- * do :
89
+ /** XXH_PRIVATE_API
90
+ * This is useful if you want to include xxhash functions in `static` mode
91
+ * in order to inline them, and remove their symbol from the public list.
92
+ * Methodology :
90
93
  * #define XXH_PRIVATE_API
91
- * #include "xxhash.c" // note the .c , instead of .h
92
- * also : don't compile and link xxhash.c separately
94
+ * #include "xxhash.h"
95
+ * `xxhash.c` is automatically included.
96
+ * It's not useful to compile and link it as a separate module anymore.
93
97
  */
94
98
  #ifdef XXH_PRIVATE_API
99
+ # ifndef XXH_STATIC_LINKING_ONLY
100
+ # define XXH_STATIC_LINKING_ONLY
101
+ # endif
95
102
  # if defined(__GNUC__)
96
- # define XXH_PUBLIC_API static __attribute__((unused))
103
+ # define XXH_PUBLIC_API static __inline __attribute__((unused))
97
104
  # elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
98
105
  # define XXH_PUBLIC_API static inline
99
106
  # elif defined(_MSC_VER)
@@ -103,17 +110,17 @@ typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
103
110
  # endif
104
111
  #else
105
112
  # define XXH_PUBLIC_API /* do nothing */
106
- #endif
113
+ #endif /* XXH_PRIVATE_API */
107
114
 
108
115
  /*!XXH_NAMESPACE, aka Namespace Emulation :
109
116
 
110
117
  If you want to include _and expose_ xxHash functions from within your own library,
111
118
  but also want to avoid symbol collisions with another library which also includes xxHash,
112
119
 
113
- you can use XXH_NAMESPACE, to automatically prefix any public symbol from `xxhash.c`
120
+ you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library
114
121
  with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values).
115
122
 
116
- Note that no change is required within the calling program as long as it also includes `xxhash.h` :
123
+ Note that no change is required within the calling program as long as it includes `xxhash.h` :
117
124
  regular symbol name will be automatically translated by this header.
118
125
  */
119
126
  #ifdef XXH_NAMESPACE
@@ -132,6 +139,12 @@ regular symbol name will be automatically translated by this header.
132
139
  # define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
133
140
  # define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
134
141
  # define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest)
142
+ # define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState)
143
+ # define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState)
144
+ # define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash)
145
+ # define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash)
146
+ # define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical)
147
+ # define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical)
135
148
  #endif
136
149
 
137
150
 
@@ -140,7 +153,7 @@ regular symbol name will be automatically translated by this header.
140
153
  ***************************************/
141
154
  #define XXH_VERSION_MAJOR 0
142
155
  #define XXH_VERSION_MINOR 6
143
- #define XXH_VERSION_RELEASE 0
156
+ #define XXH_VERSION_RELEASE 2
144
157
  #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
145
158
  XXH_PUBLIC_API unsigned XXH_versionNumber (void);
146
159
 
@@ -163,7 +176,7 @@ XXH32() :
163
176
  XXH64() :
164
177
  Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
165
178
  "seed" can be used to alter the result predictably.
166
- This function runs faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
179
+ This function runs 2x faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
167
180
  */
168
181
 
169
182
 
@@ -173,8 +186,7 @@ XXH64() :
173
186
  typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
174
187
  typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
175
188
 
176
- /*! Dynamic allocation of states
177
- Compatible with dynamic libraries */
189
+ /*! State allocation, compatible with dynamic libraries */
178
190
 
179
191
  XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
180
192
  XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
@@ -193,28 +205,40 @@ XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned lon
193
205
  XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
194
206
  XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
195
207
 
196
- /*!
197
- These functions generate the xxHash of an input provided in multiple segments,
198
- as opposed to provided as a single block.
208
+ /*
209
+ These functions generate the xxHash of an input provided in multiple segments.
210
+ Note that, for small input, they are slower than single-call functions, due to state management.
211
+ For small input, prefer `XXH32()` and `XXH64()` .
199
212
 
200
- XXH state must first be allocated, using either static or dynamic method provided above.
213
+ XXH state must first be allocated, using XXH*_createState() .
201
214
 
202
- Start a new hash by initializing state with a seed, using XXHnn_reset().
215
+ Start a new hash by initializing state with a seed, using XXH*_reset().
203
216
 
204
- Then, feed the hash state by calling XXHnn_update() as many times as necessary.
205
- Obviously, input must be valid, hence allocated and read accessible.
217
+ Then, feed the hash state by calling XXH*_update() as many times as necessary.
218
+ Obviously, input must be allocated and read accessible.
206
219
  The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
207
220
 
208
- Finally, a hash value can be produced anytime, by using XXHnn_digest().
221
+ Finally, a hash value can be produced anytime, by using XXH*_digest().
209
222
  This function returns the nn-bits hash as an int or long long.
210
223
 
211
224
  It's still possible to continue inserting input into the hash state after a digest,
212
- and later on generate some new hashes, by calling again XXHnn_digest().
225
+ and generate some new hashes later on, by calling again XXH*_digest().
213
226
 
214
227
  When done, free XXH state space if it was allocated dynamically.
215
228
  */
216
229
 
217
230
 
231
+ /* **************************
232
+ * Utils
233
+ ****************************/
234
+ #if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* ! C99 */
235
+ # define restrict /* disable restrict */
236
+ #endif
237
+
238
+ XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state);
239
+ XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state);
240
+
241
+
218
242
  /* **************************
219
243
  * Canonical representation
220
244
  ****************************/
@@ -227,43 +251,55 @@ XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t
227
251
  XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
228
252
  XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
229
253
 
230
- /*! Default result type for XXH functions are primitive unsigned 32 and 64 bits.
231
- * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
232
- * These functions allow transformation of hash result into and from its canonical format.
233
- * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
254
+ /* Default result type for XXH functions are primitive unsigned 32 and 64 bits.
255
+ * The canonical representation uses human-readable write convention, aka big-endian (large digits first).
256
+ * These functions allow transformation of hash result into and from its canonical format.
257
+ * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs.
234
258
  */
235
259
 
236
260
 
237
261
  #ifdef XXH_STATIC_LINKING_ONLY
238
262
 
239
- /* This part contains definition which shall only be used with static linking.
240
- The prototypes / types defined here are not guaranteed to remain stable.
241
- They could change in a future version, becoming incompatible with a different version of the library */
263
+ /* ================================================================================================
264
+ This section contains definitions which are not guaranteed to remain stable.
265
+ They may change in future versions, becoming incompatible with a different version of the library.
266
+ They shall only be used with static linking.
267
+ Never use these definitions in association with dynamic linking !
268
+ =================================================================================================== */
269
+
270
+ /* These definitions are only meant to allow allocation of XXH state
271
+ statically, on stack, or in a struct for example.
272
+ Do not use members directly. */
242
273
 
243
274
  struct XXH32_state_s {
244
- unsigned long long total_len;
245
- unsigned seed;
275
+ unsigned total_len_32;
276
+ unsigned large_len;
246
277
  unsigned v1;
247
278
  unsigned v2;
248
279
  unsigned v3;
249
280
  unsigned v4;
250
281
  unsigned mem32[4]; /* buffer defined as U32 for alignment */
251
282
  unsigned memsize;
283
+ unsigned reserved; /* never read nor write, will be removed in a future version */
252
284
  }; /* typedef'd to XXH32_state_t */
253
285
 
254
286
  struct XXH64_state_s {
255
287
  unsigned long long total_len;
256
- unsigned long long seed;
257
288
  unsigned long long v1;
258
289
  unsigned long long v2;
259
290
  unsigned long long v3;
260
291
  unsigned long long v4;
261
292
  unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
262
293
  unsigned memsize;
294
+ unsigned reserved[2]; /* never read nor write, will be removed in a future version */
263
295
  }; /* typedef'd to XXH64_state_t */
264
296
 
265
297
 
266
- #endif
298
+ # ifdef XXH_PRIVATE_API
299
+ # include "xxhash.c" /* include xxhash functions as `static`, for inlining */
300
+ # endif
301
+
302
+ #endif /* XXH_STATIC_LINKING_ONLY */
267
303
 
268
304
 
269
305
  #if defined (__cplusplus)