blob: 614bd1eaba01c9d3b6e72869dfdc2d54083c35b2 [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Yann Collet4ded9e52016-08-30 10:04:33 -07002 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * 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).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Yann Collet4ded9e52016-08-30 10:04:33 -07009 */
Yann Collet2acb5d32015-10-29 16:49:43 +010010
Yann Collet2acb5d32015-10-29 16:49:43 +010011#ifndef ZSTD_CCOMMON_H_MODULE
12#define ZSTD_CCOMMON_H_MODULE
13
Yann Collet5c956d52016-09-06 15:05:19 +020014
Yann Collet7d360282016-02-12 00:07:30 +010015/*-*************************************
Yann Collet953ce722016-02-04 15:28:14 +010016* Dependencies
Yann Collet2acb5d32015-10-29 16:49:43 +010017***************************************/
Nick Terrell565e9252017-08-14 17:20:50 -070018#include "compiler.h"
Yann Collet2acb5d32015-10-29 16:49:43 +010019#include "mem.h"
Yann Collet977f1f32016-01-21 15:38:47 +010020#include "error_private.h"
Yann Colletd3b7f8d2016-06-04 19:47:02 +020021#define ZSTD_STATIC_LINKING_ONLY
22#include "zstd.h"
Nick Terrellde0414b2017-07-12 19:08:24 -070023#define FSE_STATIC_LINKING_ONLY
24#include "fse.h"
25#define HUF_STATIC_LINKING_ONLY
26#include "huf.h"
Yann Collet4bcc69b2017-03-01 11:33:25 -080027#ifndef XXH_STATIC_LINKING_ONLY
Yann Collet58e8d792017-06-02 18:20:48 -070028# define XXH_STATIC_LINKING_ONLY /* XXH64_state_t */
Yann Collet4bcc69b2017-03-01 11:33:25 -080029#endif
Yann Collet58e8d792017-06-02 18:20:48 -070030#include "xxhash.h" /* XXH_reset, update, digest */
31
32
Nick Terrellde6c6bc2017-08-24 18:09:50 -070033#if defined (__cplusplus)
34extern "C" {
35#endif
36
37
Yann Collet58e8d792017-06-02 18:20:48 -070038/*-*************************************
39* Debug
40***************************************/
41#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1)
42# include <assert.h>
43#else
44# ifndef assert
45# define assert(condition) ((void)0)
46# endif
47#endif
48
49#define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; }
50
51#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=2)
52# include <stdio.h>
Yann Collet33a66392017-06-28 11:09:43 -070053/* recommended values for ZSTD_DEBUG display levels :
Yann Colleta3d99262017-06-29 14:44:49 -070054 * 1 : no display, enables assert() only
Yann Collet33a66392017-06-28 11:09:43 -070055 * 2 : reserved for currently active debugging path
56 * 3 : events once per object lifetime (CCtx, CDict)
57 * 4 : events once per frame
58 * 5 : events once per block
59 * 6 : events once per sequence (*very* verbose) */
60# define DEBUGLOG(l, ...) { \
61 if (l<=ZSTD_DEBUG) { \
62 fprintf(stderr, __FILE__ ": "); \
63 fprintf(stderr, __VA_ARGS__); \
64 fprintf(stderr, " \n"); \
Yann Collet58e8d792017-06-02 18:20:48 -070065 } }
66#else
67# define DEBUGLOG(l, ...) {} /* disabled */
68#endif
Yann Collet2acb5d32015-10-29 16:49:43 +010069
70
Yann Collet7d360282016-02-12 00:07:30 +010071/*-*************************************
Yann Collet3e21ec52016-09-06 15:36:19 +020072* shared macros
Yann Collet14983e72015-11-11 21:38:21 +010073***************************************/
Yann Collet4f818182017-04-17 17:57:35 -070074#undef MIN
75#undef MAX
Yann Colletbe2010e2015-10-31 12:57:14 +010076#define MIN(a,b) ((a)<(b) ? (a) : (b))
Yann Collet14983e72015-11-11 21:38:21 +010077#define MAX(a,b) ((a)>(b) ? (a) : (b))
Yann Collet3e21ec52016-09-06 15:36:19 +020078#define CHECK_F(f) { size_t const errcod = f; if (ERR_isError(errcod)) return errcod; } /* check and Forward error code */
Yann Collet95d07d72016-09-06 16:38:51 +020079#define CHECK_E(f, e) { size_t const errcod = f; if (ERR_isError(errcod)) return ERROR(e); } /* check and send Error code */
Yann Collet2acb5d32015-10-29 16:49:43 +010080
81
Yann Collet7d360282016-02-12 00:07:30 +010082/*-*************************************
Yann Collet14983e72015-11-11 21:38:21 +010083* Common constants
84***************************************/
inikep87d4f3d2016-03-02 15:56:24 +010085#define ZSTD_OPT_NUM (1<<12)
Yann Collet88fcd292015-11-25 14:42:45 +010086
inikep5f49eba2016-08-10 15:01:53 +020087#define ZSTD_REP_NUM 3 /* number of repcodes */
88#define ZSTD_REP_CHECK (ZSTD_REP_NUM) /* number of repcodes to check by the optimal parser */
89#define ZSTD_REP_MOVE (ZSTD_REP_NUM-1)
90#define ZSTD_REP_MOVE_OPT (ZSTD_REP_NUM)
Yann Collet4266c0a2016-06-14 01:49:25 +020091static const U32 repStartValue[ZSTD_REP_NUM] = { 1, 4, 8 };
Yann Collet14983e72015-11-11 21:38:21 +010092
93#define KB *(1 <<10)
94#define MB *(1 <<20)
95#define GB *(1U<<30)
Yann Collet2acb5d32015-10-29 16:49:43 +010096
Yann Collet14983e72015-11-11 21:38:21 +010097#define BIT7 128
98#define BIT6 64
99#define BIT5 32
100#define BIT4 16
101#define BIT1 2
102#define BIT0 1
103
Yann Collet673f0d72016-06-06 00:26:38 +0200104#define ZSTD_WINDOWLOG_ABSOLUTEMIN 10
105static const size_t ZSTD_fcs_fieldSize[4] = { 0, 2, 4, 8 };
Yann Colletc46fb922016-05-29 05:01:04 +0200106static const size_t ZSTD_did_fieldSize[4] = { 0, 1, 2, 4 };
Yann Collet37f3d1b2016-03-19 15:11:42 +0100107
Yann Colletdf4e9bb2017-09-26 14:31:06 -0700108#define ZSTD_FRAMEIDSIZE 4
109static const size_t ZSTD_frameIdSize = ZSTD_FRAMEIDSIZE; /* magic number size */
Yann Colletb8d4a382017-09-25 15:25:07 -0700110
Yann Collet49bb0042016-06-04 20:17:38 +0200111#define ZSTD_BLOCKHEADERSIZE 3 /* C standard doesn't allow `static const` variable to be init using another `static const` variable */
Yann Collet37f3d1b2016-03-19 15:11:42 +0100112static const size_t ZSTD_blockHeaderSize = ZSTD_BLOCKHEADERSIZE;
Yann Colletc991cc12016-07-28 00:55:43 +0200113typedef enum { bt_raw, bt_rle, bt_compressed, bt_reserved } blockType_e;
Yann Collet37f3d1b2016-03-19 15:11:42 +0100114
115#define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */
116#define MIN_CBLOCK_SIZE (1 /*litCSize*/ + 1 /* RLE or RAW */ + MIN_SEQUENCES_SIZE /* nbSeq==0 */) /* for a non-null block */
117
118#define HufLog 12
Yann Colletf8e7b532016-07-23 16:31:49 +0200119typedef enum { set_basic, set_rle, set_compressed, set_repeat } symbolEncodingType_e;
Yann Collet14983e72015-11-11 21:38:21 +0100120
Yann Collet37f3d1b2016-03-19 15:11:42 +0100121#define LONGNBSEQ 0x7F00
122
inikep7bc19b62016-04-06 09:46:01 +0200123#define MINMATCH 3
Yann Collet14983e72015-11-11 21:38:21 +0100124
inikep3bfcfc72016-02-03 18:47:30 +0100125#define Litbits 8
inikep70b05452016-02-03 22:56:55 +0100126#define MaxLit ((1<<Litbits) - 1)
Yann Colletfadda6c2016-03-22 12:14:26 +0100127#define MaxML 52
Yann Colletb0aec172016-03-21 13:24:16 +0100128#define MaxLL 35
Nick Terrellbbe77212017-09-18 16:54:53 -0700129#define DefaultMaxOff 28
130#define MaxOff 31
Yann Collet4db09ef2016-03-18 22:23:49 +0100131#define MaxSeq MAX(MaxLL, MaxML) /* Assumption : MaxOff < MaxLL,MaxML */
Yann Colletbe391432016-03-22 23:19:28 +0100132#define MLFSELog 9
Yann Colletd64f4352016-03-21 00:07:42 +0100133#define LLFSELog 9
Yann Collet646693e2016-03-24 02:31:27 +0100134#define OffFSELog 8
inikepf3c65032016-03-04 20:04:25 +0100135
Yann Colletb0aec172016-03-21 13:24:16 +0100136static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
137 1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
138 13,14,15,16 };
Yann Collet48537162016-04-07 15:24:29 +0200139static const S16 LL_defaultNorm[MaxLL+1] = { 4, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1,
140 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 1, 1, 1, 1, 1,
141 -1,-1,-1,-1 };
Yann Collet51f4d562016-09-22 15:57:28 +0200142#define LL_DEFAULTNORMLOG 6 /* for static allocation */
143static const U32 LL_defaultNormLog = LL_DEFAULTNORMLOG;
Yann Colletb0aec172016-03-21 13:24:16 +0100144
Yann Colletfadda6c2016-03-22 12:14:26 +0100145static const U32 ML_bits[MaxML+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
146 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
147 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 7, 8, 9,10,11,
Yann Collet48537162016-04-07 15:24:29 +0200148 12,13,14,15,16 };
149static const S16 ML_defaultNorm[MaxML+1] = { 1, 4, 3, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
Yann Colletfadda6c2016-03-22 12:14:26 +0100150 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Yann Collet48537162016-04-07 15:24:29 +0200151 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,
152 -1,-1,-1,-1,-1 };
Yann Collet51f4d562016-09-22 15:57:28 +0200153#define ML_DEFAULTNORMLOG 6 /* for static allocation */
154static const U32 ML_defaultNormLog = ML_DEFAULTNORMLOG;
Yann Colletfadda6c2016-03-22 12:14:26 +0100155
Nick Terrellbbe77212017-09-18 16:54:53 -0700156static const S16 OF_defaultNorm[DefaultMaxOff+1] = { 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1,
157 1, 1, 1, 1, 1, 1, 1, 1,-1,-1,-1,-1,-1 };
Yann Collet51f4d562016-09-22 15:57:28 +0200158#define OF_DEFAULTNORMLOG 5 /* for static allocation */
159static const U32 OF_defaultNormLog = OF_DEFAULTNORMLOG;
Yann Collet48537162016-04-07 15:24:29 +0200160
Yann Collet2acb5d32015-10-29 16:49:43 +0100161
Yann Colletfb810d62016-01-28 00:18:06 +0100162/*-*******************************************
Yann Collet14983e72015-11-11 21:38:21 +0100163* Shared functions to include for inlining
Yann Colletfb810d62016-01-28 00:18:06 +0100164*********************************************/
Yann Collet2acb5d32015-10-29 16:49:43 +0100165static void ZSTD_copy8(void* dst, const void* src) { memcpy(dst, src, 8); }
Yann Collet2acb5d32015-10-29 16:49:43 +0100166#define COPY8(d,s) { ZSTD_copy8(d,s); d+=8; s+=8; }
167
Yann Collet953ce722016-02-04 15:28:14 +0100168/*! ZSTD_wildcopy() :
169* custom version of memcpy(), can copy up to 7 bytes too many (8 bytes if length==0) */
Yann Collet37f3d1b2016-03-19 15:11:42 +0100170#define WILDCOPY_OVERLENGTH 8
Nick Terrell064a1432016-12-12 19:01:23 -0800171MEM_STATIC void ZSTD_wildcopy(void* dst, const void* src, ptrdiff_t length)
Yann Collet2acb5d32015-10-29 16:49:43 +0100172{
173 const BYTE* ip = (const BYTE*)src;
174 BYTE* op = (BYTE*)dst;
175 BYTE* const oend = op + length;
Yann Collet50c5cdb2015-11-04 20:35:33 +0100176 do
177 COPY8(op, ip)
178 while (op < oend);
Yann Collet2acb5d32015-10-29 16:49:43 +0100179}
180
Yann Collet280f9a82016-08-08 00:44:00 +0200181MEM_STATIC void ZSTD_wildcopy_e(void* dst, const void* src, void* dstEnd) /* should be faster for decoding, but strangely, not verified on all platform */
182{
183 const BYTE* ip = (const BYTE*)src;
184 BYTE* op = (BYTE*)dst;
185 BYTE* const oend = (BYTE*)dstEnd;
186 do
187 COPY8(op, ip)
188 while (op < oend);
189}
190
Yann Collet7d360282016-02-12 00:07:30 +0100191
192/*-*******************************************
193* Private interfaces
194*********************************************/
inikep35b891c2016-05-20 19:42:20 +0200195typedef struct ZSTD_stats_s ZSTD_stats_t;
196
Yann Colleted57d852016-07-29 21:22:17 +0200197typedef struct seqDef_s {
198 U32 offset;
199 U16 litLength;
200 U16 matchLength;
201} seqDef;
202
Stella Lauf181f332017-08-21 01:59:08 -0700203
inikep87d4f3d2016-03-02 15:56:24 +0100204typedef struct {
Yann Colletc0ce4f12016-07-30 00:55:13 +0200205 seqDef* sequencesStart;
Yann Colleted57d852016-07-29 21:22:17 +0200206 seqDef* sequences;
Yann Collet7d360282016-02-12 00:07:30 +0100207 BYTE* litStart;
208 BYTE* lit;
Yann Colleted57d852016-07-29 21:22:17 +0200209 BYTE* llCode;
210 BYTE* mlCode;
211 BYTE* ofCode;
Yann Collet5d393572016-04-07 17:19:00 +0200212 U32 longLengthID; /* 0 == no longLength; 1 == Lit.longLength; 2 == Match.longLength; */
213 U32 longLengthPos;
Nick Terrelle1982302017-07-17 12:27:24 -0700214 U32 rep[ZSTD_REP_NUM];
215 U32 repToConfirm[ZSTD_REP_NUM];
Nick Terrell7a28b9e2017-07-17 15:29:11 -0700216} seqStore_t;
217
218typedef struct {
219 U32 off;
220 U32 len;
221} ZSTD_match_t;
222
223typedef struct {
224 U32 price;
225 U32 off;
226 U32 mlen;
227 U32 litlen;
228 U32 rep[ZSTD_REP_NUM];
229} ZSTD_optimal_t;
230
231typedef struct {
Yann Collet7d360282016-02-12 00:07:30 +0100232 U32* litFreq;
Nick Terrell7a28b9e2017-07-17 15:29:11 -0700233 U32* litLengthFreq;
234 U32* matchLengthFreq;
Yann Collet7d360282016-02-12 00:07:30 +0100235 U32* offCodeFreq;
Nick Terrell7a28b9e2017-07-17 15:29:11 -0700236 ZSTD_match_t* matchTable;
237 ZSTD_optimal_t* priceTable;
238
Yann Collet7d360282016-02-12 00:07:30 +0100239 U32 matchLengthSum;
inikepe0010e92016-02-23 16:25:04 +0100240 U32 matchSum;
Yann Collet7d360282016-02-12 00:07:30 +0100241 U32 litLengthSum;
242 U32 litSum;
243 U32 offCodeSum;
inikepb5a519f2016-03-09 15:45:01 +0100244 U32 log2matchLengthSum;
245 U32 log2matchSum;
246 U32 log2litLengthSum;
247 U32 log2litSum;
248 U32 log2offCodeSum;
249 U32 factor;
Przemyslaw Skibinski9ca65af2016-11-23 17:22:54 +0100250 U32 staticPrices;
inikepf7d210b2016-04-11 16:35:13 +0200251 U32 cachedPrice;
252 U32 cachedLitLength;
253 const BYTE* cachedLiterals;
Nick Terrell7a28b9e2017-07-17 15:29:11 -0700254} optState_t;
Yann Collet7d360282016-02-12 00:07:30 +0100255
Nick Terrellde0414b2017-07-12 19:08:24 -0700256typedef struct {
Stella Lau6a546ef2017-07-28 15:51:33 -0700257 U32 offset;
258 U32 checksum;
259} ldmEntry_t;
260
261typedef struct {
262 ldmEntry_t* hashTable;
Stella Lau767a0b32017-09-01 12:24:59 -0700263 BYTE* bucketOffsets; /* Next position in bucket to insert entry */
Stella Lau767a0b32017-09-01 12:24:59 -0700264 U64 hashPower; /* Used to compute the rolling hash.
265 * Depends on ldmParams.minMatchLength */
Stella Lau6a546ef2017-07-28 15:51:33 -0700266} ldmState_t;
267
268typedef struct {
Stella Lau767a0b32017-09-01 12:24:59 -0700269 U32 enableLdm; /* 1 if enable long distance matching */
270 U32 hashLog; /* Log size of hashTable */
Stella Lau67d4a612017-09-02 21:10:36 -0700271 U32 bucketSizeLog; /* Log bucket size for collision resolution, at most 8 */
Stella Lau767a0b32017-09-01 12:24:59 -0700272 U32 minMatchLength; /* Minimum match length */
Stella Laua1f04d52017-09-01 14:52:51 -0700273 U32 hashEveryLog; /* Log number of entries to skip */
Stella Lau767a0b32017-09-01 12:24:59 -0700274} ldmParams_t;
275
276typedef struct {
Nick Terrellde0414b2017-07-12 19:08:24 -0700277 U32 hufCTable[HUF_CTABLE_SIZE_U32(255)];
Nick Terrellde0414b2017-07-12 19:08:24 -0700278 FSE_CTable offcodeCTable[FSE_CTABLE_SIZE_U32(OffFSELog, MaxOff)];
279 FSE_CTable matchlengthCTable[FSE_CTABLE_SIZE_U32(MLFSELog, MaxML)];
280 FSE_CTable litlengthCTable[FSE_CTABLE_SIZE_U32(LLFSELog, MaxLL)];
281 U32 workspace[HUF_WORKSPACE_SIZE_U32];
Nick Terrell830ef412017-07-13 12:45:39 -0700282 HUF_repeat hufCTable_repeatMode;
283 FSE_repeat offcode_repeatMode;
284 FSE_repeat matchlength_repeatMode;
285 FSE_repeat litlength_repeatMode;
Nick Terrellde0414b2017-07-12 19:08:24 -0700286} ZSTD_entropyCTables_t;
287
Stella Lau91b30db2017-08-21 10:09:06 -0700288struct ZSTD_CCtx_params_s {
Yann Collet7c3dea42017-09-24 15:57:29 -0700289 ZSTD_format_e format;
Stella Lau91b30db2017-08-21 10:09:06 -0700290 ZSTD_compressionParameters cParams;
291 ZSTD_frameParameters fParams;
292
293 int compressionLevel;
294 U32 forceWindow; /* force back-references to respect limit of
295 * 1<<wLog, even for dictionary */
Stella Lau91b30db2017-08-21 10:09:06 -0700296
Stella Lau2adde892017-08-25 16:13:40 -0700297 /* Multithreading: used to pass parameters to mtctx */
Stella Lau91b30db2017-08-21 10:09:06 -0700298 U32 nbThreads;
299 unsigned jobSize;
300 unsigned overlapSizeLog;
Stella Lau5bc2c1e2017-08-23 12:03:30 -0700301
Stella Lau767a0b32017-09-01 12:24:59 -0700302 /* Long distance matching parameters */
303 ldmParams_t ldmParams;
Stella Lau8081bec2017-08-31 15:40:16 -0700304
Stella Lau5bc2c1e2017-08-23 12:03:30 -0700305 /* For use with createCCtxParams() and freeCCtxParams() only */
306 ZSTD_customMem customMem;
307
Stella Lau91b30db2017-08-21 10:09:06 -0700308}; /* typedef'd to ZSTD_CCtx_params within "zstd.h" */
309
Yann Colletb44be742016-03-26 20:52:14 +0100310const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx);
Yann Colleted57d852016-07-29 21:22:17 +0200311void ZSTD_seqToCodes(const seqStore_t* seqStorePtr);
Yann Collet2acb5d32015-10-29 16:49:43 +0100312
inikepc4807f42016-06-02 15:11:39 +0200313/* custom memory allocation functions */
Yann Collet23b6e052016-08-28 21:05:43 -0700314void* ZSTD_malloc(size_t size, ZSTD_customMem customMem);
Yann Collet44e45e82017-05-30 16:12:06 -0700315void* ZSTD_calloc(size_t size, ZSTD_customMem customMem);
Yann Collet23b6e052016-08-28 21:05:43 -0700316void ZSTD_free(void* ptr, ZSTD_customMem customMem);
317
inikep2a746092016-06-03 14:53:51 +0200318
Yann Colletc154d9d2016-07-27 14:37:00 +0200319/*====== common function ======*/
320
321MEM_STATIC U32 ZSTD_highbit32(U32 val)
322{
Stella Laue50ed1f2017-08-22 11:55:42 -0700323 assert(val != 0);
324 {
Yann Colletc154d9d2016-07-27 14:37:00 +0200325# if defined(_MSC_VER) /* Visual */
Stella Laue50ed1f2017-08-22 11:55:42 -0700326 unsigned long r=0;
327 _BitScanReverse(&r, val);
328 return (unsigned)r;
Yann Colletc154d9d2016-07-27 14:37:00 +0200329# elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */
Stella Laue50ed1f2017-08-22 11:55:42 -0700330 return 31 - __builtin_clz(val);
Yann Colletc154d9d2016-07-27 14:37:00 +0200331# else /* Software version */
Stella Laue50ed1f2017-08-22 11:55:42 -0700332 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 };
333 U32 v = val;
334 int r;
335 v |= v >> 1;
336 v |= v >> 2;
337 v |= v >> 4;
338 v |= v >> 8;
339 v |= v >> 16;
340 r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27];
341 return r;
Yann Colletc154d9d2016-07-27 14:37:00 +0200342# endif
Stella Laue50ed1f2017-08-22 11:55:42 -0700343 }
Yann Colletc154d9d2016-07-27 14:37:00 +0200344}
345
346
Yann Collet32dfae62017-01-19 10:32:55 -0800347/* hidden functions */
348
349/* ZSTD_invalidateRepCodes() :
350 * ensures next compression will not use repcodes from previous block.
351 * Note : only works with regular variant;
352 * do not use with extDict variant ! */
353void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx);
354
355
Stella Lau8fd16362017-08-21 18:10:44 -0700356/*! ZSTD_initCStream_internal() :
Yann Collet8c910d22017-06-03 01:15:02 -0700357 * Private use only. Init streaming operation.
358 * expects params to be valid.
359 * must receive dict, or cdict, or none, but not both.
360 * @return : 0, or an error code */
Stella Lauee657012017-08-29 20:27:35 -0700361size_t ZSTD_initCStream_internal(ZSTD_CStream* zcs,
362 const void* dict, size_t dictSize,
363 const ZSTD_CDict* cdict,
364 ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
Yann Collet8c910d22017-06-03 01:15:02 -0700365
Yann Collet5a773612017-07-03 15:21:24 -0700366/*! ZSTD_compressStream_generic() :
Yann Colletd5c046c2017-06-30 14:51:01 -0700367 * Private use only. To be called from zstdmt_compress.c in single-thread mode. */
368size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
369 ZSTD_outBuffer* output,
370 ZSTD_inBuffer* input,
371 ZSTD_EndDirective const flushMode);
Yann Collet8c910d22017-06-03 01:15:02 -0700372
Stella Lau024098a2017-08-25 17:58:28 -0700373/*! ZSTD_getCParamsFromCDict() :
Yann Collet8c910d22017-06-03 01:15:02 -0700374 * as the name implies */
Stella Lau024098a2017-08-25 17:58:28 -0700375ZSTD_compressionParameters ZSTD_getCParamsFromCDict(const ZSTD_CDict* cdict);
Yann Collet8c910d22017-06-03 01:15:02 -0700376
Stella Lauee657012017-08-29 20:27:35 -0700377/* ZSTD_compressBegin_advanced_internal() :
378 * Private use only. To be called from zstdmt_compress.c. */
Stella Lau23fc0e42017-08-22 14:24:47 -0700379size_t ZSTD_compressBegin_advanced_internal(ZSTD_CCtx* cctx,
Stella Laud7755192017-08-18 17:37:58 -0700380 const void* dict, size_t dictSize,
Stella Lauc7a18b72017-08-29 15:10:42 -0700381 ZSTD_dictMode_e dictMode,
Stella Laud7755192017-08-18 17:37:58 -0700382 ZSTD_CCtx_params params,
383 unsigned long long pledgedSrcSize);
384
Stella Lauee657012017-08-29 20:27:35 -0700385/* ZSTD_compress_advanced_internal() :
386 * Private use only. To be called from zstdmt_compress.c. */
Stella Lau23fc0e42017-08-22 14:24:47 -0700387size_t ZSTD_compress_advanced_internal(ZSTD_CCtx* cctx,
388 void* dst, size_t dstCapacity,
389 const void* src, size_t srcSize,
390 const void* dict,size_t dictSize,
391 ZSTD_CCtx_params params);
Yann Collet8c910d22017-06-03 01:15:02 -0700392
Yann Colletf04deff2017-07-06 01:42:46 -0700393typedef struct {
394 blockType_e blockType;
395 U32 lastBlock;
396 U32 origSize;
397} blockProperties_t;
398
399/*! ZSTD_getcBlockSize() :
400* Provides the size of compressed block from block header `src` */
401size_t ZSTD_getcBlockSize(const void* src, size_t srcSize,
402 blockProperties_t* bpPtr);
403
Nick Terrellde6c6bc2017-08-24 18:09:50 -0700404#if defined (__cplusplus)
405}
406#endif
Yann Colletf04deff2017-07-06 01:42:46 -0700407
Yann Collet2acb5d32015-10-29 16:49:43 +0100408#endif /* ZSTD_CCOMMON_H_MODULE */