xref: /src/sys/contrib/openzfs/module/zstd/lib/compress/zstd_compress_sequences.h (revision 8e28d84935f2f0ee081d44f9803f3052b960e50b)
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0-only
2 /*
3  * Copyright (c) 2016-2020, Yann Collet, Facebook, Inc.
4  * All rights reserved.
5  *
6  * This source code is licensed under both the BSD-style license (found in the
7  * LICENSE file in the root directory of this source tree) and the GPLv2 (found
8  * in the COPYING file in the root directory of this source tree).
9  * You may select, at your option, one of the above-listed licenses.
10  */
11 
12 #ifndef ZSTD_COMPRESS_SEQUENCES_H
13 #define ZSTD_COMPRESS_SEQUENCES_H
14 
15 #include "../common/fse.h" /* FSE_repeat, FSE_CTable */
16 #include "../common/zstd_internal.h" /* symbolEncodingType_e, ZSTD_strategy */
17 
18 typedef enum {
19     ZSTD_defaultDisallowed = 0,
20     ZSTD_defaultAllowed = 1
21 } ZSTD_defaultPolicy_e;
22 
23 symbolEncodingType_e
24 ZSTD_selectEncodingType(
25         FSE_repeat* repeatMode, unsigned const* count, unsigned const max,
26         size_t const mostFrequent, size_t nbSeq, unsigned const FSELog,
27         FSE_CTable const* prevCTable,
28         short const* defaultNorm, U32 defaultNormLog,
29         ZSTD_defaultPolicy_e const isDefaultAllowed,
30         ZSTD_strategy const strategy);
31 
32 size_t
33 ZSTD_buildCTable(void* dst, size_t dstCapacity,
34                 FSE_CTable* nextCTable, U32 FSELog, symbolEncodingType_e type,
35                 unsigned* count, U32 max,
36                 const BYTE* codeTable, size_t nbSeq,
37                 const S16* defaultNorm, U32 defaultNormLog, U32 defaultMax,
38                 const FSE_CTable* prevCTable, size_t prevCTableSize,
39                 void* entropyWorkspace, size_t entropyWorkspaceSize);
40 
41 size_t ZSTD_encodeSequences(
42             void* dst, size_t dstCapacity,
43             FSE_CTable const* CTable_MatchLength, BYTE const* mlCodeTable,
44             FSE_CTable const* CTable_OffsetBits, BYTE const* ofCodeTable,
45             FSE_CTable const* CTable_LitLength, BYTE const* llCodeTable,
46             seqDef const* sequences, size_t nbSeq, int longOffsets, int bmi2);
47 
48 size_t ZSTD_fseBitCost(
49     FSE_CTable const* ctable,
50     unsigned const* count,
51     unsigned const max);
52 
53 size_t ZSTD_crossEntropyCost(short const* norm, unsigned accuracyLog,
54                              unsigned const* count, unsigned const max);
55 #endif /* ZSTD_COMPRESS_SEQUENCES_H */
56