zstdlib 0.1.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGES.md +9 -0
  3. data/Gemfile +3 -0
  4. data/README.md +96 -0
  5. data/Rakefile +29 -0
  6. data/ext/zstdlib/extconf.rb +53 -0
  7. data/ext/zstdlib/ruby/zlib-2.2/zlib.c +4659 -0
  8. data/ext/zstdlib/ruby/zlib-2.3/zlib.c +4686 -0
  9. data/ext/zstdlib/ruby/zlib-2.4/zlib.c +4843 -0
  10. data/ext/zstdlib/ruby/zlib-2.5/zlib.c +4848 -0
  11. data/ext/zstdlib/ruby/zlib-2.6/zlib.c +4890 -0
  12. data/ext/zstdlib/zlib-1.2.11/adler32.c +186 -0
  13. data/ext/zstdlib/zlib-1.2.11/compress.c +86 -0
  14. data/ext/zstdlib/zlib-1.2.11/crc32.c +442 -0
  15. data/ext/zstdlib/zlib-1.2.11/crc32.h +441 -0
  16. data/ext/zstdlib/zlib-1.2.11/deflate.c +2163 -0
  17. data/ext/zstdlib/zlib-1.2.11/deflate.h +349 -0
  18. data/ext/zstdlib/zlib-1.2.11/gzclose.c +25 -0
  19. data/ext/zstdlib/zlib-1.2.11/gzguts.h +218 -0
  20. data/ext/zstdlib/zlib-1.2.11/gzlib.c +637 -0
  21. data/ext/zstdlib/zlib-1.2.11/gzread.c +654 -0
  22. data/ext/zstdlib/zlib-1.2.11/gzwrite.c +665 -0
  23. data/ext/zstdlib/zlib-1.2.11/infback.c +640 -0
  24. data/ext/zstdlib/zlib-1.2.11/inffast.c +323 -0
  25. data/ext/zstdlib/zlib-1.2.11/inffast.h +11 -0
  26. data/ext/zstdlib/zlib-1.2.11/inffixed.h +94 -0
  27. data/ext/zstdlib/zlib-1.2.11/inflate.c +1561 -0
  28. data/ext/zstdlib/zlib-1.2.11/inflate.h +125 -0
  29. data/ext/zstdlib/zlib-1.2.11/inftrees.c +304 -0
  30. data/ext/zstdlib/zlib-1.2.11/inftrees.h +62 -0
  31. data/ext/zstdlib/zlib-1.2.11/trees.c +1203 -0
  32. data/ext/zstdlib/zlib-1.2.11/trees.h +128 -0
  33. data/ext/zstdlib/zlib-1.2.11/uncompr.c +93 -0
  34. data/ext/zstdlib/zlib-1.2.11/zconf.h +534 -0
  35. data/ext/zstdlib/zlib-1.2.11/zlib.h +1912 -0
  36. data/ext/zstdlib/zlib-1.2.11/zutil.c +325 -0
  37. data/ext/zstdlib/zlib-1.2.11/zutil.h +271 -0
  38. data/ext/zstdlib/zlib.mk +14 -0
  39. data/ext/zstdlib/zlibwrapper.mk +14 -0
  40. data/ext/zstdlib/zlibwrapper/zlibwrapper.c +14 -0
  41. data/ext/zstdlib/zstd-1.3.8/lib/common/bitstream.h +455 -0
  42. data/ext/zstdlib/zstd-1.3.8/lib/common/compiler.h +140 -0
  43. data/ext/zstdlib/zstd-1.3.8/lib/common/cpu.h +215 -0
  44. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.c +44 -0
  45. data/ext/zstdlib/zstd-1.3.8/lib/common/debug.h +134 -0
  46. data/ext/zstdlib/zstd-1.3.8/lib/common/entropy_common.c +236 -0
  47. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.c +54 -0
  48. data/ext/zstdlib/zstd-1.3.8/lib/common/error_private.h +76 -0
  49. data/ext/zstdlib/zstd-1.3.8/lib/common/fse.h +708 -0
  50. data/ext/zstdlib/zstd-1.3.8/lib/common/fse_decompress.c +309 -0
  51. data/ext/zstdlib/zstd-1.3.8/lib/common/huf.h +358 -0
  52. data/ext/zstdlib/zstd-1.3.8/lib/common/mem.h +380 -0
  53. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.c +340 -0
  54. data/ext/zstdlib/zstd-1.3.8/lib/common/pool.h +84 -0
  55. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.c +75 -0
  56. data/ext/zstdlib/zstd-1.3.8/lib/common/threading.h +123 -0
  57. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.c +876 -0
  58. data/ext/zstdlib/zstd-1.3.8/lib/common/xxhash.h +305 -0
  59. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_common.c +83 -0
  60. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_errors.h +93 -0
  61. data/ext/zstdlib/zstd-1.3.8/lib/common/zstd_internal.h +266 -0
  62. data/ext/zstdlib/zstd-1.3.8/lib/compress/fse_compress.c +721 -0
  63. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.c +203 -0
  64. data/ext/zstdlib/zstd-1.3.8/lib/compress/hist.h +95 -0
  65. data/ext/zstdlib/zstd-1.3.8/lib/compress/huf_compress.c +798 -0
  66. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress.c +4290 -0
  67. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_compress_internal.h +860 -0
  68. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.c +499 -0
  69. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_double_fast.h +38 -0
  70. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.c +391 -0
  71. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_fast.h +37 -0
  72. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.c +1106 -0
  73. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_lazy.h +67 -0
  74. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.c +597 -0
  75. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_ldm.h +105 -0
  76. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.c +1217 -0
  77. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstd_opt.h +56 -0
  78. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.c +2107 -0
  79. data/ext/zstdlib/zstd-1.3.8/lib/compress/zstdmt_compress.h +174 -0
  80. data/ext/zstdlib/zstd-1.3.8/lib/decompress/huf_decompress.c +1232 -0
  81. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.c +240 -0
  82. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_ddict.h +44 -0
  83. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress.c +1672 -0
  84. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.c +1307 -0
  85. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_block.h +59 -0
  86. data/ext/zstdlib/zstd-1.3.8/lib/decompress/zstd_decompress_internal.h +168 -0
  87. data/ext/zstdlib/zstd-1.3.8/lib/zstd.h +1766 -0
  88. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzclose.c +28 -0
  89. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzcompatibility.h +68 -0
  90. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzguts.h +227 -0
  91. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzlib.c +640 -0
  92. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzread.c +670 -0
  93. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/gzwrite.c +671 -0
  94. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.c +1105 -0
  95. data/ext/zstdlib/zstd-1.3.8/zlibWrapper/zstd_zlibwrapper.h +88 -0
  96. data/ext/zstdlib/zstd.mk +14 -0
  97. data/lib/2.2/zstdlib.so +0 -0
  98. data/lib/2.3/zstdlib.so +0 -0
  99. data/lib/2.4/zstdlib.so +0 -0
  100. data/lib/2.5/zstdlib.so +0 -0
  101. data/lib/2.6/zstdlib.so +0 -0
  102. data/lib/zstdlib.rb +6 -0
  103. data/test/zstdlib_test.rb +21 -0
  104. metadata +205 -0
@@ -0,0 +1,38 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #ifndef ZSTD_DOUBLE_FAST_H
12
+ #define ZSTD_DOUBLE_FAST_H
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ #include "mem.h" /* U32 */
19
+ #include "zstd_compress_internal.h" /* ZSTD_CCtx, size_t */
20
+
21
+ void ZSTD_fillDoubleHashTable(ZSTD_matchState_t* ms,
22
+ void const* end, ZSTD_dictTableLoadMethod_e dtlm);
23
+ size_t ZSTD_compressBlock_doubleFast(
24
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25
+ void const* src, size_t srcSize);
26
+ size_t ZSTD_compressBlock_doubleFast_dictMatchState(
27
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28
+ void const* src, size_t srcSize);
29
+ size_t ZSTD_compressBlock_doubleFast_extDict(
30
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31
+ void const* src, size_t srcSize);
32
+
33
+
34
+ #if defined (__cplusplus)
35
+ }
36
+ #endif
37
+
38
+ #endif /* ZSTD_DOUBLE_FAST_H */
@@ -0,0 +1,391 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #include "zstd_compress_internal.h"
12
+ #include "zstd_fast.h"
13
+
14
+
15
+ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
16
+ void const* end, ZSTD_dictTableLoadMethod_e dtlm)
17
+ {
18
+ const ZSTD_compressionParameters* const cParams = &ms->cParams;
19
+ U32* const hashTable = ms->hashTable;
20
+ U32 const hBits = cParams->hashLog;
21
+ U32 const mls = cParams->minMatch;
22
+ const BYTE* const base = ms->window.base;
23
+ const BYTE* ip = base + ms->nextToUpdate;
24
+ const BYTE* const iend = ((const BYTE*)end) - HASH_READ_SIZE;
25
+ const U32 fastHashFillStep = 3;
26
+
27
+ /* Always insert every fastHashFillStep position into the hash table.
28
+ * Insert the other positions if their hash entry is empty.
29
+ */
30
+ for ( ; ip + fastHashFillStep < iend + 2; ip += fastHashFillStep) {
31
+ U32 const current = (U32)(ip - base);
32
+ size_t const hash0 = ZSTD_hashPtr(ip, hBits, mls);
33
+ hashTable[hash0] = current;
34
+ if (dtlm == ZSTD_dtlm_fast) continue;
35
+ /* Only load extra positions for ZSTD_dtlm_full */
36
+ { U32 p;
37
+ for (p = 1; p < fastHashFillStep; ++p) {
38
+ size_t const hash = ZSTD_hashPtr(ip + p, hBits, mls);
39
+ if (hashTable[hash] == 0) { /* not yet filled */
40
+ hashTable[hash] = current + p;
41
+ } } } }
42
+ }
43
+
44
+ FORCE_INLINE_TEMPLATE
45
+ size_t ZSTD_compressBlock_fast_generic(
46
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
47
+ void const* src, size_t srcSize,
48
+ U32 const mls, ZSTD_dictMode_e const dictMode)
49
+ {
50
+ const ZSTD_compressionParameters* const cParams = &ms->cParams;
51
+ U32* const hashTable = ms->hashTable;
52
+ U32 const hlog = cParams->hashLog;
53
+ /* support stepSize of 0 */
54
+ U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
55
+ const BYTE* const base = ms->window.base;
56
+ const BYTE* const istart = (const BYTE*)src;
57
+ const BYTE* ip = istart;
58
+ const BYTE* anchor = istart;
59
+ const U32 prefixStartIndex = ms->window.dictLimit;
60
+ const BYTE* const prefixStart = base + prefixStartIndex;
61
+ const BYTE* const iend = istart + srcSize;
62
+ const BYTE* const ilimit = iend - HASH_READ_SIZE;
63
+ U32 offset_1=rep[0], offset_2=rep[1];
64
+ U32 offsetSaved = 0;
65
+
66
+ const ZSTD_matchState_t* const dms = ms->dictMatchState;
67
+ const ZSTD_compressionParameters* const dictCParams =
68
+ dictMode == ZSTD_dictMatchState ?
69
+ &dms->cParams : NULL;
70
+ const U32* const dictHashTable = dictMode == ZSTD_dictMatchState ?
71
+ dms->hashTable : NULL;
72
+ const U32 dictStartIndex = dictMode == ZSTD_dictMatchState ?
73
+ dms->window.dictLimit : 0;
74
+ const BYTE* const dictBase = dictMode == ZSTD_dictMatchState ?
75
+ dms->window.base : NULL;
76
+ const BYTE* const dictStart = dictMode == ZSTD_dictMatchState ?
77
+ dictBase + dictStartIndex : NULL;
78
+ const BYTE* const dictEnd = dictMode == ZSTD_dictMatchState ?
79
+ dms->window.nextSrc : NULL;
80
+ const U32 dictIndexDelta = dictMode == ZSTD_dictMatchState ?
81
+ prefixStartIndex - (U32)(dictEnd - dictBase) :
82
+ 0;
83
+ const U32 dictAndPrefixLength = (U32)(ip - prefixStart + dictEnd - dictStart);
84
+ const U32 dictHLog = dictMode == ZSTD_dictMatchState ?
85
+ dictCParams->hashLog : hlog;
86
+
87
+ assert(dictMode == ZSTD_noDict || dictMode == ZSTD_dictMatchState);
88
+
89
+ /* otherwise, we would get index underflow when translating a dict index
90
+ * into a local index */
91
+ assert(dictMode != ZSTD_dictMatchState
92
+ || prefixStartIndex >= (U32)(dictEnd - dictBase));
93
+
94
+ /* init */
95
+ ip += (dictAndPrefixLength == 0);
96
+ if (dictMode == ZSTD_noDict) {
97
+ U32 const maxRep = (U32)(ip - prefixStart);
98
+ if (offset_2 > maxRep) offsetSaved = offset_2, offset_2 = 0;
99
+ if (offset_1 > maxRep) offsetSaved = offset_1, offset_1 = 0;
100
+ }
101
+ if (dictMode == ZSTD_dictMatchState) {
102
+ /* dictMatchState repCode checks don't currently handle repCode == 0
103
+ * disabling. */
104
+ assert(offset_1 <= dictAndPrefixLength);
105
+ assert(offset_2 <= dictAndPrefixLength);
106
+ }
107
+
108
+ /* Main Search Loop */
109
+ while (ip < ilimit) { /* < instead of <=, because repcode check at (ip+1) */
110
+ size_t mLength;
111
+ size_t const h = ZSTD_hashPtr(ip, hlog, mls);
112
+ U32 const current = (U32)(ip-base);
113
+ U32 const matchIndex = hashTable[h];
114
+ const BYTE* match = base + matchIndex;
115
+ const U32 repIndex = current + 1 - offset_1;
116
+ const BYTE* repMatch = (dictMode == ZSTD_dictMatchState
117
+ && repIndex < prefixStartIndex) ?
118
+ dictBase + (repIndex - dictIndexDelta) :
119
+ base + repIndex;
120
+ hashTable[h] = current; /* update hash table */
121
+
122
+ if ( (dictMode == ZSTD_dictMatchState)
123
+ && ((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow : ensure repIndex isn't overlapping dict + prefix */
124
+ && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
125
+ const BYTE* const repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
126
+ mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
127
+ ip++;
128
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
129
+ } else if ( dictMode == ZSTD_noDict
130
+ && ((offset_1 > 0) & (MEM_read32(ip+1-offset_1) == MEM_read32(ip+1)))) {
131
+ mLength = ZSTD_count(ip+1+4, ip+1+4-offset_1, iend) + 4;
132
+ ip++;
133
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
134
+ } else if ( (matchIndex <= prefixStartIndex) ) {
135
+ if (dictMode == ZSTD_dictMatchState) {
136
+ size_t const dictHash = ZSTD_hashPtr(ip, dictHLog, mls);
137
+ U32 const dictMatchIndex = dictHashTable[dictHash];
138
+ const BYTE* dictMatch = dictBase + dictMatchIndex;
139
+ if (dictMatchIndex <= dictStartIndex ||
140
+ MEM_read32(dictMatch) != MEM_read32(ip)) {
141
+ assert(stepSize >= 1);
142
+ ip += ((ip-anchor) >> kSearchStrength) + stepSize;
143
+ continue;
144
+ } else {
145
+ /* found a dict match */
146
+ U32 const offset = (U32)(current-dictMatchIndex-dictIndexDelta);
147
+ mLength = ZSTD_count_2segments(ip+4, dictMatch+4, iend, dictEnd, prefixStart) + 4;
148
+ while (((ip>anchor) & (dictMatch>dictStart))
149
+ && (ip[-1] == dictMatch[-1])) {
150
+ ip--; dictMatch--; mLength++;
151
+ } /* catch up */
152
+ offset_2 = offset_1;
153
+ offset_1 = offset;
154
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
155
+ }
156
+ } else {
157
+ assert(stepSize >= 1);
158
+ ip += ((ip-anchor) >> kSearchStrength) + stepSize;
159
+ continue;
160
+ }
161
+ } else if (MEM_read32(match) != MEM_read32(ip)) {
162
+ /* it's not a match, and we're not going to check the dictionary */
163
+ assert(stepSize >= 1);
164
+ ip += ((ip-anchor) >> kSearchStrength) + stepSize;
165
+ continue;
166
+ } else {
167
+ /* found a regular match */
168
+ U32 const offset = (U32)(ip-match);
169
+ mLength = ZSTD_count(ip+4, match+4, iend) + 4;
170
+ while (((ip>anchor) & (match>prefixStart))
171
+ && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
172
+ offset_2 = offset_1;
173
+ offset_1 = offset;
174
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
175
+ }
176
+
177
+ /* match found */
178
+ ip += mLength;
179
+ anchor = ip;
180
+
181
+ if (ip <= ilimit) {
182
+ /* Fill Table */
183
+ assert(base+current+2 > istart); /* check base overflow */
184
+ hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2; /* here because current+2 could be > iend-8 */
185
+ hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base);
186
+
187
+ /* check immediate repcode */
188
+ if (dictMode == ZSTD_dictMatchState) {
189
+ while (ip <= ilimit) {
190
+ U32 const current2 = (U32)(ip-base);
191
+ U32 const repIndex2 = current2 - offset_2;
192
+ const BYTE* repMatch2 = repIndex2 < prefixStartIndex ?
193
+ dictBase - dictIndexDelta + repIndex2 :
194
+ base + repIndex2;
195
+ if ( ((U32)((prefixStartIndex-1) - (U32)repIndex2) >= 3 /* intentional overflow */)
196
+ && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
197
+ const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
198
+ size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
199
+ U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
200
+ ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
201
+ hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
202
+ ip += repLength2;
203
+ anchor = ip;
204
+ continue;
205
+ }
206
+ break;
207
+ }
208
+ }
209
+
210
+ if (dictMode == ZSTD_noDict) {
211
+ while ( (ip <= ilimit)
212
+ && ( (offset_2>0)
213
+ & (MEM_read32(ip) == MEM_read32(ip - offset_2)) )) {
214
+ /* store sequence */
215
+ size_t const rLength = ZSTD_count(ip+4, ip+4-offset_2, iend) + 4;
216
+ U32 const tmpOff = offset_2; offset_2 = offset_1; offset_1 = tmpOff; /* swap offset_2 <=> offset_1 */
217
+ hashTable[ZSTD_hashPtr(ip, hlog, mls)] = (U32)(ip-base);
218
+ ZSTD_storeSeq(seqStore, 0, anchor, 0, rLength-MINMATCH);
219
+ ip += rLength;
220
+ anchor = ip;
221
+ continue; /* faster when present ... (?) */
222
+ } } } }
223
+
224
+ /* save reps for next block */
225
+ rep[0] = offset_1 ? offset_1 : offsetSaved;
226
+ rep[1] = offset_2 ? offset_2 : offsetSaved;
227
+
228
+ /* Return the last literals size */
229
+ return iend - anchor;
230
+ }
231
+
232
+
233
+ size_t ZSTD_compressBlock_fast(
234
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
235
+ void const* src, size_t srcSize)
236
+ {
237
+ ZSTD_compressionParameters const* cParams = &ms->cParams;
238
+ U32 const mls = cParams->minMatch;
239
+ assert(ms->dictMatchState == NULL);
240
+ switch(mls)
241
+ {
242
+ default: /* includes case 3 */
243
+ case 4 :
244
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_noDict);
245
+ case 5 :
246
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_noDict);
247
+ case 6 :
248
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_noDict);
249
+ case 7 :
250
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_noDict);
251
+ }
252
+ }
253
+
254
+ size_t ZSTD_compressBlock_fast_dictMatchState(
255
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
256
+ void const* src, size_t srcSize)
257
+ {
258
+ ZSTD_compressionParameters const* cParams = &ms->cParams;
259
+ U32 const mls = cParams->minMatch;
260
+ assert(ms->dictMatchState != NULL);
261
+ switch(mls)
262
+ {
263
+ default: /* includes case 3 */
264
+ case 4 :
265
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 4, ZSTD_dictMatchState);
266
+ case 5 :
267
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 5, ZSTD_dictMatchState);
268
+ case 6 :
269
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 6, ZSTD_dictMatchState);
270
+ case 7 :
271
+ return ZSTD_compressBlock_fast_generic(ms, seqStore, rep, src, srcSize, 7, ZSTD_dictMatchState);
272
+ }
273
+ }
274
+
275
+
276
+ static size_t ZSTD_compressBlock_fast_extDict_generic(
277
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
278
+ void const* src, size_t srcSize, U32 const mls)
279
+ {
280
+ const ZSTD_compressionParameters* const cParams = &ms->cParams;
281
+ U32* const hashTable = ms->hashTable;
282
+ U32 const hlog = cParams->hashLog;
283
+ /* support stepSize of 0 */
284
+ U32 const stepSize = cParams->targetLength + !(cParams->targetLength);
285
+ const BYTE* const base = ms->window.base;
286
+ const BYTE* const dictBase = ms->window.dictBase;
287
+ const BYTE* const istart = (const BYTE*)src;
288
+ const BYTE* ip = istart;
289
+ const BYTE* anchor = istart;
290
+ const U32 dictStartIndex = ms->window.lowLimit;
291
+ const BYTE* const dictStart = dictBase + dictStartIndex;
292
+ const U32 prefixStartIndex = ms->window.dictLimit;
293
+ const BYTE* const prefixStart = base + prefixStartIndex;
294
+ const BYTE* const dictEnd = dictBase + prefixStartIndex;
295
+ const BYTE* const iend = istart + srcSize;
296
+ const BYTE* const ilimit = iend - 8;
297
+ U32 offset_1=rep[0], offset_2=rep[1];
298
+
299
+ /* Search Loop */
300
+ while (ip < ilimit) { /* < instead of <=, because (ip+1) */
301
+ const size_t h = ZSTD_hashPtr(ip, hlog, mls);
302
+ const U32 matchIndex = hashTable[h];
303
+ const BYTE* const matchBase = matchIndex < prefixStartIndex ? dictBase : base;
304
+ const BYTE* match = matchBase + matchIndex;
305
+ const U32 current = (U32)(ip-base);
306
+ const U32 repIndex = current + 1 - offset_1;
307
+ const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
308
+ const BYTE* const repMatch = repBase + repIndex;
309
+ size_t mLength;
310
+ hashTable[h] = current; /* update hash table */
311
+ assert(offset_1 <= current +1); /* check repIndex */
312
+
313
+ if ( (((U32)((prefixStartIndex-1) - repIndex) >= 3) /* intentional underflow */ & (repIndex > dictStartIndex))
314
+ && (MEM_read32(repMatch) == MEM_read32(ip+1)) ) {
315
+ const BYTE* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend;
316
+ mLength = ZSTD_count_2segments(ip+1+4, repMatch+4, iend, repMatchEnd, prefixStart) + 4;
317
+ ip++;
318
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, 0, mLength-MINMATCH);
319
+ } else {
320
+ if ( (matchIndex < dictStartIndex) ||
321
+ (MEM_read32(match) != MEM_read32(ip)) ) {
322
+ assert(stepSize >= 1);
323
+ ip += ((ip-anchor) >> kSearchStrength) + stepSize;
324
+ continue;
325
+ }
326
+ { const BYTE* matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend;
327
+ const BYTE* lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart;
328
+ U32 offset;
329
+ mLength = ZSTD_count_2segments(ip+4, match+4, iend, matchEnd, prefixStart) + 4;
330
+ while (((ip>anchor) & (match>lowMatchPtr)) && (ip[-1] == match[-1])) { ip--; match--; mLength++; } /* catch up */
331
+ offset = current - matchIndex;
332
+ offset_2 = offset_1;
333
+ offset_1 = offset;
334
+ ZSTD_storeSeq(seqStore, ip-anchor, anchor, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
335
+ } }
336
+
337
+ /* found a match : store it */
338
+ ip += mLength;
339
+ anchor = ip;
340
+
341
+ if (ip <= ilimit) {
342
+ /* Fill Table */
343
+ hashTable[ZSTD_hashPtr(base+current+2, hlog, mls)] = current+2;
344
+ hashTable[ZSTD_hashPtr(ip-2, hlog, mls)] = (U32)(ip-2-base);
345
+ /* check immediate repcode */
346
+ while (ip <= ilimit) {
347
+ U32 const current2 = (U32)(ip-base);
348
+ U32 const repIndex2 = current2 - offset_2;
349
+ const BYTE* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
350
+ if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (repIndex2 > dictStartIndex)) /* intentional overflow */
351
+ && (MEM_read32(repMatch2) == MEM_read32(ip)) ) {
352
+ const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
353
+ size_t const repLength2 = ZSTD_count_2segments(ip+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
354
+ U32 tmpOffset = offset_2; offset_2 = offset_1; offset_1 = tmpOffset; /* swap offset_2 <=> offset_1 */
355
+ ZSTD_storeSeq(seqStore, 0, anchor, 0, repLength2-MINMATCH);
356
+ hashTable[ZSTD_hashPtr(ip, hlog, mls)] = current2;
357
+ ip += repLength2;
358
+ anchor = ip;
359
+ continue;
360
+ }
361
+ break;
362
+ } } }
363
+
364
+ /* save reps for next block */
365
+ rep[0] = offset_1;
366
+ rep[1] = offset_2;
367
+
368
+ /* Return the last literals size */
369
+ return iend - anchor;
370
+ }
371
+
372
+
373
+ size_t ZSTD_compressBlock_fast_extDict(
374
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
375
+ void const* src, size_t srcSize)
376
+ {
377
+ ZSTD_compressionParameters const* cParams = &ms->cParams;
378
+ U32 const mls = cParams->minMatch;
379
+ switch(mls)
380
+ {
381
+ default: /* includes case 3 */
382
+ case 4 :
383
+ return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 4);
384
+ case 5 :
385
+ return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 5);
386
+ case 6 :
387
+ return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 6);
388
+ case 7 :
389
+ return ZSTD_compressBlock_fast_extDict_generic(ms, seqStore, rep, src, srcSize, 7);
390
+ }
391
+ }
@@ -0,0 +1,37 @@
1
+ /*
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under both the BSD-style license (found in the
6
+ * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
+ * in the COPYING file in the root directory of this source tree).
8
+ * You may select, at your option, one of the above-listed licenses.
9
+ */
10
+
11
+ #ifndef ZSTD_FAST_H
12
+ #define ZSTD_FAST_H
13
+
14
+ #if defined (__cplusplus)
15
+ extern "C" {
16
+ #endif
17
+
18
+ #include "mem.h" /* U32 */
19
+ #include "zstd_compress_internal.h"
20
+
21
+ void ZSTD_fillHashTable(ZSTD_matchState_t* ms,
22
+ void const* end, ZSTD_dictTableLoadMethod_e dtlm);
23
+ size_t ZSTD_compressBlock_fast(
24
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
25
+ void const* src, size_t srcSize);
26
+ size_t ZSTD_compressBlock_fast_dictMatchState(
27
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
28
+ void const* src, size_t srcSize);
29
+ size_t ZSTD_compressBlock_fast_extDict(
30
+ ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
31
+ void const* src, size_t srcSize);
32
+
33
+ #if defined (__cplusplus)
34
+ }
35
+ #endif
36
+
37
+ #endif /* ZSTD_FAST_H */