move Sequences definition to zstd_compress_internal.h
they should not be in common/zstd_internal.h, since these definitions are not shared beyond lib/compress/.
This commit is contained in:
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under both the BSD-style license (found in the
|
||||||
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
||||||
|
* in the COPYING file in the root directory of this source tree).
|
||||||
|
* You may select, at your option, one of the above-listed licenses.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ZSTD_ERRORS_H_398273423
|
||||||
|
#define ZSTD_ERRORS_H_398273423
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
|
||||||
|
#ifndef ZSTDERRORLIB_VISIBLE
|
||||||
|
/* Backwards compatibility with old macro name */
|
||||||
|
# ifdef ZSTDERRORLIB_VISIBILITY
|
||||||
|
# define ZSTDERRORLIB_VISIBLE ZSTDERRORLIB_VISIBILITY
|
||||||
|
# elif defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
|
# define ZSTDERRORLIB_VISIBLE __attribute__ ((visibility ("default")))
|
||||||
|
# else
|
||||||
|
# define ZSTDERRORLIB_VISIBLE
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef ZSTDERRORLIB_HIDDEN
|
||||||
|
# if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(__MINGW32__)
|
||||||
|
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
|
||||||
|
# else
|
||||||
|
# define ZSTDERRORLIB_HIDDEN
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
|
||||||
|
# define ZSTDERRORLIB_API __declspec(dllexport) ZSTDERRORLIB_VISIBLE
|
||||||
|
#elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1)
|
||||||
|
# define ZSTDERRORLIB_API __declspec(dllimport) ZSTDERRORLIB_VISIBLE /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||||
|
#else
|
||||||
|
# define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*-*********************************************
|
||||||
|
* Error codes list
|
||||||
|
*-*********************************************
|
||||||
|
* Error codes _values_ are pinned down since v1.3.1 only.
|
||||||
|
* Therefore, don't rely on values if you may link to any version < v1.3.1.
|
||||||
|
*
|
||||||
|
* Only values < 100 are considered stable.
|
||||||
|
*
|
||||||
|
* note 1 : this API shall be used with static linking only.
|
||||||
|
* dynamic linking is not yet officially supported.
|
||||||
|
* note 2 : Prefer relying on the enum than on its value whenever possible
|
||||||
|
* This is the only supported way to use the error list < v1.3.1
|
||||||
|
* note 3 : ZSTD_isError() is always correct, whatever the library version.
|
||||||
|
**********************************************/
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_error_no_error = 0,
|
||||||
|
ZSTD_error_GENERIC = 1,
|
||||||
|
ZSTD_error_prefix_unknown = 10,
|
||||||
|
ZSTD_error_version_unsupported = 12,
|
||||||
|
ZSTD_error_frameParameter_unsupported = 14,
|
||||||
|
ZSTD_error_frameParameter_windowTooLarge = 16,
|
||||||
|
ZSTD_error_corruption_detected = 20,
|
||||||
|
ZSTD_error_checksum_wrong = 22,
|
||||||
|
ZSTD_error_literals_headerWrong = 24,
|
||||||
|
ZSTD_error_dictionary_corrupted = 30,
|
||||||
|
ZSTD_error_dictionary_wrong = 32,
|
||||||
|
ZSTD_error_dictionaryCreation_failed = 34,
|
||||||
|
ZSTD_error_parameter_unsupported = 40,
|
||||||
|
ZSTD_error_parameter_combination_unsupported = 41,
|
||||||
|
ZSTD_error_parameter_outOfBound = 42,
|
||||||
|
ZSTD_error_tableLog_tooLarge = 44,
|
||||||
|
ZSTD_error_maxSymbolValue_tooLarge = 46,
|
||||||
|
ZSTD_error_maxSymbolValue_tooSmall = 48,
|
||||||
|
ZSTD_error_stabilityCondition_notRespected = 50,
|
||||||
|
ZSTD_error_stage_wrong = 60,
|
||||||
|
ZSTD_error_init_missing = 62,
|
||||||
|
ZSTD_error_memory_allocation = 64,
|
||||||
|
ZSTD_error_workSpace_tooSmall= 66,
|
||||||
|
ZSTD_error_dstSize_tooSmall = 70,
|
||||||
|
ZSTD_error_srcSize_wrong = 72,
|
||||||
|
ZSTD_error_dstBuffer_null = 74,
|
||||||
|
ZSTD_error_noForwardProgress_destFull = 80,
|
||||||
|
ZSTD_error_noForwardProgress_inputEmpty = 82,
|
||||||
|
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
|
||||||
|
ZSTD_error_frameIndex_tooLarge = 100,
|
||||||
|
ZSTD_error_seekableIO = 102,
|
||||||
|
ZSTD_error_dstBuffer_wrong = 104,
|
||||||
|
ZSTD_error_srcBuffer_wrong = 105,
|
||||||
|
ZSTD_error_sequenceProducer_failed = 106,
|
||||||
|
ZSTD_error_externalSequences_invalid = 107,
|
||||||
|
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
|
||||||
|
} ZSTD_ErrorCode;
|
||||||
|
|
||||||
|
ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /**< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
|
||||||
|
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZSTD_ERRORS_H_398273423 */
|
||||||
+15
-1
@@ -154,7 +154,7 @@ size_t ZSTD_compressBound(size_t srcSize); </b>/*!< maximum compressed size in w
|
|||||||
it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
it's recommended to provide @dstCapacity >= ZSTD_compressBound(srcSize)
|
||||||
as it eliminates one potential failure scenario,
|
as it eliminates one potential failure scenario,
|
||||||
aka not enough room in dst buffer to write the compressed frame.
|
aka not enough room in dst buffer to write the compressed frame.
|
||||||
Note : ZSTD_compressBound() itself can fail, if @srcSize > ZSTD_MAX_INPUT_SIZE .
|
Note : ZSTD_compressBound() itself can fail, if @srcSize >= ZSTD_MAX_INPUT_SIZE .
|
||||||
In which case, ZSTD_compressBound() will return an error code
|
In which case, ZSTD_compressBound() will return an error code
|
||||||
which can be tested using ZSTD_isError().
|
which can be tested using ZSTD_isError().
|
||||||
|
|
||||||
@@ -1410,6 +1410,20 @@ ZSTD_compressSequences( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
|||||||
|
|
||||||
</p></pre><BR>
|
</p></pre><BR>
|
||||||
|
|
||||||
|
<pre><b>ZSTDLIB_STATIC_API size_t
|
||||||
|
ZSTD_compressSequencesAndLiterals( ZSTD_CCtx* cctx, void* dst, size_t dstSize,
|
||||||
|
const ZSTD_Sequence* inSeqs, size_t inSeqsSize,
|
||||||
|
const void* literals, size_t litSize);
|
||||||
|
</b><p> This is a variant of ZSTD_compressSequences() which,
|
||||||
|
instead of receiving (src,srcSize) as input parameter, receives (literals,litSize),
|
||||||
|
aka all literals already extracted and grouped into a single continuous buffer.
|
||||||
|
This can be useful if the process generating the sequences also happens to generate the buffer of literals,
|
||||||
|
thus skipping an extraction + caching stage.
|
||||||
|
To be valid, `litSize` must be equal to the sum of all @.litLength fields in @inSeqs.
|
||||||
|
@return : final compressed size, or a ZSTD error code.
|
||||||
|
|
||||||
|
</p></pre><BR>
|
||||||
|
|
||||||
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
|
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_writeSkippableFrame(void* dst, size_t dstCapacity,
|
||||||
const void* src, size_t srcSize, unsigned magicVariant);
|
const void* src, size_t srcSize, unsigned magicVariant);
|
||||||
</b><p> Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
|
</b><p> Generates a zstd skippable frame containing data given by src, and writes it to dst buffer.
|
||||||
|
|||||||
@@ -278,62 +278,6 @@ typedef enum {
|
|||||||
/*-*******************************************
|
/*-*******************************************
|
||||||
* Private declarations
|
* Private declarations
|
||||||
*********************************************/
|
*********************************************/
|
||||||
typedef struct seqDef_s {
|
|
||||||
U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
|
||||||
U16 litLength;
|
|
||||||
U16 mlBase; /* mlBase == matchLength - MINMATCH */
|
|
||||||
} seqDef;
|
|
||||||
|
|
||||||
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
|
||||||
typedef enum {
|
|
||||||
ZSTD_llt_none = 0, /* no longLengthType */
|
|
||||||
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
|
||||||
ZSTD_llt_matchLength = 2 /* represents a long match */
|
|
||||||
} ZSTD_longLengthType_e;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
seqDef* sequencesStart;
|
|
||||||
seqDef* sequences; /* ptr to end of sequences */
|
|
||||||
BYTE* litStart;
|
|
||||||
BYTE* lit; /* ptr to end of literals */
|
|
||||||
BYTE* llCode;
|
|
||||||
BYTE* mlCode;
|
|
||||||
BYTE* ofCode;
|
|
||||||
size_t maxNbSeq;
|
|
||||||
size_t maxNbLit;
|
|
||||||
|
|
||||||
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
|
||||||
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
|
||||||
* the existing value of the litLength or matchLength by 0x10000.
|
|
||||||
*/
|
|
||||||
ZSTD_longLengthType_e longLengthType;
|
|
||||||
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
|
||||||
} seqStore_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
U32 litLength;
|
|
||||||
U32 matchLength;
|
|
||||||
} ZSTD_sequenceLength;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
|
||||||
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
|
||||||
*/
|
|
||||||
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
|
||||||
{
|
|
||||||
ZSTD_sequenceLength seqLen;
|
|
||||||
seqLen.litLength = seq->litLength;
|
|
||||||
seqLen.matchLength = seq->mlBase + MINMATCH;
|
|
||||||
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
|
||||||
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
|
||||||
seqLen.litLength += 0x10000;
|
|
||||||
}
|
|
||||||
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
|
||||||
seqLen.matchLength += 0x10000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return seqLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
||||||
@@ -347,10 +291,6 @@ typedef struct {
|
|||||||
unsigned long long decompressedBound;
|
unsigned long long decompressedBound;
|
||||||
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
} ZSTD_frameSizeInfo; /* decompress & legacy */
|
||||||
|
|
||||||
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
|
||||||
int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
|
||||||
|
|
||||||
|
|
||||||
/* ZSTD_invalidateRepCodes() :
|
/* ZSTD_invalidateRepCodes() :
|
||||||
* ensures next compression will not use repcodes from previous block.
|
* ensures next compression will not use repcodes from previous block.
|
||||||
* Note : only works with regular variant;
|
* Note : only works with regular variant;
|
||||||
|
|||||||
@@ -6909,7 +6909,7 @@ ZSTD_compressSequences_internal(ZSTD_CCtx* cctx,
|
|||||||
if (blockSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1+1) {
|
if (blockSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1+1) {
|
||||||
cBlockSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
cBlockSize = ZSTD_noCompressBlock(op, dstCapacity, ip, blockSize, lastBlock);
|
||||||
FORWARD_IF_ERROR(cBlockSize, "Nocompress block failed");
|
FORWARD_IF_ERROR(cBlockSize, "Nocompress block failed");
|
||||||
DEBUGLOG(5, "Block too small, writing out nocompress block: cSize: %zu", cBlockSize);
|
DEBUGLOG(5, "Block too small (%zu): data remains uncompressed: cSize=%zu", blockSize, cBlockSize);
|
||||||
cSize += cBlockSize;
|
cSize += cBlockSize;
|
||||||
ip += blockSize;
|
ip += blockSize;
|
||||||
op += cBlockSize;
|
op += cBlockSize;
|
||||||
|
|||||||
@@ -83,6 +83,70 @@ typedef struct {
|
|||||||
ZSTD_fseCTables_t fse;
|
ZSTD_fseCTables_t fse;
|
||||||
} ZSTD_entropyCTables_t;
|
} ZSTD_entropyCTables_t;
|
||||||
|
|
||||||
|
/***********************************************
|
||||||
|
* Sequences *
|
||||||
|
***********************************************/
|
||||||
|
typedef struct seqDef_s {
|
||||||
|
U32 offBase; /* offBase == Offset + ZSTD_REP_NUM, or repcode 1,2,3 */
|
||||||
|
U16 litLength;
|
||||||
|
U16 mlBase; /* mlBase == matchLength - MINMATCH */
|
||||||
|
} seqDef;
|
||||||
|
|
||||||
|
/* Controls whether seqStore has a single "long" litLength or matchLength. See seqStore_t. */
|
||||||
|
typedef enum {
|
||||||
|
ZSTD_llt_none = 0, /* no longLengthType */
|
||||||
|
ZSTD_llt_literalLength = 1, /* represents a long literal */
|
||||||
|
ZSTD_llt_matchLength = 2 /* represents a long match */
|
||||||
|
} ZSTD_longLengthType_e;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
seqDef* sequencesStart;
|
||||||
|
seqDef* sequences; /* ptr to end of sequences */
|
||||||
|
BYTE* litStart;
|
||||||
|
BYTE* lit; /* ptr to end of literals */
|
||||||
|
BYTE* llCode;
|
||||||
|
BYTE* mlCode;
|
||||||
|
BYTE* ofCode;
|
||||||
|
size_t maxNbSeq;
|
||||||
|
size_t maxNbLit;
|
||||||
|
|
||||||
|
/* longLengthPos and longLengthType to allow us to represent either a single litLength or matchLength
|
||||||
|
* in the seqStore that has a value larger than U16 (if it exists). To do so, we increment
|
||||||
|
* the existing value of the litLength or matchLength by 0x10000.
|
||||||
|
*/
|
||||||
|
ZSTD_longLengthType_e longLengthType;
|
||||||
|
U32 longLengthPos; /* Index of the sequence to apply long length modification to */
|
||||||
|
} seqStore_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
U32 litLength;
|
||||||
|
U32 matchLength;
|
||||||
|
} ZSTD_sequenceLength;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the ZSTD_sequenceLength for the given sequences. It handles the decoding of long sequences
|
||||||
|
* indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength.
|
||||||
|
*/
|
||||||
|
MEM_STATIC ZSTD_sequenceLength ZSTD_getSequenceLength(seqStore_t const* seqStore, seqDef const* seq)
|
||||||
|
{
|
||||||
|
ZSTD_sequenceLength seqLen;
|
||||||
|
seqLen.litLength = seq->litLength;
|
||||||
|
seqLen.matchLength = seq->mlBase + MINMATCH;
|
||||||
|
if (seqStore->longLengthPos == (U32)(seq - seqStore->sequencesStart)) {
|
||||||
|
if (seqStore->longLengthType == ZSTD_llt_literalLength) {
|
||||||
|
seqLen.litLength += 0x10000;
|
||||||
|
}
|
||||||
|
if (seqStore->longLengthType == ZSTD_llt_matchLength) {
|
||||||
|
seqLen.matchLength += 0x10000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return seqLen;
|
||||||
|
}
|
||||||
|
|
||||||
|
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
|
||||||
|
int ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */
|
||||||
|
|
||||||
|
|
||||||
/***********************************************
|
/***********************************************
|
||||||
* Entropy buffer statistics structs and funcs *
|
* Entropy buffer statistics structs and funcs *
|
||||||
***********************************************/
|
***********************************************/
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#ifndef ZSTD_COMPRESS_SEQUENCES_H
|
#ifndef ZSTD_COMPRESS_SEQUENCES_H
|
||||||
#define ZSTD_COMPRESS_SEQUENCES_H
|
#define ZSTD_COMPRESS_SEQUENCES_H
|
||||||
|
|
||||||
|
#include "zstd_compress_internal.h" /* seqDef */
|
||||||
#include "../common/fse.h" /* FSE_repeat, FSE_CTable */
|
#include "../common/fse.h" /* FSE_repeat, FSE_CTable */
|
||||||
#include "../common/zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */
|
#include "../common/zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user