zstd-ruby 0.1.0
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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.gitmodules +3 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +29 -0
- data/README.md +63 -0
- data/Rakefile +22 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/zstdruby/extconf.rb +23 -0
- data/ext/zstdruby/libzstd/.gitignore +2 -0
- data/ext/zstdruby/libzstd/Makefile +133 -0
- data/ext/zstdruby/libzstd/README.md +77 -0
- data/ext/zstdruby/libzstd/common/bitstream.h +414 -0
- data/ext/zstdruby/libzstd/common/entropy_common.c +227 -0
- data/ext/zstdruby/libzstd/common/error_private.c +43 -0
- data/ext/zstdruby/libzstd/common/error_private.h +76 -0
- data/ext/zstdruby/libzstd/common/fse.h +668 -0
- data/ext/zstdruby/libzstd/common/fse_decompress.c +329 -0
- data/ext/zstdruby/libzstd/common/huf.h +238 -0
- data/ext/zstdruby/libzstd/common/mem.h +372 -0
- data/ext/zstdruby/libzstd/common/xxhash.c +867 -0
- data/ext/zstdruby/libzstd/common/xxhash.h +309 -0
- data/ext/zstdruby/libzstd/common/zstd_common.c +77 -0
- data/ext/zstdruby/libzstd/common/zstd_errors.h +60 -0
- data/ext/zstdruby/libzstd/common/zstd_internal.h +270 -0
- data/ext/zstdruby/libzstd/compress/fse_compress.c +850 -0
- data/ext/zstdruby/libzstd/compress/huf_compress.c +609 -0
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +3291 -0
- data/ext/zstdruby/libzstd/compress/zstd_opt.h +919 -0
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +885 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +2154 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +210 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +145 -0
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +74 -0
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.c +1913 -0
- data/ext/zstdruby/libzstd/dictBuilder/divsufsort.h +67 -0
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +1012 -0
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +111 -0
- data/ext/zstdruby/libzstd/dll/example/Makefile +47 -0
- data/ext/zstdruby/libzstd/dll/example/README.md +69 -0
- data/ext/zstdruby/libzstd/dll/example/build_package.bat +17 -0
- data/ext/zstdruby/libzstd/dll/example/fullbench-dll.sln +25 -0
- data/ext/zstdruby/libzstd/dll/example/fullbench-dll.vcxproj +179 -0
- data/ext/zstdruby/libzstd/dll/libzstd.def +86 -0
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +259 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +2095 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +80 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +3518 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +79 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +3159 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +79 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +3795 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +128 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +4056 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +149 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +4167 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +159 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +4540 -0
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +173 -0
- data/ext/zstdruby/libzstd/libzstd.pc.in +14 -0
- data/ext/zstdruby/libzstd/zstd.h +673 -0
- data/ext/zstdruby/zstdruby.c +117 -0
- data/ext/zstdruby/zstdruby.h +6 -0
- data/lib/zstd-ruby.rb +6 -0
- data/lib/zstd-ruby/version.rb +3 -0
- data/zstd-ruby.gemspec +37 -0
- metadata +170 -0
@@ -0,0 +1,309 @@
|
|
1
|
+
/*
|
2
|
+
xxHash - Extremely Fast Hash algorithm
|
3
|
+
Header File
|
4
|
+
Copyright (C) 2012-2016, 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
|
+
- xxHash source repository : https://github.com/Cyan4973/xxHash
|
33
|
+
*/
|
34
|
+
|
35
|
+
/* Notice extracted from xxHash homepage :
|
36
|
+
|
37
|
+
xxHash is an extremely fast Hash algorithm, running at RAM speed limits.
|
38
|
+
It also successfully passes all tests from the SMHasher suite.
|
39
|
+
|
40
|
+
Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz)
|
41
|
+
|
42
|
+
Name Speed Q.Score Author
|
43
|
+
xxHash 5.4 GB/s 10
|
44
|
+
CrapWow 3.2 GB/s 2 Andrew
|
45
|
+
MumurHash 3a 2.7 GB/s 10 Austin Appleby
|
46
|
+
SpookyHash 2.0 GB/s 10 Bob Jenkins
|
47
|
+
SBox 1.4 GB/s 9 Bret Mulvey
|
48
|
+
Lookup3 1.2 GB/s 9 Bob Jenkins
|
49
|
+
SuperFastHash 1.2 GB/s 1 Paul Hsieh
|
50
|
+
CityHash64 1.05 GB/s 10 Pike & Alakuijala
|
51
|
+
FNV 0.55 GB/s 5 Fowler, Noll, Vo
|
52
|
+
CRC32 0.43 GB/s 9
|
53
|
+
MD5-32 0.33 GB/s 10 Ronald L. Rivest
|
54
|
+
SHA1-32 0.28 GB/s 10
|
55
|
+
|
56
|
+
Q.Score is a measure of quality of the hash function.
|
57
|
+
It depends on successfully passing SMHasher test set.
|
58
|
+
10 is a perfect score.
|
59
|
+
|
60
|
+
A 64-bits version, named XXH64, is available since r35.
|
61
|
+
It offers much better speed, but for 64-bits applications only.
|
62
|
+
Name Speed on 64 bits Speed on 32 bits
|
63
|
+
XXH64 13.8 GB/s 1.9 GB/s
|
64
|
+
XXH32 6.8 GB/s 6.0 GB/s
|
65
|
+
*/
|
66
|
+
|
67
|
+
#ifndef XXHASH_H_5627135585666179
|
68
|
+
#define XXHASH_H_5627135585666179 1
|
69
|
+
|
70
|
+
#if defined (__cplusplus)
|
71
|
+
extern "C" {
|
72
|
+
#endif
|
73
|
+
|
74
|
+
#ifndef XXH_NAMESPACE
|
75
|
+
# define XXH_NAMESPACE ZSTD_ /* Zstandard specific */
|
76
|
+
#endif
|
77
|
+
|
78
|
+
|
79
|
+
/* ****************************
|
80
|
+
* Definitions
|
81
|
+
******************************/
|
82
|
+
#include <stddef.h> /* size_t */
|
83
|
+
typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode;
|
84
|
+
|
85
|
+
|
86
|
+
/* ****************************
|
87
|
+
* API modifier
|
88
|
+
******************************/
|
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 :
|
93
|
+
* #define XXH_PRIVATE_API
|
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.
|
97
|
+
*/
|
98
|
+
#ifdef XXH_PRIVATE_API
|
99
|
+
# ifndef XXH_STATIC_LINKING_ONLY
|
100
|
+
# define XXH_STATIC_LINKING_ONLY
|
101
|
+
# endif
|
102
|
+
# if defined(__GNUC__)
|
103
|
+
# define XXH_PUBLIC_API static __inline __attribute__((unused))
|
104
|
+
# elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
105
|
+
# define XXH_PUBLIC_API static inline
|
106
|
+
# elif defined(_MSC_VER)
|
107
|
+
# define XXH_PUBLIC_API static __inline
|
108
|
+
# else
|
109
|
+
# define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */
|
110
|
+
# endif
|
111
|
+
#else
|
112
|
+
# define XXH_PUBLIC_API /* do nothing */
|
113
|
+
#endif /* XXH_PRIVATE_API */
|
114
|
+
|
115
|
+
/*!XXH_NAMESPACE, aka Namespace Emulation :
|
116
|
+
|
117
|
+
If you want to include _and expose_ xxHash functions from within your own library,
|
118
|
+
but also want to avoid symbol collisions with another library which also includes xxHash,
|
119
|
+
|
120
|
+
you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library
|
121
|
+
with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values).
|
122
|
+
|
123
|
+
Note that no change is required within the calling program as long as it includes `xxhash.h` :
|
124
|
+
regular symbol name will be automatically translated by this header.
|
125
|
+
*/
|
126
|
+
#ifdef XXH_NAMESPACE
|
127
|
+
# define XXH_CAT(A,B) A##B
|
128
|
+
# define XXH_NAME2(A,B) XXH_CAT(A,B)
|
129
|
+
# define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32)
|
130
|
+
# define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64)
|
131
|
+
# define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber)
|
132
|
+
# define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState)
|
133
|
+
# define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState)
|
134
|
+
# define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState)
|
135
|
+
# define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState)
|
136
|
+
# define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset)
|
137
|
+
# define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset)
|
138
|
+
# define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update)
|
139
|
+
# define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update)
|
140
|
+
# define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest)
|
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)
|
148
|
+
#endif
|
149
|
+
|
150
|
+
|
151
|
+
/* *************************************
|
152
|
+
* Version
|
153
|
+
***************************************/
|
154
|
+
#define XXH_VERSION_MAJOR 0
|
155
|
+
#define XXH_VERSION_MINOR 6
|
156
|
+
#define XXH_VERSION_RELEASE 2
|
157
|
+
#define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE)
|
158
|
+
XXH_PUBLIC_API unsigned XXH_versionNumber (void);
|
159
|
+
|
160
|
+
|
161
|
+
/* ****************************
|
162
|
+
* Simple Hash Functions
|
163
|
+
******************************/
|
164
|
+
typedef unsigned int XXH32_hash_t;
|
165
|
+
typedef unsigned long long XXH64_hash_t;
|
166
|
+
|
167
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed);
|
168
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed);
|
169
|
+
|
170
|
+
/*!
|
171
|
+
XXH32() :
|
172
|
+
Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input".
|
173
|
+
The memory between input & input+length must be valid (allocated and read-accessible).
|
174
|
+
"seed" can be used to alter the result predictably.
|
175
|
+
Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s
|
176
|
+
XXH64() :
|
177
|
+
Calculate the 64-bits hash of sequence of length "len" stored at memory address "input".
|
178
|
+
"seed" can be used to alter the result predictably.
|
179
|
+
This function runs 2x faster on 64-bits systems, but slower on 32-bits systems (see benchmark).
|
180
|
+
*/
|
181
|
+
|
182
|
+
|
183
|
+
/* ****************************
|
184
|
+
* Streaming Hash Functions
|
185
|
+
******************************/
|
186
|
+
typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */
|
187
|
+
typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */
|
188
|
+
|
189
|
+
/*! State allocation, compatible with dynamic libraries */
|
190
|
+
|
191
|
+
XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void);
|
192
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr);
|
193
|
+
|
194
|
+
XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void);
|
195
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr);
|
196
|
+
|
197
|
+
|
198
|
+
/* hash streaming */
|
199
|
+
|
200
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed);
|
201
|
+
XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length);
|
202
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr);
|
203
|
+
|
204
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed);
|
205
|
+
XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length);
|
206
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr);
|
207
|
+
|
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()` .
|
212
|
+
|
213
|
+
XXH state must first be allocated, using XXH*_createState() .
|
214
|
+
|
215
|
+
Start a new hash by initializing state with a seed, using XXH*_reset().
|
216
|
+
|
217
|
+
Then, feed the hash state by calling XXH*_update() as many times as necessary.
|
218
|
+
Obviously, input must be allocated and read accessible.
|
219
|
+
The function returns an error code, with 0 meaning OK, and any other value meaning there is an error.
|
220
|
+
|
221
|
+
Finally, a hash value can be produced anytime, by using XXH*_digest().
|
222
|
+
This function returns the nn-bits hash as an int or long long.
|
223
|
+
|
224
|
+
It's still possible to continue inserting input into the hash state after a digest,
|
225
|
+
and generate some new hashes later on, by calling again XXH*_digest().
|
226
|
+
|
227
|
+
When done, free XXH state space if it was allocated dynamically.
|
228
|
+
*/
|
229
|
+
|
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
|
+
|
242
|
+
/* **************************
|
243
|
+
* Canonical representation
|
244
|
+
****************************/
|
245
|
+
typedef struct { unsigned char digest[4]; } XXH32_canonical_t;
|
246
|
+
typedef struct { unsigned char digest[8]; } XXH64_canonical_t;
|
247
|
+
|
248
|
+
XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash);
|
249
|
+
XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash);
|
250
|
+
|
251
|
+
XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src);
|
252
|
+
XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src);
|
253
|
+
|
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.
|
258
|
+
*/
|
259
|
+
|
260
|
+
|
261
|
+
#ifdef XXH_STATIC_LINKING_ONLY
|
262
|
+
|
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. */
|
273
|
+
|
274
|
+
struct XXH32_state_s {
|
275
|
+
unsigned total_len_32;
|
276
|
+
unsigned large_len;
|
277
|
+
unsigned v1;
|
278
|
+
unsigned v2;
|
279
|
+
unsigned v3;
|
280
|
+
unsigned v4;
|
281
|
+
unsigned mem32[4]; /* buffer defined as U32 for alignment */
|
282
|
+
unsigned memsize;
|
283
|
+
unsigned reserved; /* never read nor write, will be removed in a future version */
|
284
|
+
}; /* typedef'd to XXH32_state_t */
|
285
|
+
|
286
|
+
struct XXH64_state_s {
|
287
|
+
unsigned long long total_len;
|
288
|
+
unsigned long long v1;
|
289
|
+
unsigned long long v2;
|
290
|
+
unsigned long long v3;
|
291
|
+
unsigned long long v4;
|
292
|
+
unsigned long long mem64[4]; /* buffer defined as U64 for alignment */
|
293
|
+
unsigned memsize;
|
294
|
+
unsigned reserved[2]; /* never read nor write, will be removed in a future version */
|
295
|
+
}; /* typedef'd to XXH64_state_t */
|
296
|
+
|
297
|
+
|
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 */
|
303
|
+
|
304
|
+
|
305
|
+
#if defined (__cplusplus)
|
306
|
+
}
|
307
|
+
#endif
|
308
|
+
|
309
|
+
#endif /* XXHASH_H_5627135585666179 */
|
@@ -0,0 +1,77 @@
|
|
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
|
+
|
10
|
+
|
11
|
+
|
12
|
+
/*-*************************************
|
13
|
+
* Dependencies
|
14
|
+
***************************************/
|
15
|
+
#include <stdlib.h> /* malloc */
|
16
|
+
#include "error_private.h"
|
17
|
+
#define ZSTD_STATIC_LINKING_ONLY
|
18
|
+
#include "zstd.h" /* declaration of ZSTD_isError, ZSTD_getErrorName, ZSTD_getErrorCode, ZSTD_getErrorString, ZSTD_versionNumber */
|
19
|
+
|
20
|
+
|
21
|
+
/*-****************************************
|
22
|
+
* Version
|
23
|
+
******************************************/
|
24
|
+
unsigned ZSTD_versionNumber (void) { return ZSTD_VERSION_NUMBER; }
|
25
|
+
|
26
|
+
|
27
|
+
/*-****************************************
|
28
|
+
* ZSTD Error Management
|
29
|
+
******************************************/
|
30
|
+
/*! ZSTD_isError() :
|
31
|
+
* tells if a return value is an error code */
|
32
|
+
unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
|
33
|
+
|
34
|
+
/*! ZSTD_getErrorName() :
|
35
|
+
* provides error code string from function result (useful for debugging) */
|
36
|
+
const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
37
|
+
|
38
|
+
/*! ZSTD_getError() :
|
39
|
+
* convert a `size_t` function result into a proper ZSTD_errorCode enum */
|
40
|
+
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
|
41
|
+
|
42
|
+
/*! ZSTD_getErrorString() :
|
43
|
+
* provides error code string from enum */
|
44
|
+
const char* ZSTD_getErrorString(ZSTD_ErrorCode code) { return ERR_getErrorName(code); }
|
45
|
+
|
46
|
+
/* --- ZBUFF Error Management (deprecated) --- */
|
47
|
+
unsigned ZBUFF_isError(size_t errorCode) { return ERR_isError(errorCode); }
|
48
|
+
const char* ZBUFF_getErrorName(size_t errorCode) { return ERR_getErrorName(errorCode); }
|
49
|
+
|
50
|
+
|
51
|
+
/*=**************************************************************
|
52
|
+
* Custom allocator
|
53
|
+
****************************************************************/
|
54
|
+
/* default uses stdlib */
|
55
|
+
void* ZSTD_defaultAllocFunction(void* opaque, size_t size)
|
56
|
+
{
|
57
|
+
void* address = malloc(size);
|
58
|
+
(void)opaque;
|
59
|
+
return address;
|
60
|
+
}
|
61
|
+
|
62
|
+
void ZSTD_defaultFreeFunction(void* opaque, void* address)
|
63
|
+
{
|
64
|
+
(void)opaque;
|
65
|
+
free(address);
|
66
|
+
}
|
67
|
+
|
68
|
+
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem)
|
69
|
+
{
|
70
|
+
return customMem.customAlloc(customMem.opaque, size);
|
71
|
+
}
|
72
|
+
|
73
|
+
void ZSTD_free(void* ptr, ZSTD_customMem customMem)
|
74
|
+
{
|
75
|
+
if (ptr!=NULL)
|
76
|
+
customMem.customFree(customMem.opaque, ptr);
|
77
|
+
}
|
@@ -0,0 +1,60 @@
|
|
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
|
+
|
10
|
+
#ifndef ZSTD_ERRORS_H_398273423
|
11
|
+
#define ZSTD_ERRORS_H_398273423
|
12
|
+
|
13
|
+
#if defined (__cplusplus)
|
14
|
+
extern "C" {
|
15
|
+
#endif
|
16
|
+
|
17
|
+
/*===== dependency =====*/
|
18
|
+
#include <stddef.h> /* size_t */
|
19
|
+
|
20
|
+
|
21
|
+
/*-****************************************
|
22
|
+
* error codes list
|
23
|
+
******************************************/
|
24
|
+
typedef enum {
|
25
|
+
ZSTD_error_no_error,
|
26
|
+
ZSTD_error_GENERIC,
|
27
|
+
ZSTD_error_prefix_unknown,
|
28
|
+
ZSTD_error_version_unsupported,
|
29
|
+
ZSTD_error_parameter_unknown,
|
30
|
+
ZSTD_error_frameParameter_unsupported,
|
31
|
+
ZSTD_error_frameParameter_unsupportedBy32bits,
|
32
|
+
ZSTD_error_frameParameter_windowTooLarge,
|
33
|
+
ZSTD_error_compressionParameter_unsupported,
|
34
|
+
ZSTD_error_init_missing,
|
35
|
+
ZSTD_error_memory_allocation,
|
36
|
+
ZSTD_error_stage_wrong,
|
37
|
+
ZSTD_error_dstSize_tooSmall,
|
38
|
+
ZSTD_error_srcSize_wrong,
|
39
|
+
ZSTD_error_corruption_detected,
|
40
|
+
ZSTD_error_checksum_wrong,
|
41
|
+
ZSTD_error_tableLog_tooLarge,
|
42
|
+
ZSTD_error_maxSymbolValue_tooLarge,
|
43
|
+
ZSTD_error_maxSymbolValue_tooSmall,
|
44
|
+
ZSTD_error_dictionary_corrupted,
|
45
|
+
ZSTD_error_dictionary_wrong,
|
46
|
+
ZSTD_error_maxCode
|
47
|
+
} ZSTD_ErrorCode;
|
48
|
+
|
49
|
+
/*! ZSTD_getErrorCode() :
|
50
|
+
convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
|
51
|
+
which can be used to compare directly with enum list published into "error_public.h" */
|
52
|
+
ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
|
53
|
+
const char* ZSTD_getErrorString(ZSTD_ErrorCode code);
|
54
|
+
|
55
|
+
|
56
|
+
#if defined (__cplusplus)
|
57
|
+
}
|
58
|
+
#endif
|
59
|
+
|
60
|
+
#endif /* ZSTD_ERRORS_H_398273423 */
|
@@ -0,0 +1,270 @@
|
|
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
|
+
|
10
|
+
#ifndef ZSTD_CCOMMON_H_MODULE
|
11
|
+
#define ZSTD_CCOMMON_H_MODULE
|
12
|
+
|
13
|
+
/*-*******************************************************
|
14
|
+
* Compiler specifics
|
15
|
+
*********************************************************/
|
16
|
+
#ifdef _MSC_VER /* Visual Studio */
|
17
|
+
# define FORCE_INLINE static __forceinline
|
18
|
+
# include <intrin.h> /* For Visual 2005 */
|
19
|
+
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
20
|
+
# pragma warning(disable : 4324) /* disable: C4324: padded structure */
|
21
|
+
# pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */
|
22
|
+
#else
|
23
|
+
# if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
|
24
|
+
# ifdef __GNUC__
|
25
|
+
# define FORCE_INLINE static inline __attribute__((always_inline))
|
26
|
+
# else
|
27
|
+
# define FORCE_INLINE static inline
|
28
|
+
# endif
|
29
|
+
# else
|
30
|
+
# define FORCE_INLINE static
|
31
|
+
# endif /* __STDC_VERSION__ */
|
32
|
+
#endif
|
33
|
+
|
34
|
+
#ifdef _MSC_VER
|
35
|
+
# define FORCE_NOINLINE static __declspec(noinline)
|
36
|
+
#else
|
37
|
+
# ifdef __GNUC__
|
38
|
+
# define FORCE_NOINLINE static __attribute__((__noinline__))
|
39
|
+
# else
|
40
|
+
# define FORCE_NOINLINE static
|
41
|
+
# endif
|
42
|
+
#endif
|
43
|
+
|
44
|
+
|
45
|
+
/*-*************************************
|
46
|
+
* Dependencies
|
47
|
+
***************************************/
|
48
|
+
#include "mem.h"
|
49
|
+
#include "error_private.h"
|
50
|
+
#define ZSTD_STATIC_LINKING_ONLY
|
51
|
+
#include "zstd.h"
|
52
|
+
|
53
|
+
|
54
|
+
/*-*************************************
|
55
|
+
* shared macros
|
56
|
+
***************************************/
|
57
|
+
#define MIN(a,b) ((a)<(b) ? (a) : (b))
|
58
|
+
#define MAX(a,b) ((a)>(b) ? (a) : (b))
|
59
|
+
#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
|
60
|
+
#define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */
|
61
|
+
|
62
|
+
|
63
|
+
/*-*************************************
|
64
|
+
* Common constants
|
65
|
+
***************************************/
|
66
|
+
#define ZSTD_OPT_NUM (1<<12)
|
67
|
+
#define ZSTD_DICT_MAGIC 0xEC30A437 /* v0.7+ */
|
68
|
+
|
69
|
+
#define ZSTD_REP_NUM 3 /* number of repcodes */
|
70
|
+
#define ZSTD_REP_CHECK (ZSTD_REP_NUM) /* number of repcodes to check by the optimal parser */
|
71
|
+
#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
|
72
|
+
#define ZSTD_REP_MOVE_OPT (ZSTD_REP_NUM)
|
73
|
+
static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
|
74
|
+
|
75
|
+
#define KB *(1 <<10)
|
76
|
+
#define MB *(1 <<20)
|
77
|
+
#define GB *(1U<<30)
|
78
|
+
|
79
|
+
#define BIT7 128
|
80
|
+
#define BIT6 64
|
81
|
+
#define BIT5 32
|
82
|
+
#define BIT4 16
|
83
|
+
#define BIT1 2
|
84
|
+
#define BIT0 1
|
85
|
+
|
86
|
+
#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
|
87
|
+
static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
|
88
|
+
static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
|
89
|
+
|
90
|
+
#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
|
91
|
+
static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
|
92
|
+
typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
|
93
|
+
|
94
|
+
#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
|
95
|
+
#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
|
96
|
+
|
97
|
+
#define HufLog 12
|
98
|
+
typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
|
99
|
+
|
100
|
+
#define LONGNBSEQ 0x7F00
|
101
|
+
|
102
|
+
#define MINMATCH 3
|
103
|
+
#define EQUAL_READ32 4
|
104
|
+
|
105
|
+
#define Litbits 8
|
106
|
+
#define MaxLit ((1<<Litbits) - 1)
|
107
|
+
#define MaxML 52
|
108
|
+
#define MaxLL 35
|
109
|
+
#define MaxOff 28
|
110
|
+
#define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
|
111
|
+
#define MLFSELog 9
|
112
|
+
#define LLFSELog 9
|
113
|
+
#define OffFSELog 8
|
114
|
+
|
115
|
+
static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
116
|
+
1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
|
117
|
+
13,14,15,16 };
|
118
|
+
static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
|
119
|
+
2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
|
120
|
+
-1,-1,-1,-1 };
|
121
|
+
#define LL_DEFAULTNORMLOG 6 /* for static allocation */
|
122
|
+
static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
|
123
|
+
|
124
|
+
static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
125
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
126
|
+
1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9,10,11,
|
127
|
+
12,13,14,15,16 };
|
128
|
+
static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
|
129
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
130
|
+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
|
131
|
+
-1,-1,-1,-1,-1 };
|
132
|
+
#define ML_DEFAULTNORMLOG 6 /* for static allocation */
|
133
|
+
static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
|
134
|
+
|
135
|
+
static const S16 OF_defaultNorm[MaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
|
136
|
+
1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
|
137
|
+
#define OF_DEFAULTNORMLOG 5 /* for static allocation */
|
138
|
+
static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
|
139
|
+
|
140
|
+
|
141
|
+
/*-*******************************************
|
142
|
+
* Shared functions to include for inlining
|
143
|
+
*********************************************/
|
144
|
+
static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
|
145
|
+
#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
|
146
|
+
|
147
|
+
/*! ZSTD_wildcopy() :
|
148
|
+
* custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
|
149
|
+
#define WILDCOPY_OVERLENGTH 8
|
150
|
+
MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
|
151
|
+
{
|
152
|
+
const BYTE* ip = (const BYTE*)src;
|
153
|
+
BYTE* op = (BYTE*)dst;
|
154
|
+
BYTE* const oend = op + length;
|
155
|
+
do
|
156
|
+
COPY8(op, ip)
|
157
|
+
while (op < oend);
|
158
|
+
}
|
159
|
+
|
160
|
+
MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
|
161
|
+
{
|
162
|
+
const BYTE* ip = (const BYTE*)src;
|
163
|
+
BYTE* op = (BYTE*)dst;
|
164
|
+
BYTE* const oend = (BYTE*)dstEnd;
|
165
|
+
do
|
166
|
+
COPY8(op, ip)
|
167
|
+
while (op < oend);
|
168
|
+
}
|
169
|
+
|
170
|
+
|
171
|
+
/*-*******************************************
|
172
|
+
* Private interfaces
|
173
|
+
*********************************************/
|
174
|
+
typedef struct ZSTD_stats_s ZSTD_stats_t;
|
175
|
+
|
176
|
+
typedef struct {
|
177
|
+
U32 off;
|
178
|
+
U32 len;
|
179
|
+
} ZSTD_match_t;
|
180
|
+
|
181
|
+
typedef struct {
|
182
|
+
U32 price;
|
183
|
+
U32 off;
|
184
|
+
U32 mlen;
|
185
|
+
U32 litlen;
|
186
|
+
U32 rep[ZSTD_REP_NUM];
|
187
|
+
} ZSTD_optimal_t;
|
188
|
+
|
189
|
+
|
190
|
+
typedef struct seqDef_s {
|
191
|
+
U32 offset;
|
192
|
+
U16 litLength;
|
193
|
+
U16 matchLength;
|
194
|
+
} seqDef;
|
195
|
+
|
196
|
+
|
197
|
+
typedef struct {
|
198
|
+
seqDef* sequencesStart;
|
199
|
+
seqDef* sequences;
|
200
|
+
BYTE* litStart;
|
201
|
+
BYTE* lit;
|
202
|
+
BYTE* llCode;
|
203
|
+
BYTE* mlCode;
|
204
|
+
BYTE* ofCode;
|
205
|
+
U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
|
206
|
+
U32 longLengthPos;
|
207
|
+
/* opt */
|
208
|
+
ZSTD_optimal_t* priceTable;
|
209
|
+
ZSTD_match_t* matchTable;
|
210
|
+
U32* matchLengthFreq;
|
211
|
+
U32* litLengthFreq;
|
212
|
+
U32* litFreq;
|
213
|
+
U32* offCodeFreq;
|
214
|
+
U32 matchLengthSum;
|
215
|
+
U32 matchSum;
|
216
|
+
U32 litLengthSum;
|
217
|
+
U32 litSum;
|
218
|
+
U32 offCodeSum;
|
219
|
+
U32 log2matchLengthSum;
|
220
|
+
U32 log2matchSum;
|
221
|
+
U32 log2litLengthSum;
|
222
|
+
U32 log2litSum;
|
223
|
+
U32 log2offCodeSum;
|
224
|
+
U32 factor;
|
225
|
+
U32 staticPrices;
|
226
|
+
U32 cachedPrice;
|
227
|
+
U32 cachedLitLength;
|
228
|
+
const BYTE* cachedLiterals;
|
229
|
+
} seqStore_t;
|
230
|
+
|
231
|
+
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
|
232
|
+
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
|
233
|
+
int ZSTD_isSkipFrame(ZSTD_DCtx* dctx);
|
234
|
+
|
235
|
+
/* custom memory allocation functions */
|
236
|
+
void* ZSTD_defaultAllocFunction(void* opaque, size_t size);
|
237
|
+
void ZSTD_defaultFreeFunction(void* opaque, void* address);
|
238
|
+
#ifndef ZSTD_DLL_IMPORT
|
239
|
+
static const ZSTD_customMem defaultCustomMem = { ZSTD_defaultAllocFunction, ZSTD_defaultFreeFunction, NULL };
|
240
|
+
#endif
|
241
|
+
void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
|
242
|
+
void ZSTD_free(void* ptr, ZSTD_customMem customMem);
|
243
|
+
|
244
|
+
|
245
|
+
/*====== common function ======*/
|
246
|
+
|
247
|
+
MEM_STATIC U32 ZSTD_highbit32(U32 val)
|
248
|
+
{
|
249
|
+
# if defined(_MSC_VER) /* Visual */
|
250
|
+
unsigned long r=0;
|
251
|
+
_BitScanReverse(&r, val);
|
252
|
+
return (unsigned)r;
|
253
|
+
# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
|
254
|
+
return 31 - __builtin_clz(val);
|
255
|
+
# else /* Software version */
|
256
|
+
static const int DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 };
|
257
|
+
U32 v = val;
|
258
|
+
int r;
|
259
|
+
v |= v >> 1;
|
260
|
+
v |= v >> 2;
|
261
|
+
v |= v >> 4;
|
262
|
+
v |= v >> 8;
|
263
|
+
v |= v >> 16;
|
264
|
+
r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27];
|
265
|
+
return r;
|
266
|
+
# endif
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
#endif /* ZSTD_CCOMMON_H_MODULE */
|