extzstd 0.0.1.CONCEPT
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +24 -0
- data/README.md +47 -0
- data/Rakefile +147 -0
- data/contrib/zstd/LICENSE +26 -0
- data/contrib/zstd/Makefile +114 -0
- data/contrib/zstd/fse.c +1521 -0
- data/contrib/zstd/fse.h +380 -0
- data/contrib/zstd/fse_static.h +108 -0
- data/contrib/zstd/libzstd.pc.in +14 -0
- data/contrib/zstd/zstd.c +1801 -0
- data/contrib/zstd/zstd.h +102 -0
- data/contrib/zstd/zstd_static.h +80 -0
- data/ext/extconf.rb +17 -0
- data/ext/extzstd-stream.c +219 -0
- data/ext/extzstd.c +134 -0
- data/ext/extzstd.h +52 -0
- data/gemstub.rb +19 -0
- data/lib/extzstd/version.rb +5 -0
- data/lib/extzstd.rb +12 -0
- metadata +85 -0
data/contrib/zstd/fse.h
ADDED
@@ -0,0 +1,380 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
FSE : Finite State Entropy coder
|
3
|
+
header file
|
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
|
+
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
|
+
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
34
|
+
****************************************************************** */
|
35
|
+
#pragma once
|
36
|
+
|
37
|
+
#if defined (__cplusplus)
|
38
|
+
extern "C" {
|
39
|
+
#endif
|
40
|
+
|
41
|
+
|
42
|
+
/******************************************
|
43
|
+
* Includes
|
44
|
+
******************************************/
|
45
|
+
#include <stddef.h> // size_t, ptrdiff_t
|
46
|
+
|
47
|
+
|
48
|
+
/******************************************
|
49
|
+
* FSE simple functions
|
50
|
+
******************************************/
|
51
|
+
size_t FSE_compress(void* dst, size_t maxDstSize,
|
52
|
+
const void* src, size_t srcSize);
|
53
|
+
size_t FSE_decompress(void* dst, size_t maxDstSize,
|
54
|
+
const void* cSrc, size_t cSrcSize);
|
55
|
+
/*
|
56
|
+
FSE_compress():
|
57
|
+
Compress content of buffer 'src', of size 'srcSize', into destination buffer 'dst'.
|
58
|
+
'dst' buffer must be already allocated, and sized to handle worst case situations.
|
59
|
+
Worst case size evaluation is provided by FSE_compressBound().
|
60
|
+
return : size of compressed data
|
61
|
+
Special values : if result == 0, data is uncompressible => Nothing is stored within cSrc !!
|
62
|
+
if result == 1, data is one constant element x srcSize times. Use RLE compression.
|
63
|
+
if FSE_isError(result), it's an error code.
|
64
|
+
|
65
|
+
FSE_decompress():
|
66
|
+
Decompress FSE data from buffer 'cSrc', of size 'cSrcSize',
|
67
|
+
into already allocated destination buffer 'dst', of size 'maxDstSize'.
|
68
|
+
** Important ** : This function doesn't decompress uncompressed nor RLE data !
|
69
|
+
return : size of regenerated data (<= maxDstSize)
|
70
|
+
or an error code, which can be tested using FSE_isError()
|
71
|
+
*/
|
72
|
+
|
73
|
+
|
74
|
+
size_t FSE_decompressRLE(void* dst, size_t originalSize,
|
75
|
+
const void* cSrc, size_t cSrcSize);
|
76
|
+
/*
|
77
|
+
FSE_decompressRLE():
|
78
|
+
Decompress specific RLE corner case (equivalent to memset()).
|
79
|
+
cSrcSize must be == 1. originalSize must be exact.
|
80
|
+
return : size of regenerated data (==originalSize)
|
81
|
+
or an error code, which can be tested using FSE_isError()
|
82
|
+
|
83
|
+
Note : there is no function provided for uncompressed data, as it's just a simple memcpy()
|
84
|
+
*/
|
85
|
+
|
86
|
+
|
87
|
+
/******************************************
|
88
|
+
* Tool functions
|
89
|
+
******************************************/
|
90
|
+
size_t FSE_compressBound(size_t size); /* maximum compressed size */
|
91
|
+
|
92
|
+
/* Error Management */
|
93
|
+
unsigned FSE_isError(size_t code); /* tells if a return value is an error code */
|
94
|
+
const char* FSE_getErrorName(size_t code); /* provides error code string (useful for debugging) */
|
95
|
+
|
96
|
+
|
97
|
+
/******************************************
|
98
|
+
* FSE advanced functions
|
99
|
+
******************************************/
|
100
|
+
/*
|
101
|
+
FSE_compress2():
|
102
|
+
Same as FSE_compress(), but allows the selection of 'maxSymbolValue' and 'tableLog'
|
103
|
+
Both parameters can be defined as '0' to mean : use default value
|
104
|
+
return : size of compressed data
|
105
|
+
or -1 if there is an error
|
106
|
+
*/
|
107
|
+
size_t FSE_compress2 (void* dst, size_t dstSize, const void* src, size_t srcSize, unsigned maxSymbolValue, unsigned tableLog);
|
108
|
+
|
109
|
+
|
110
|
+
/******************************************
|
111
|
+
FSE detailed API
|
112
|
+
******************************************/
|
113
|
+
/*
|
114
|
+
int FSE_compress(char* dest, const char* source, int inputSize) does the following:
|
115
|
+
1. count symbol occurrence from source[] into table count[]
|
116
|
+
2. normalize counters so that sum(count[]) == Power_of_2 (2^tableLog)
|
117
|
+
3. save normalized counters to memory buffer using writeHeader()
|
118
|
+
4. build encoding table 'CTable' from normalized counters
|
119
|
+
5. encode the data stream using encoding table
|
120
|
+
|
121
|
+
int FSE_decompress(char* dest, int originalSize, const char* compressed) performs:
|
122
|
+
1. read normalized counters with readHeader()
|
123
|
+
2. build decoding table 'DTable' from normalized counters
|
124
|
+
3. decode the data stream using decoding table
|
125
|
+
|
126
|
+
The following API allows triggering specific sub-functions.
|
127
|
+
*/
|
128
|
+
|
129
|
+
/* *** COMPRESSION *** */
|
130
|
+
|
131
|
+
size_t FSE_count(unsigned* count, const unsigned char* src, size_t srcSize, unsigned* maxSymbolValuePtr);
|
132
|
+
|
133
|
+
unsigned FSE_optimalTableLog(unsigned tableLog, size_t srcSize, unsigned maxSymbolValue);
|
134
|
+
size_t FSE_normalizeCount(short* normalizedCounter, unsigned tableLog, const unsigned* count, size_t total, unsigned maxSymbolValue);
|
135
|
+
|
136
|
+
size_t FSE_headerBound(unsigned maxSymbolValue, unsigned tableLog);
|
137
|
+
size_t FSE_writeHeader (void* headerBuffer, size_t headerBufferSize, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
|
138
|
+
|
139
|
+
void* FSE_createCTable (unsigned tableLog, unsigned maxSymbolValue);
|
140
|
+
void FSE_freeCTable (void* CTable);
|
141
|
+
size_t FSE_buildCTable(void* CTable, const short* normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
|
142
|
+
|
143
|
+
size_t FSE_compress_usingCTable (void* dst, size_t dstSize, const void* src, size_t srcSize, const void* CTable);
|
144
|
+
|
145
|
+
/*
|
146
|
+
The first step is to count all symbols. FSE_count() provides one quick way to do this job.
|
147
|
+
Result will be saved into 'count', a table of unsigned int, which must be already allocated, and have '*maxSymbolValuePtr+1' cells.
|
148
|
+
'source' is a table of char of size 'sourceSize'. All values within 'src' MUST be <= *maxSymbolValuePtr
|
149
|
+
*maxSymbolValuePtr will be updated, with its real value (necessarily <= original value)
|
150
|
+
FSE_count() will return the number of occurrence of the most frequent symbol.
|
151
|
+
If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()).
|
152
|
+
|
153
|
+
The next step is to normalize the frequencies.
|
154
|
+
FSE_normalizeCount() will ensure that sum of frequencies is == 2 ^'tableLog'.
|
155
|
+
It also guarantees a minimum of 1 to any Symbol which frequency is >= 1.
|
156
|
+
You can use input 'tableLog'==0 to mean "use default tableLog value".
|
157
|
+
If you are unsure of which tableLog value to use, you can optionally call FSE_optimalTableLog(),
|
158
|
+
which will provide the optimal valid tableLog given sourceSize, maxSymbolValue, and a user-defined maximum (0 means "default").
|
159
|
+
|
160
|
+
The result of FSE_normalizeCount() will be saved into a table,
|
161
|
+
called 'normalizedCounter', which is a table of signed short.
|
162
|
+
'normalizedCounter' must be already allocated, and have at least 'maxSymbolValue+1' cells.
|
163
|
+
The return value is tableLog if everything proceeded as expected.
|
164
|
+
It is 0 if there is a single symbol within distribution.
|
165
|
+
If there is an error(typically, invalid tableLog value), the function will return an ErrorCode (which can be tested using FSE_isError()).
|
166
|
+
|
167
|
+
'normalizedCounter' can be saved in a compact manner to a memory area using FSE_writeHeader().
|
168
|
+
'header' buffer must be already allocated.
|
169
|
+
For guaranteed success, buffer size must be at least FSE_headerBound().
|
170
|
+
The result of the function is the number of bytes written into 'header'.
|
171
|
+
If there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()) (for example, buffer size too small).
|
172
|
+
|
173
|
+
'normalizedCounter' can then be used to create the compression tables 'CTable'.
|
174
|
+
The space required by 'CTable' must be already allocated. Its size is provided by FSE_sizeof_CTable().
|
175
|
+
'CTable' must be aligned of 4 bytes boundaries.
|
176
|
+
You can then use FSE_buildCTable() to fill 'CTable'.
|
177
|
+
In both cases, if there is an error, the function will return an ErrorCode (which can be tested using FSE_isError()).
|
178
|
+
|
179
|
+
'CTable' can then be used to compress 'source', with FSE_compress_usingCTable().
|
180
|
+
Similar to FSE_count(), the convention is that 'source' is assumed to be a table of char of size 'sourceSize'
|
181
|
+
The function returns the size of compressed data (without header), or -1 if failed.
|
182
|
+
*/
|
183
|
+
|
184
|
+
|
185
|
+
/* *** DECOMPRESSION *** */
|
186
|
+
|
187
|
+
size_t FSE_readHeader (short* normalizedCounter, unsigned* maxSymbolValuePtr, unsigned* tableLogPtr, const void* headerBuffer, size_t hbSize);
|
188
|
+
|
189
|
+
void* FSE_createDTable(unsigned tableLog);
|
190
|
+
void FSE_freeDTable(void* DTable);
|
191
|
+
size_t FSE_buildDTable (void* DTable, const short* const normalizedCounter, unsigned maxSymbolValue, unsigned tableLog);
|
192
|
+
|
193
|
+
size_t FSE_decompress_usingDTable(void* dst, size_t maxDstSize, const void* cSrc, size_t cSrcSize, const void* DTable, size_t fastMode);
|
194
|
+
|
195
|
+
/*
|
196
|
+
If the block is RLE compressed, or uncompressed, use the relevant specific functions.
|
197
|
+
|
198
|
+
The first step is to obtain the normalized frequencies of symbols.
|
199
|
+
This can be performed by reading a header with FSE_readHeader().
|
200
|
+
'normalizedCounter' must be already allocated, and have at least '*maxSymbolValuePtr+1' cells of short.
|
201
|
+
In practice, that means it's necessary to know 'maxSymbolValue' beforehand,
|
202
|
+
or size the table to handle worst case situations (typically 256).
|
203
|
+
FSE_readHeader will provide 'tableLog' and 'maxSymbolValue' stored into the header.
|
204
|
+
The result of FSE_readHeader() is the number of bytes read from 'header'.
|
205
|
+
The following values have special meaning :
|
206
|
+
return 2 : there is only a single symbol value. The value is provided into the second byte of header.
|
207
|
+
return 1 : data is uncompressed
|
208
|
+
If there is an error, the function will return an error code, which can be tested using FSE_isError().
|
209
|
+
|
210
|
+
The next step is to create the decompression tables 'DTable' from 'normalizedCounter'.
|
211
|
+
This is performed by the function FSE_buildDTable().
|
212
|
+
The space required by 'DTable' must be already allocated and properly aligned.
|
213
|
+
One can create a DTable using FSE_createDTable().
|
214
|
+
The function will return 1 if DTable is compatible with fastMode, 0 otherwise.
|
215
|
+
If there is an error, the function will return an error code, which can be tested using FSE_isError().
|
216
|
+
|
217
|
+
'DTable' can then be used to decompress 'compressed', with FSE_decompress_usingDTable().
|
218
|
+
Only trigger fastMode if it was authorized by result of FSE_buildDTable(), otherwise decompression will fail.
|
219
|
+
cSrcSize must be correct, otherwise decompression will fail.
|
220
|
+
FSE_decompress_usingDTable() result will tell how many bytes were regenerated.
|
221
|
+
If there is an error, the function will return an error code, which can be tested using FSE_isError().
|
222
|
+
*/
|
223
|
+
|
224
|
+
|
225
|
+
/******************************************
|
226
|
+
* FSE streaming compression API
|
227
|
+
******************************************/
|
228
|
+
typedef struct
|
229
|
+
{
|
230
|
+
size_t bitContainer;
|
231
|
+
int bitPos;
|
232
|
+
char* startPtr;
|
233
|
+
char* ptr;
|
234
|
+
} FSE_CStream_t;
|
235
|
+
|
236
|
+
typedef struct
|
237
|
+
{
|
238
|
+
ptrdiff_t value;
|
239
|
+
const void* stateTable;
|
240
|
+
const void* symbolTT;
|
241
|
+
unsigned stateLog;
|
242
|
+
} FSE_CState_t;
|
243
|
+
|
244
|
+
void FSE_initCStream(FSE_CStream_t* bitC, void* dstBuffer);
|
245
|
+
void FSE_initCState(FSE_CState_t* CStatePtr, const void* CTable);
|
246
|
+
|
247
|
+
void FSE_encodeByte(FSE_CStream_t* bitC, FSE_CState_t* CStatePtr, unsigned char symbol);
|
248
|
+
void FSE_addBits(FSE_CStream_t* bitC, size_t value, unsigned nbBits);
|
249
|
+
void FSE_flushBits(FSE_CStream_t* bitC);
|
250
|
+
|
251
|
+
void FSE_flushCState(FSE_CStream_t* bitC, const FSE_CState_t* CStatePtr);
|
252
|
+
size_t FSE_closeCStream(FSE_CStream_t* bitC);
|
253
|
+
|
254
|
+
/*
|
255
|
+
These functions are inner components of FSE_compress_usingCTable().
|
256
|
+
They allow creation of custom streams, mixing multiple tables and bit sources.
|
257
|
+
|
258
|
+
A key property to keep in mind is that encoding and decoding are done **in reverse direction**.
|
259
|
+
So the first symbol you will encode is the last you will decode, like a lifo stack.
|
260
|
+
|
261
|
+
You will need a few variables to track your CStream. They are :
|
262
|
+
|
263
|
+
void* CTable; // Provided by FSE_buildCTable()
|
264
|
+
FSE_CStream_t bitC; // bitStream tracking structure
|
265
|
+
FSE_CState_t state; // State tracking structure
|
266
|
+
|
267
|
+
|
268
|
+
The first thing to do is to init the bitStream, and the state.
|
269
|
+
FSE_initCStream(&bitC, dstBuffer);
|
270
|
+
FSE_initState(&state, CTable);
|
271
|
+
|
272
|
+
You can then encode your input data, byte after byte.
|
273
|
+
FSE_encodeByte() outputs a maximum of 'tableLog' bits at a time.
|
274
|
+
Remember decoding will be done in reverse direction.
|
275
|
+
FSE_encodeByte(&bitStream, &state, symbol);
|
276
|
+
|
277
|
+
At any time, you can add any bit sequence.
|
278
|
+
Note : maximum allowed nbBits is 25, for compatibility with 32-bits decoders
|
279
|
+
FSE_addBits(&bitStream, bitField, nbBits);
|
280
|
+
|
281
|
+
The above methods don't commit data to memory, they just store it into local register, for speed.
|
282
|
+
Local register size is 64-bits on 64-bits systems, 32-bits on 32-bits systems (size_t).
|
283
|
+
Writing data to memory is a manual operation, performed by the flushBits function.
|
284
|
+
FSE_flushBits(&bitStream);
|
285
|
+
|
286
|
+
Your last FSE encoding operation shall be to flush your last state value(s).
|
287
|
+
FSE_flushState(&bitStream, &state);
|
288
|
+
|
289
|
+
You must then close the bitStream if you opened it with FSE_initCStream().
|
290
|
+
It's possible to embed some user-info into the header, as an optionalId [0-31].
|
291
|
+
The function returns the size in bytes of CStream.
|
292
|
+
If there is an error, it returns an errorCode (which can be tested using FSE_isError()).
|
293
|
+
size_t size = FSE_closeCStream(&bitStream, optionalId);
|
294
|
+
*/
|
295
|
+
|
296
|
+
|
297
|
+
/******************************************
|
298
|
+
* FSE streaming decompression API
|
299
|
+
******************************************/
|
300
|
+
//typedef unsigned int bitD_t;
|
301
|
+
typedef size_t bitD_t;
|
302
|
+
|
303
|
+
typedef struct
|
304
|
+
{
|
305
|
+
bitD_t bitContainer;
|
306
|
+
unsigned bitsConsumed;
|
307
|
+
const char* ptr;
|
308
|
+
const char* start;
|
309
|
+
} FSE_DStream_t;
|
310
|
+
|
311
|
+
typedef struct
|
312
|
+
{
|
313
|
+
bitD_t state;
|
314
|
+
const void* table;
|
315
|
+
} FSE_DState_t;
|
316
|
+
|
317
|
+
|
318
|
+
size_t FSE_initDStream(FSE_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
|
319
|
+
void FSE_initDState(FSE_DState_t* DStatePtr, FSE_DStream_t* bitD, const void* DTable);
|
320
|
+
|
321
|
+
unsigned char FSE_decodeSymbol(FSE_DState_t* DStatePtr, FSE_DStream_t* bitD);
|
322
|
+
bitD_t FSE_readBits(FSE_DStream_t* bitD, unsigned nbBits);
|
323
|
+
unsigned int FSE_reloadDStream(FSE_DStream_t* bitD);
|
324
|
+
|
325
|
+
unsigned FSE_endOfDStream(const FSE_DStream_t* bitD);
|
326
|
+
unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr);
|
327
|
+
|
328
|
+
/*
|
329
|
+
Let's now decompose FSE_decompress_usingDTable() into its unitary elements.
|
330
|
+
You will decode FSE-encoded symbols from the bitStream,
|
331
|
+
and also any other bitFields you put in, **in reverse order**.
|
332
|
+
|
333
|
+
You will need a few variables to track your bitStream. They are :
|
334
|
+
|
335
|
+
FSE_DStream_t DStream; // Stream context
|
336
|
+
FSE_DState_t DState; // State context. Multiple ones are possible
|
337
|
+
const void* DTable; // Decoding table, provided by FSE_buildDTable()
|
338
|
+
U32 tableLog; // Provided by FSE_readHeader()
|
339
|
+
|
340
|
+
The first thing to do is to init the bitStream.
|
341
|
+
errorCode = FSE_initDStream(&DStream, &optionalId, srcBuffer, srcSize);
|
342
|
+
|
343
|
+
You should then retrieve your initial state(s) (multiple ones are possible) :
|
344
|
+
errorCode = FSE_initDState(&DState, &DStream, DTable, tableLog);
|
345
|
+
|
346
|
+
You can then decode your data, symbol after symbol.
|
347
|
+
For information the maximum number of bits read by FSE_decodeSymbol() is 'tableLog'.
|
348
|
+
Keep in mind that symbols are decoded in reverse order, like a lifo stack (last in, first out).
|
349
|
+
unsigned char symbol = FSE_decodeSymbol(&DState, &DStream);
|
350
|
+
|
351
|
+
You can retrieve any bitfield you eventually stored into the bitStream (in reverse order)
|
352
|
+
Note : maximum allowed nbBits is 25
|
353
|
+
unsigned int bitField = FSE_readBits(&DStream, nbBits);
|
354
|
+
|
355
|
+
All above operations only read from local register (which size is controlled by bitD_t==32 bits).
|
356
|
+
Reading data from memory is manually performed by the reload method.
|
357
|
+
endSignal = FSE_reloadDStream(&DStream);
|
358
|
+
|
359
|
+
FSE_reloadDStream() result tells if there is still some more data to read from DStream.
|
360
|
+
0 : there is still some data left into the DStream.
|
361
|
+
1 Dstream reached end of buffer, but is not yet fully extracted. It will not load data from memory any more.
|
362
|
+
2 Dstream reached its exact end, corresponding in general to decompression completed.
|
363
|
+
3 Dstream went too far. Decompression result is corrupted.
|
364
|
+
|
365
|
+
When reaching end of buffer(1), progress slowly if you decode multiple symbols per loop,
|
366
|
+
to properly detect the exact end of stream.
|
367
|
+
After each decoded symbol, check if DStream is fully consumed using this simple test :
|
368
|
+
FSE_reloadDStream(&DStream) >= 2
|
369
|
+
|
370
|
+
When it's done, verify decompression is fully completed, by checking both DStream and the relevant states.
|
371
|
+
Checking if DStream has reached its end is performed by :
|
372
|
+
FSE_endOfDStream(&DStream);
|
373
|
+
Check also the states. There might be some entropy left there, still able to decode some high probability symbol.
|
374
|
+
FSE_endOfDState(&DState);
|
375
|
+
*/
|
376
|
+
|
377
|
+
|
378
|
+
#if defined (__cplusplus)
|
379
|
+
}
|
380
|
+
#endif
|
@@ -0,0 +1,108 @@
|
|
1
|
+
/* ******************************************************************
|
2
|
+
FSE : Finite State Entropy coder
|
3
|
+
header file for static linking (only)
|
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
|
+
- Source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
33
|
+
- Public forum : https://groups.google.com/forum/#!forum/lz4c
|
34
|
+
****************************************************************** */
|
35
|
+
#pragma once
|
36
|
+
|
37
|
+
#if defined (__cplusplus)
|
38
|
+
extern "C" {
|
39
|
+
#endif
|
40
|
+
|
41
|
+
|
42
|
+
/******************************************
|
43
|
+
* Tool functions
|
44
|
+
******************************************/
|
45
|
+
#define FSE_MAX_HEADERSIZE 512
|
46
|
+
#define FSE_COMPRESSBOUND(size) (size + (size>>7) + FSE_MAX_HEADERSIZE) /* Macro can be useful for static allocation */
|
47
|
+
|
48
|
+
|
49
|
+
/******************************************
|
50
|
+
* Static allocation
|
51
|
+
******************************************/
|
52
|
+
/* You can statically allocate a CTable as a table of U32 using below macro */
|
53
|
+
#define FSE_CTABLE_SIZE_U32(maxTableLog, maxSymbolValue) (1 + (1<<(maxTableLog-1)) + ((maxSymbolValue+1)*2))
|
54
|
+
#define FSE_DTABLE_SIZE_U32(maxTableLog) ((1<<maxTableLog)+1)
|
55
|
+
|
56
|
+
|
57
|
+
/******************************************
|
58
|
+
* FSE supported API for DLL
|
59
|
+
******************************************/
|
60
|
+
#include "fse.h"
|
61
|
+
|
62
|
+
|
63
|
+
/******************************************
|
64
|
+
* Error Management
|
65
|
+
******************************************/
|
66
|
+
#define FSE_LIST_ERRORS(ITEM) \
|
67
|
+
ITEM(FSE_OK_NoError) ITEM(FSE_ERROR_GENERIC) \
|
68
|
+
ITEM(FSE_ERROR_tableLog_tooLarge) ITEM(FSE_ERROR_maxSymbolValue_tooLarge) \
|
69
|
+
ITEM(FSE_ERROR_dstSize_tooSmall) ITEM(FSE_ERROR_srcSize_wrong)\
|
70
|
+
ITEM(FSE_ERROR_corruptionDetected) \
|
71
|
+
ITEM(FSE_ERROR_maxCode)
|
72
|
+
|
73
|
+
#define FSE_GENERATE_ENUM(ENUM) ENUM,
|
74
|
+
typedef enum { FSE_LIST_ERRORS(FSE_GENERATE_ENUM) } FSE_errorCodes; /* enum is exposed, to detect & handle specific errors; compare function result to -enum value */
|
75
|
+
|
76
|
+
|
77
|
+
/******************************************
|
78
|
+
* FSE advanced API
|
79
|
+
******************************************/
|
80
|
+
size_t FSE_countFast(unsigned* count, const unsigned char* src, size_t srcSize, unsigned* maxSymbolValuePtr);
|
81
|
+
/* same as FSE_count(), but won't check if input really respect that all values within src are <= *maxSymbolValuePtr */
|
82
|
+
|
83
|
+
size_t FSE_buildCTable_raw (void* CTable, unsigned nbBits);
|
84
|
+
/* create a fake CTable, designed to not compress an input where each element uses nbBits */
|
85
|
+
|
86
|
+
size_t FSE_buildCTable_rle (void* CTable, unsigned char symbolValue);
|
87
|
+
/* create a fake CTable, designed to compress a single identical value */
|
88
|
+
|
89
|
+
size_t FSE_buildDTable_raw (void* DTable, unsigned nbBits);
|
90
|
+
/* create a fake DTable, designed to read an uncompressed bitstream where each element uses nbBits */
|
91
|
+
|
92
|
+
size_t FSE_buildDTable_rle (void* DTable, unsigned char symbolValue);
|
93
|
+
/* create a fake DTable, designed to always generate the same symbolValue */
|
94
|
+
|
95
|
+
|
96
|
+
/******************************************
|
97
|
+
* FSE streaming API
|
98
|
+
******************************************/
|
99
|
+
bitD_t FSE_readBitsFast(FSE_DStream_t* bitD, unsigned nbBits);
|
100
|
+
/* faster, but works only if nbBits >= 1 (otherwise, result will be corrupted) */
|
101
|
+
|
102
|
+
unsigned char FSE_decodeSymbolFast(FSE_DState_t* DStatePtr, FSE_DStream_t* bitD);
|
103
|
+
/* faster, but works only if nbBits >= 1 (otherwise, result will be corrupted) */
|
104
|
+
|
105
|
+
|
106
|
+
#if defined (__cplusplus)
|
107
|
+
}
|
108
|
+
#endif
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# ZSTD - standard compression algorithm
|
2
|
+
# Copyright (C) 2014-2015, Yann Collet.
|
3
|
+
# BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
4
|
+
|
5
|
+
prefix=@PREFIX@
|
6
|
+
libdir=@LIBDIR@
|
7
|
+
includedir=@INCLUDEDIR@
|
8
|
+
|
9
|
+
Name: zstd
|
10
|
+
Description: lossless compression algorithm library
|
11
|
+
URL: https://github.com/Cyan4973/zstd
|
12
|
+
Version: @VERSION@
|
13
|
+
Libs: -L@LIBDIR@ -lzstd
|
14
|
+
Cflags: -I@INCLUDEDIR@
|