multi_compress 0.3.2 → 0.3.4
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 +4 -4
- data/CHANGELOG.md +17 -3
- data/GET_STARTED.md +3 -3
- data/README.md +75 -66
- data/THIRD_PARTY_NOTICES.md +24 -0
- data/ext/multi_compress/brotli_dec_static_init.c +3 -0
- data/ext/multi_compress/brotli_enc_static_init.c +3 -0
- data/ext/multi_compress/extconf.rb +79 -3
- data/ext/multi_compress/multi_compress.c +199 -120
- data/ext/multi_compress/vendor/.vendored +2 -2
- data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
- data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
- data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
- data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
- data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
- data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
- data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
- data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
- data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
- data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
- data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
- data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
- data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
- data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
- data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
- data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
- data/ext/multi_compress/vendor/zstd/COPYING +339 -0
- data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
- data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
- data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
- data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
- data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
- data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
- data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
- data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
- data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
- data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
- data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
- data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
- data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
- data/lib/multi_compress/version.rb +1 -1
- data/lib/multi_compress.rb +80 -41
- metadata +29 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* ******************************************************************
|
|
2
2
|
* Huffman encoder, part of New Generation Entropy library
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
4
|
*
|
|
5
5
|
* You can contact the author at :
|
|
6
6
|
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
#include "hist.h"
|
|
30
30
|
#define FSE_STATIC_LINKING_ONLY /* FSE_optimalTableLog_internal */
|
|
31
31
|
#include "../common/fse.h" /* header compression */
|
|
32
|
-
#define HUF_STATIC_LINKING_ONLY
|
|
33
32
|
#include "../common/huf.h"
|
|
34
33
|
#include "../common/error_private.h"
|
|
34
|
+
#include "../common/bits.h" /* ZSTD_highbit32 */
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
/* **************************************************************
|
|
@@ -42,13 +42,67 @@
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
/* **************************************************************
|
|
45
|
-
*
|
|
45
|
+
* Required declarations
|
|
46
46
|
****************************************************************/
|
|
47
|
-
|
|
47
|
+
typedef struct nodeElt_s {
|
|
48
|
+
U32 count;
|
|
49
|
+
U16 parent;
|
|
50
|
+
BYTE byte;
|
|
51
|
+
BYTE nbBits;
|
|
52
|
+
} nodeElt;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
/* **************************************************************
|
|
56
|
+
* Debug Traces
|
|
57
|
+
****************************************************************/
|
|
58
|
+
|
|
59
|
+
#if DEBUGLEVEL >= 2
|
|
60
|
+
|
|
61
|
+
static size_t showU32(const U32* arr, size_t size)
|
|
48
62
|
{
|
|
49
|
-
|
|
63
|
+
size_t u;
|
|
64
|
+
for (u=0; u<size; u++) {
|
|
65
|
+
RAWLOG(6, " %u", arr[u]); (void)arr;
|
|
66
|
+
}
|
|
67
|
+
RAWLOG(6, " \n");
|
|
68
|
+
return size;
|
|
50
69
|
}
|
|
51
70
|
|
|
71
|
+
static size_t HUF_getNbBits(HUF_CElt elt);
|
|
72
|
+
|
|
73
|
+
static size_t showCTableBits(const HUF_CElt* ctable, size_t size)
|
|
74
|
+
{
|
|
75
|
+
size_t u;
|
|
76
|
+
for (u=0; u<size; u++) {
|
|
77
|
+
RAWLOG(6, " %zu", HUF_getNbBits(ctable[u])); (void)ctable;
|
|
78
|
+
}
|
|
79
|
+
RAWLOG(6, " \n");
|
|
80
|
+
return size;
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
static size_t showHNodeSymbols(const nodeElt* hnode, size_t size)
|
|
85
|
+
{
|
|
86
|
+
size_t u;
|
|
87
|
+
for (u=0; u<size; u++) {
|
|
88
|
+
RAWLOG(6, " %u", hnode[u].byte); (void)hnode;
|
|
89
|
+
}
|
|
90
|
+
RAWLOG(6, " \n");
|
|
91
|
+
return size;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static size_t showHNodeBits(const nodeElt* hnode, size_t size)
|
|
95
|
+
{
|
|
96
|
+
size_t u;
|
|
97
|
+
for (u=0; u<size; u++) {
|
|
98
|
+
RAWLOG(6, " %u", hnode[u].nbBits); (void)hnode;
|
|
99
|
+
}
|
|
100
|
+
RAWLOG(6, " \n");
|
|
101
|
+
return size;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#endif
|
|
105
|
+
|
|
52
106
|
|
|
53
107
|
/* *******************************************************
|
|
54
108
|
* HUF : Huffman block compression
|
|
@@ -89,7 +143,10 @@ typedef struct {
|
|
|
89
143
|
S16 norm[HUF_TABLELOG_MAX+1];
|
|
90
144
|
} HUF_CompressWeightsWksp;
|
|
91
145
|
|
|
92
|
-
static size_t
|
|
146
|
+
static size_t
|
|
147
|
+
HUF_compressWeights(void* dst, size_t dstSize,
|
|
148
|
+
const void* weightTable, size_t wtSize,
|
|
149
|
+
void* workspace, size_t workspaceSize)
|
|
93
150
|
{
|
|
94
151
|
BYTE* const ostart = (BYTE*) dst;
|
|
95
152
|
BYTE* op = ostart;
|
|
@@ -140,7 +197,7 @@ static size_t HUF_getNbBitsFast(HUF_CElt elt)
|
|
|
140
197
|
|
|
141
198
|
static size_t HUF_getValue(HUF_CElt elt)
|
|
142
199
|
{
|
|
143
|
-
return elt & ~0xFF;
|
|
200
|
+
return elt & ~(size_t)0xFF;
|
|
144
201
|
}
|
|
145
202
|
|
|
146
203
|
static size_t HUF_getValueFast(HUF_CElt elt)
|
|
@@ -163,6 +220,25 @@ static void HUF_setValue(HUF_CElt* elt, size_t value)
|
|
|
163
220
|
}
|
|
164
221
|
}
|
|
165
222
|
|
|
223
|
+
HUF_CTableHeader HUF_readCTableHeader(HUF_CElt const* ctable)
|
|
224
|
+
{
|
|
225
|
+
HUF_CTableHeader header;
|
|
226
|
+
ZSTD_memcpy(&header, ctable, sizeof(header));
|
|
227
|
+
return header;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
static void HUF_writeCTableHeader(HUF_CElt* ctable, U32 tableLog, U32 maxSymbolValue)
|
|
231
|
+
{
|
|
232
|
+
HUF_CTableHeader header;
|
|
233
|
+
HUF_STATIC_ASSERT(sizeof(ctable[0]) == sizeof(header));
|
|
234
|
+
ZSTD_memset(&header, 0, sizeof(header));
|
|
235
|
+
assert(tableLog < 256);
|
|
236
|
+
header.tableLog = (BYTE)tableLog;
|
|
237
|
+
assert(maxSymbolValue < 256);
|
|
238
|
+
header.maxSymbolValue = (BYTE)maxSymbolValue;
|
|
239
|
+
ZSTD_memcpy(ctable, &header, sizeof(header));
|
|
240
|
+
}
|
|
241
|
+
|
|
166
242
|
typedef struct {
|
|
167
243
|
HUF_CompressWeightsWksp wksp;
|
|
168
244
|
BYTE bitsToWeight[HUF_TABLELOG_MAX + 1]; /* precomputed conversion table */
|
|
@@ -178,6 +254,11 @@ size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize,
|
|
|
178
254
|
U32 n;
|
|
179
255
|
HUF_WriteCTableWksp* wksp = (HUF_WriteCTableWksp*)HUF_alignUpWorkspace(workspace, &workspaceSize, ZSTD_ALIGNOF(U32));
|
|
180
256
|
|
|
257
|
+
HUF_STATIC_ASSERT(HUF_CTABLE_WORKSPACE_SIZE >= sizeof(HUF_WriteCTableWksp));
|
|
258
|
+
|
|
259
|
+
assert(HUF_readCTableHeader(CTable).maxSymbolValue == maxSymbolValue);
|
|
260
|
+
assert(HUF_readCTableHeader(CTable).tableLog == huffLog);
|
|
261
|
+
|
|
181
262
|
/* check conditions */
|
|
182
263
|
if (workspaceSize < sizeof(HUF_WriteCTableWksp)) return ERROR(GENERIC);
|
|
183
264
|
if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(maxSymbolValue_tooLarge);
|
|
@@ -207,16 +288,6 @@ size_t HUF_writeCTable_wksp(void* dst, size_t maxDstSize,
|
|
|
207
288
|
return ((maxSymbolValue+1)/2) + 1;
|
|
208
289
|
}
|
|
209
290
|
|
|
210
|
-
/*! HUF_writeCTable() :
|
|
211
|
-
`CTable` : Huffman tree to save, using huf representation.
|
|
212
|
-
@return : size of saved CTable */
|
|
213
|
-
size_t HUF_writeCTable (void* dst, size_t maxDstSize,
|
|
214
|
-
const HUF_CElt* CTable, unsigned maxSymbolValue, unsigned huffLog)
|
|
215
|
-
{
|
|
216
|
-
HUF_WriteCTableWksp wksp;
|
|
217
|
-
return HUF_writeCTable_wksp(dst, maxDstSize, CTable, maxSymbolValue, huffLog, &wksp, sizeof(wksp));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
291
|
|
|
221
292
|
size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void* src, size_t srcSize, unsigned* hasZeroWeights)
|
|
222
293
|
{
|
|
@@ -234,7 +305,9 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
|
|
|
234
305
|
if (tableLog > HUF_TABLELOG_MAX) return ERROR(tableLog_tooLarge);
|
|
235
306
|
if (nbSymbols > *maxSymbolValuePtr+1) return ERROR(maxSymbolValue_tooSmall);
|
|
236
307
|
|
|
237
|
-
|
|
308
|
+
*maxSymbolValuePtr = nbSymbols - 1;
|
|
309
|
+
|
|
310
|
+
HUF_writeCTableHeader(CTable, tableLog, *maxSymbolValuePtr);
|
|
238
311
|
|
|
239
312
|
/* Prepare base value per rank */
|
|
240
313
|
{ U32 n, nextRankStart = 0;
|
|
@@ -266,74 +339,71 @@ size_t HUF_readCTable (HUF_CElt* CTable, unsigned* maxSymbolValuePtr, const void
|
|
|
266
339
|
{ U32 n; for (n=0; n<nbSymbols; n++) HUF_setValue(ct + n, valPerRank[HUF_getNbBits(ct[n])]++); }
|
|
267
340
|
}
|
|
268
341
|
|
|
269
|
-
*maxSymbolValuePtr = nbSymbols - 1;
|
|
270
342
|
return readSize;
|
|
271
343
|
}
|
|
272
344
|
|
|
273
345
|
U32 HUF_getNbBitsFromCTable(HUF_CElt const* CTable, U32 symbolValue)
|
|
274
346
|
{
|
|
275
|
-
const HUF_CElt* ct = CTable + 1;
|
|
347
|
+
const HUF_CElt* const ct = CTable + 1;
|
|
276
348
|
assert(symbolValue <= HUF_SYMBOLVALUE_MAX);
|
|
349
|
+
if (symbolValue > HUF_readCTableHeader(CTable).maxSymbolValue)
|
|
350
|
+
return 0;
|
|
277
351
|
return (U32)HUF_getNbBits(ct[symbolValue]);
|
|
278
352
|
}
|
|
279
353
|
|
|
280
354
|
|
|
281
|
-
typedef struct nodeElt_s {
|
|
282
|
-
U32 count;
|
|
283
|
-
U16 parent;
|
|
284
|
-
BYTE byte;
|
|
285
|
-
BYTE nbBits;
|
|
286
|
-
} nodeElt;
|
|
287
|
-
|
|
288
355
|
/**
|
|
289
356
|
* HUF_setMaxHeight():
|
|
290
|
-
*
|
|
357
|
+
* Try to enforce @targetNbBits on the Huffman tree described in @huffNode.
|
|
291
358
|
*
|
|
292
|
-
* It
|
|
293
|
-
*
|
|
359
|
+
* It attempts to convert all nodes with nbBits > @targetNbBits
|
|
360
|
+
* to employ @targetNbBits instead. Then it adjusts the tree
|
|
361
|
+
* so that it remains a valid canonical Huffman tree.
|
|
294
362
|
*
|
|
295
363
|
* @pre The sum of the ranks of each symbol == 2^largestBits,
|
|
296
364
|
* where largestBits == huffNode[lastNonNull].nbBits.
|
|
297
365
|
* @post The sum of the ranks of each symbol == 2^largestBits,
|
|
298
|
-
* where largestBits is the return value <=
|
|
366
|
+
* where largestBits is the return value (expected <= targetNbBits).
|
|
299
367
|
*
|
|
300
|
-
* @param huffNode The Huffman tree modified in place to enforce
|
|
368
|
+
* @param huffNode The Huffman tree modified in place to enforce targetNbBits.
|
|
369
|
+
* It's presumed sorted, from most frequent to rarest symbol.
|
|
301
370
|
* @param lastNonNull The symbol with the lowest count in the Huffman tree.
|
|
302
|
-
* @param
|
|
371
|
+
* @param targetNbBits The allowed number of bits, which the Huffman tree
|
|
303
372
|
* may not respect. After this function the Huffman tree will
|
|
304
|
-
* respect
|
|
305
|
-
* @return The maximum number of bits of the Huffman tree after adjustment
|
|
306
|
-
* necessarily no more than maxNbBits.
|
|
373
|
+
* respect targetNbBits.
|
|
374
|
+
* @return The maximum number of bits of the Huffman tree after adjustment.
|
|
307
375
|
*/
|
|
308
|
-
static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32
|
|
376
|
+
static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 targetNbBits)
|
|
309
377
|
{
|
|
310
378
|
const U32 largestBits = huffNode[lastNonNull].nbBits;
|
|
311
|
-
/* early exit : no elt >
|
|
312
|
-
if (largestBits <=
|
|
379
|
+
/* early exit : no elt > targetNbBits, so the tree is already valid. */
|
|
380
|
+
if (largestBits <= targetNbBits) return largestBits;
|
|
381
|
+
|
|
382
|
+
DEBUGLOG(5, "HUF_setMaxHeight (targetNbBits = %u)", targetNbBits);
|
|
313
383
|
|
|
314
384
|
/* there are several too large elements (at least >= 2) */
|
|
315
385
|
{ int totalCost = 0;
|
|
316
|
-
const U32 baseCost = 1 << (largestBits -
|
|
386
|
+
const U32 baseCost = 1 << (largestBits - targetNbBits);
|
|
317
387
|
int n = (int)lastNonNull;
|
|
318
388
|
|
|
319
|
-
/* Adjust any ranks >
|
|
389
|
+
/* Adjust any ranks > targetNbBits to targetNbBits.
|
|
320
390
|
* Compute totalCost, which is how far the sum of the ranks is
|
|
321
391
|
* we are over 2^largestBits after adjust the offending ranks.
|
|
322
392
|
*/
|
|
323
|
-
while (huffNode[n].nbBits >
|
|
393
|
+
while (huffNode[n].nbBits > targetNbBits) {
|
|
324
394
|
totalCost += baseCost - (1 << (largestBits - huffNode[n].nbBits));
|
|
325
|
-
huffNode[n].nbBits = (BYTE)
|
|
395
|
+
huffNode[n].nbBits = (BYTE)targetNbBits;
|
|
326
396
|
n--;
|
|
327
397
|
}
|
|
328
|
-
/* n stops at huffNode[n].nbBits <=
|
|
329
|
-
assert(huffNode[n].nbBits <=
|
|
330
|
-
/* n end at index of smallest symbol using <
|
|
331
|
-
while (huffNode[n].nbBits ==
|
|
398
|
+
/* n stops at huffNode[n].nbBits <= targetNbBits */
|
|
399
|
+
assert(huffNode[n].nbBits <= targetNbBits);
|
|
400
|
+
/* n end at index of smallest symbol using < targetNbBits */
|
|
401
|
+
while (huffNode[n].nbBits == targetNbBits) --n;
|
|
332
402
|
|
|
333
|
-
/* renorm totalCost from 2^largestBits to 2^
|
|
403
|
+
/* renorm totalCost from 2^largestBits to 2^targetNbBits
|
|
334
404
|
* note : totalCost is necessarily a multiple of baseCost */
|
|
335
|
-
assert((totalCost & (baseCost - 1)) == 0);
|
|
336
|
-
totalCost >>= (largestBits -
|
|
405
|
+
assert(((U32)totalCost & (baseCost - 1)) == 0);
|
|
406
|
+
totalCost >>= (largestBits - targetNbBits);
|
|
337
407
|
assert(totalCost > 0);
|
|
338
408
|
|
|
339
409
|
/* repay normalized cost */
|
|
@@ -342,19 +412,19 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|
|
342
412
|
|
|
343
413
|
/* Get pos of last (smallest = lowest cum. count) symbol per rank */
|
|
344
414
|
ZSTD_memset(rankLast, 0xF0, sizeof(rankLast));
|
|
345
|
-
{ U32 currentNbBits =
|
|
415
|
+
{ U32 currentNbBits = targetNbBits;
|
|
346
416
|
int pos;
|
|
347
417
|
for (pos=n ; pos >= 0; pos--) {
|
|
348
418
|
if (huffNode[pos].nbBits >= currentNbBits) continue;
|
|
349
|
-
currentNbBits = huffNode[pos].nbBits; /* <
|
|
350
|
-
rankLast[
|
|
419
|
+
currentNbBits = huffNode[pos].nbBits; /* < targetNbBits */
|
|
420
|
+
rankLast[targetNbBits-currentNbBits] = (U32)pos;
|
|
351
421
|
} }
|
|
352
422
|
|
|
353
423
|
while (totalCost > 0) {
|
|
354
424
|
/* Try to reduce the next power of 2 above totalCost because we
|
|
355
425
|
* gain back half the rank.
|
|
356
426
|
*/
|
|
357
|
-
U32 nBitsToDecrease =
|
|
427
|
+
U32 nBitsToDecrease = ZSTD_highbit32((U32)totalCost) + 1;
|
|
358
428
|
for ( ; nBitsToDecrease > 1; nBitsToDecrease--) {
|
|
359
429
|
U32 const highPos = rankLast[nBitsToDecrease];
|
|
360
430
|
U32 const lowPos = rankLast[nBitsToDecrease-1];
|
|
@@ -394,7 +464,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|
|
394
464
|
rankLast[nBitsToDecrease] = noSymbol;
|
|
395
465
|
else {
|
|
396
466
|
rankLast[nBitsToDecrease]--;
|
|
397
|
-
if (huffNode[rankLast[nBitsToDecrease]].nbBits !=
|
|
467
|
+
if (huffNode[rankLast[nBitsToDecrease]].nbBits != targetNbBits-nBitsToDecrease)
|
|
398
468
|
rankLast[nBitsToDecrease] = noSymbol; /* this rank is now empty */
|
|
399
469
|
}
|
|
400
470
|
} /* while (totalCost > 0) */
|
|
@@ -406,11 +476,11 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|
|
406
476
|
* TODO.
|
|
407
477
|
*/
|
|
408
478
|
while (totalCost < 0) { /* Sometimes, cost correction overshoot */
|
|
409
|
-
/* special case : no rank 1 symbol (using
|
|
410
|
-
* let's create one from largest rank 0 (using
|
|
479
|
+
/* special case : no rank 1 symbol (using targetNbBits-1);
|
|
480
|
+
* let's create one from largest rank 0 (using targetNbBits).
|
|
411
481
|
*/
|
|
412
482
|
if (rankLast[1] == noSymbol) {
|
|
413
|
-
while (huffNode[n].nbBits ==
|
|
483
|
+
while (huffNode[n].nbBits == targetNbBits) n--;
|
|
414
484
|
huffNode[n+1].nbBits--;
|
|
415
485
|
assert(n >= 0);
|
|
416
486
|
rankLast[1] = (U32)(n+1);
|
|
@@ -424,7 +494,7 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
|
|
|
424
494
|
} /* repay normalized cost */
|
|
425
495
|
} /* there are several too large elements (at least >= 2) */
|
|
426
496
|
|
|
427
|
-
return
|
|
497
|
+
return targetNbBits;
|
|
428
498
|
}
|
|
429
499
|
|
|
430
500
|
typedef struct {
|
|
@@ -432,7 +502,7 @@ typedef struct {
|
|
|
432
502
|
U16 curr;
|
|
433
503
|
} rankPos;
|
|
434
504
|
|
|
435
|
-
typedef nodeElt huffNodeTable[
|
|
505
|
+
typedef nodeElt huffNodeTable[2 * (HUF_SYMBOLVALUE_MAX + 1)];
|
|
436
506
|
|
|
437
507
|
/* Number of buckets available for HUF_sort() */
|
|
438
508
|
#define RANK_POSITION_TABLE_SIZE 192
|
|
@@ -451,8 +521,8 @@ typedef struct {
|
|
|
451
521
|
* Let buckets 166 to 192 represent all remaining counts up to RANK_POSITION_MAX_COUNT_LOG using log2 bucketing.
|
|
452
522
|
*/
|
|
453
523
|
#define RANK_POSITION_MAX_COUNT_LOG 32
|
|
454
|
-
#define RANK_POSITION_LOG_BUCKETS_BEGIN (RANK_POSITION_TABLE_SIZE - 1) - RANK_POSITION_MAX_COUNT_LOG - 1 /* == 158 */
|
|
455
|
-
#define RANK_POSITION_DISTINCT_COUNT_CUTOFF RANK_POSITION_LOG_BUCKETS_BEGIN +
|
|
524
|
+
#define RANK_POSITION_LOG_BUCKETS_BEGIN ((RANK_POSITION_TABLE_SIZE - 1) - RANK_POSITION_MAX_COUNT_LOG - 1 /* == 158 */)
|
|
525
|
+
#define RANK_POSITION_DISTINCT_COUNT_CUTOFF (RANK_POSITION_LOG_BUCKETS_BEGIN + ZSTD_highbit32(RANK_POSITION_LOG_BUCKETS_BEGIN) /* == 166 */)
|
|
456
526
|
|
|
457
527
|
/* Return the appropriate bucket index for a given count. See definition of
|
|
458
528
|
* RANK_POSITION_DISTINCT_COUNT_CUTOFF for explanation of bucketing strategy.
|
|
@@ -460,7 +530,7 @@ typedef struct {
|
|
|
460
530
|
static U32 HUF_getIndex(U32 const count) {
|
|
461
531
|
return (count < RANK_POSITION_DISTINCT_COUNT_CUTOFF)
|
|
462
532
|
? count
|
|
463
|
-
:
|
|
533
|
+
: ZSTD_highbit32(count) + RANK_POSITION_LOG_BUCKETS_BEGIN;
|
|
464
534
|
}
|
|
465
535
|
|
|
466
536
|
/* Helper swap function for HUF_quickSortPartition() */
|
|
@@ -583,7 +653,7 @@ static void HUF_sort(nodeElt huffNode[], const unsigned count[], U32 const maxSy
|
|
|
583
653
|
|
|
584
654
|
/* Sort each bucket. */
|
|
585
655
|
for (n = RANK_POSITION_DISTINCT_COUNT_CUTOFF; n < RANK_POSITION_TABLE_SIZE - 1; ++n) {
|
|
586
|
-
|
|
656
|
+
int const bucketSize = rankPosition[n].curr - rankPosition[n].base;
|
|
587
657
|
U32 const bucketStartIdx = rankPosition[n].base;
|
|
588
658
|
if (bucketSize > 1) {
|
|
589
659
|
assert(bucketStartIdx < maxSymbolValue1);
|
|
@@ -594,6 +664,7 @@ static void HUF_sort(nodeElt huffNode[], const unsigned count[], U32 const maxSy
|
|
|
594
664
|
assert(HUF_isSorted(huffNode, maxSymbolValue1));
|
|
595
665
|
}
|
|
596
666
|
|
|
667
|
+
|
|
597
668
|
/** HUF_buildCTable_wksp() :
|
|
598
669
|
* Same as HUF_buildCTable(), but using externally allocated scratch buffer.
|
|
599
670
|
* `workSpace` must be aligned on 4-bytes boundaries, and be at least as large as sizeof(HUF_buildCTable_wksp_tables).
|
|
@@ -614,6 +685,7 @@ static int HUF_buildTree(nodeElt* huffNode, U32 maxSymbolValue)
|
|
|
614
685
|
int lowS, lowN;
|
|
615
686
|
int nodeNb = STARTNODE;
|
|
616
687
|
int n, nodeRoot;
|
|
688
|
+
DEBUGLOG(5, "HUF_buildTree (alphabet size = %u)", maxSymbolValue + 1);
|
|
617
689
|
/* init for parents */
|
|
618
690
|
nonNullRank = (int)maxSymbolValue;
|
|
619
691
|
while(huffNode[nonNullRank].count == 0) nonNullRank--;
|
|
@@ -640,6 +712,8 @@ static int HUF_buildTree(nodeElt* huffNode, U32 maxSymbolValue)
|
|
|
640
712
|
for (n=0; n<=nonNullRank; n++)
|
|
641
713
|
huffNode[n].nbBits = huffNode[ huffNode[n].parent ].nbBits + 1;
|
|
642
714
|
|
|
715
|
+
DEBUGLOG(6, "Initial distribution of bits completed (%zu sorted symbols)", showHNodeBits(huffNode, maxSymbolValue+1));
|
|
716
|
+
|
|
643
717
|
return nonNullRank;
|
|
644
718
|
}
|
|
645
719
|
|
|
@@ -674,31 +748,40 @@ static void HUF_buildCTableFromTree(HUF_CElt* CTable, nodeElt const* huffNode, i
|
|
|
674
748
|
HUF_setNbBits(ct + huffNode[n].byte, huffNode[n].nbBits); /* push nbBits per symbol, symbol order */
|
|
675
749
|
for (n=0; n<alphabetSize; n++)
|
|
676
750
|
HUF_setValue(ct + n, valPerRank[HUF_getNbBits(ct[n])]++); /* assign value within rank, symbol order */
|
|
677
|
-
|
|
751
|
+
|
|
752
|
+
HUF_writeCTableHeader(CTable, maxNbBits, maxSymbolValue);
|
|
678
753
|
}
|
|
679
754
|
|
|
680
|
-
size_t
|
|
755
|
+
size_t
|
|
756
|
+
HUF_buildCTable_wksp(HUF_CElt* CTable, const unsigned* count, U32 maxSymbolValue, U32 maxNbBits,
|
|
757
|
+
void* workSpace, size_t wkspSize)
|
|
681
758
|
{
|
|
682
|
-
HUF_buildCTable_wksp_tables* const wksp_tables =
|
|
759
|
+
HUF_buildCTable_wksp_tables* const wksp_tables =
|
|
760
|
+
(HUF_buildCTable_wksp_tables*)HUF_alignUpWorkspace(workSpace, &wkspSize, ZSTD_ALIGNOF(U32));
|
|
683
761
|
nodeElt* const huffNode0 = wksp_tables->huffNodeTbl;
|
|
684
762
|
nodeElt* const huffNode = huffNode0+1;
|
|
685
763
|
int nonNullRank;
|
|
686
764
|
|
|
765
|
+
HUF_STATIC_ASSERT(HUF_CTABLE_WORKSPACE_SIZE == sizeof(HUF_buildCTable_wksp_tables));
|
|
766
|
+
|
|
767
|
+
DEBUGLOG(5, "HUF_buildCTable_wksp (alphabet size = %u)", maxSymbolValue+1);
|
|
768
|
+
|
|
687
769
|
/* safety checks */
|
|
688
770
|
if (wkspSize < sizeof(HUF_buildCTable_wksp_tables))
|
|
689
|
-
|
|
771
|
+
return ERROR(workSpace_tooSmall);
|
|
690
772
|
if (maxNbBits == 0) maxNbBits = HUF_TABLELOG_DEFAULT;
|
|
691
773
|
if (maxSymbolValue > HUF_SYMBOLVALUE_MAX)
|
|
692
|
-
|
|
774
|
+
return ERROR(maxSymbolValue_tooLarge);
|
|
693
775
|
ZSTD_memset(huffNode0, 0, sizeof(huffNodeTable));
|
|
694
776
|
|
|
695
777
|
/* sort, decreasing order */
|
|
696
778
|
HUF_sort(huffNode, count, maxSymbolValue, wksp_tables->rankPosition);
|
|
779
|
+
DEBUGLOG(6, "sorted symbols completed (%zu symbols)", showHNodeSymbols(huffNode, maxSymbolValue+1));
|
|
697
780
|
|
|
698
781
|
/* build tree */
|
|
699
782
|
nonNullRank = HUF_buildTree(huffNode, maxSymbolValue);
|
|
700
783
|
|
|
701
|
-
/* enforce maxTableLog */
|
|
784
|
+
/* determine and enforce maxTableLog */
|
|
702
785
|
maxNbBits = HUF_setMaxHeight(huffNode, (U32)nonNullRank, maxNbBits);
|
|
703
786
|
if (maxNbBits > HUF_TABLELOG_MAX) return ERROR(GENERIC); /* check fit into table */
|
|
704
787
|
|
|
@@ -719,13 +802,20 @@ size_t HUF_estimateCompressedSize(const HUF_CElt* CTable, const unsigned* count,
|
|
|
719
802
|
}
|
|
720
803
|
|
|
721
804
|
int HUF_validateCTable(const HUF_CElt* CTable, const unsigned* count, unsigned maxSymbolValue) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
805
|
+
HUF_CTableHeader header = HUF_readCTableHeader(CTable);
|
|
806
|
+
HUF_CElt const* ct = CTable + 1;
|
|
807
|
+
int bad = 0;
|
|
808
|
+
int s;
|
|
809
|
+
|
|
810
|
+
assert(header.tableLog <= HUF_TABLELOG_ABSOLUTEMAX);
|
|
811
|
+
|
|
812
|
+
if (header.maxSymbolValue < maxSymbolValue)
|
|
813
|
+
return 0;
|
|
814
|
+
|
|
815
|
+
for (s = 0; s <= (int)maxSymbolValue; ++s) {
|
|
816
|
+
bad |= (count[s] != 0) & (HUF_getNbBits(ct[s]) == 0);
|
|
817
|
+
}
|
|
818
|
+
return !bad;
|
|
729
819
|
}
|
|
730
820
|
|
|
731
821
|
size_t HUF_compressBound(size_t size) { return HUF_COMPRESSBOUND(size); }
|
|
@@ -807,7 +897,7 @@ FORCE_INLINE_TEMPLATE void HUF_addBits(HUF_CStream_t* bitC, HUF_CElt elt, int id
|
|
|
807
897
|
#if DEBUGLEVEL >= 1
|
|
808
898
|
{
|
|
809
899
|
size_t const nbBits = HUF_getNbBits(elt);
|
|
810
|
-
size_t const dirtyBits = nbBits == 0 ? 0 :
|
|
900
|
+
size_t const dirtyBits = nbBits == 0 ? 0 : ZSTD_highbit32((U32)nbBits) + 1;
|
|
811
901
|
(void)dirtyBits;
|
|
812
902
|
/* Middle bits are 0. */
|
|
813
903
|
assert(((elt >> dirtyBits) << (dirtyBits + nbBits)) == 0);
|
|
@@ -887,7 +977,7 @@ static size_t HUF_closeCStream(HUF_CStream_t* bitC)
|
|
|
887
977
|
{
|
|
888
978
|
size_t const nbBits = bitC->bitPos[0] & 0xFF;
|
|
889
979
|
if (bitC->ptr >= bitC->endPtr) return 0; /* overflow detected */
|
|
890
|
-
return (bitC->ptr - bitC->startPtr) + (nbBits > 0);
|
|
980
|
+
return (size_t)(bitC->ptr - bitC->startPtr) + (nbBits > 0);
|
|
891
981
|
}
|
|
892
982
|
}
|
|
893
983
|
|
|
@@ -967,17 +1057,17 @@ HUF_compress1X_usingCTable_internal_body(void* dst, size_t dstSize,
|
|
|
967
1057
|
const void* src, size_t srcSize,
|
|
968
1058
|
const HUF_CElt* CTable)
|
|
969
1059
|
{
|
|
970
|
-
U32 const tableLog = (
|
|
1060
|
+
U32 const tableLog = HUF_readCTableHeader(CTable).tableLog;
|
|
971
1061
|
HUF_CElt const* ct = CTable + 1;
|
|
972
1062
|
const BYTE* ip = (const BYTE*) src;
|
|
973
1063
|
BYTE* const ostart = (BYTE*)dst;
|
|
974
1064
|
BYTE* const oend = ostart + dstSize;
|
|
975
|
-
BYTE* op = ostart;
|
|
976
1065
|
HUF_CStream_t bitC;
|
|
977
1066
|
|
|
978
1067
|
/* init */
|
|
979
1068
|
if (dstSize < 8) return 0; /* not enough space to compress */
|
|
980
|
-
{
|
|
1069
|
+
{ BYTE* op = ostart;
|
|
1070
|
+
size_t const initErr = HUF_initCStream(&bitC, op, (size_t)(oend-op));
|
|
981
1071
|
if (HUF_isError(initErr)) return 0; }
|
|
982
1072
|
|
|
983
1073
|
if (dstSize < HUF_tightCompressBound(srcSize, (size_t)tableLog) || tableLog > 11)
|
|
@@ -1048,9 +1138,9 @@ HUF_compress1X_usingCTable_internal_default(void* dst, size_t dstSize,
|
|
|
1048
1138
|
static size_t
|
|
1049
1139
|
HUF_compress1X_usingCTable_internal(void* dst, size_t dstSize,
|
|
1050
1140
|
const void* src, size_t srcSize,
|
|
1051
|
-
const HUF_CElt* CTable, const int
|
|
1141
|
+
const HUF_CElt* CTable, const int flags)
|
|
1052
1142
|
{
|
|
1053
|
-
if (
|
|
1143
|
+
if (flags & HUF_flags_bmi2) {
|
|
1054
1144
|
return HUF_compress1X_usingCTable_internal_bmi2(dst, dstSize, src, srcSize, CTable);
|
|
1055
1145
|
}
|
|
1056
1146
|
return HUF_compress1X_usingCTable_internal_default(dst, dstSize, src, srcSize, CTable);
|
|
@@ -1061,28 +1151,23 @@ HUF_compress1X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1061
1151
|
static size_t
|
|
1062
1152
|
HUF_compress1X_usingCTable_internal(void* dst, size_t dstSize,
|
|
1063
1153
|
const void* src, size_t srcSize,
|
|
1064
|
-
const HUF_CElt* CTable, const int
|
|
1154
|
+
const HUF_CElt* CTable, const int flags)
|
|
1065
1155
|
{
|
|
1066
|
-
(void)
|
|
1156
|
+
(void)flags;
|
|
1067
1157
|
return HUF_compress1X_usingCTable_internal_body(dst, dstSize, src, srcSize, CTable);
|
|
1068
1158
|
}
|
|
1069
1159
|
|
|
1070
1160
|
#endif
|
|
1071
1161
|
|
|
1072
|
-
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable)
|
|
1162
|
+
size_t HUF_compress1X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags)
|
|
1073
1163
|
{
|
|
1074
|
-
return
|
|
1075
|
-
}
|
|
1076
|
-
|
|
1077
|
-
size_t HUF_compress1X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2)
|
|
1078
|
-
{
|
|
1079
|
-
return HUF_compress1X_usingCTable_internal(dst, dstSize, src, srcSize, CTable, bmi2);
|
|
1164
|
+
return HUF_compress1X_usingCTable_internal(dst, dstSize, src, srcSize, CTable, flags);
|
|
1080
1165
|
}
|
|
1081
1166
|
|
|
1082
1167
|
static size_t
|
|
1083
1168
|
HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
1084
1169
|
const void* src, size_t srcSize,
|
|
1085
|
-
const HUF_CElt* CTable, int
|
|
1170
|
+
const HUF_CElt* CTable, int flags)
|
|
1086
1171
|
{
|
|
1087
1172
|
size_t const segmentSize = (srcSize+3)/4; /* first 3 segments */
|
|
1088
1173
|
const BYTE* ip = (const BYTE*) src;
|
|
@@ -1096,7 +1181,7 @@ HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1096
1181
|
op += 6; /* jumpTable */
|
|
1097
1182
|
|
|
1098
1183
|
assert(op <= oend);
|
|
1099
|
-
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable,
|
|
1184
|
+
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable, flags) );
|
|
1100
1185
|
if (cSize == 0 || cSize > 65535) return 0;
|
|
1101
1186
|
MEM_writeLE16(ostart, (U16)cSize);
|
|
1102
1187
|
op += cSize;
|
|
@@ -1104,7 +1189,7 @@ HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1104
1189
|
|
|
1105
1190
|
ip += segmentSize;
|
|
1106
1191
|
assert(op <= oend);
|
|
1107
|
-
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable,
|
|
1192
|
+
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable, flags) );
|
|
1108
1193
|
if (cSize == 0 || cSize > 65535) return 0;
|
|
1109
1194
|
MEM_writeLE16(ostart+2, (U16)cSize);
|
|
1110
1195
|
op += cSize;
|
|
@@ -1112,7 +1197,7 @@ HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1112
1197
|
|
|
1113
1198
|
ip += segmentSize;
|
|
1114
1199
|
assert(op <= oend);
|
|
1115
|
-
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable,
|
|
1200
|
+
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, segmentSize, CTable, flags) );
|
|
1116
1201
|
if (cSize == 0 || cSize > 65535) return 0;
|
|
1117
1202
|
MEM_writeLE16(ostart+4, (U16)cSize);
|
|
1118
1203
|
op += cSize;
|
|
@@ -1121,7 +1206,7 @@ HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1121
1206
|
ip += segmentSize;
|
|
1122
1207
|
assert(op <= oend);
|
|
1123
1208
|
assert(ip <= iend);
|
|
1124
|
-
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, (size_t)(iend-ip), CTable,
|
|
1209
|
+
{ CHECK_V_F(cSize, HUF_compress1X_usingCTable_internal(op, (size_t)(oend-op), ip, (size_t)(iend-ip), CTable, flags) );
|
|
1125
1210
|
if (cSize == 0 || cSize > 65535) return 0;
|
|
1126
1211
|
op += cSize;
|
|
1127
1212
|
}
|
|
@@ -1129,14 +1214,9 @@ HUF_compress4X_usingCTable_internal(void* dst, size_t dstSize,
|
|
|
1129
1214
|
return (size_t)(op-ostart);
|
|
1130
1215
|
}
|
|
1131
1216
|
|
|
1132
|
-
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable)
|
|
1217
|
+
size_t HUF_compress4X_usingCTable(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int flags)
|
|
1133
1218
|
{
|
|
1134
|
-
return
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
size_t HUF_compress4X_usingCTable_bmi2(void* dst, size_t dstSize, const void* src, size_t srcSize, const HUF_CElt* CTable, int bmi2)
|
|
1138
|
-
{
|
|
1139
|
-
return HUF_compress4X_usingCTable_internal(dst, dstSize, src, srcSize, CTable, bmi2);
|
|
1219
|
+
return HUF_compress4X_usingCTable_internal(dst, dstSize, src, srcSize, CTable, flags);
|
|
1140
1220
|
}
|
|
1141
1221
|
|
|
1142
1222
|
typedef enum { HUF_singleStream, HUF_fourStreams } HUF_nbStreams_e;
|
|
@@ -1144,11 +1224,11 @@ typedef enum { HUF_singleStream, HUF_fourStreams } HUF_nbStreams_e;
|
|
|
1144
1224
|
static size_t HUF_compressCTable_internal(
|
|
1145
1225
|
BYTE* const ostart, BYTE* op, BYTE* const oend,
|
|
1146
1226
|
const void* src, size_t srcSize,
|
|
1147
|
-
HUF_nbStreams_e nbStreams, const HUF_CElt* CTable, const int
|
|
1227
|
+
HUF_nbStreams_e nbStreams, const HUF_CElt* CTable, const int flags)
|
|
1148
1228
|
{
|
|
1149
1229
|
size_t const cSize = (nbStreams==HUF_singleStream) ?
|
|
1150
|
-
HUF_compress1X_usingCTable_internal(op, (size_t)(oend - op), src, srcSize, CTable,
|
|
1151
|
-
HUF_compress4X_usingCTable_internal(op, (size_t)(oend - op), src, srcSize, CTable,
|
|
1230
|
+
HUF_compress1X_usingCTable_internal(op, (size_t)(oend - op), src, srcSize, CTable, flags) :
|
|
1231
|
+
HUF_compress4X_usingCTable_internal(op, (size_t)(oend - op), src, srcSize, CTable, flags);
|
|
1152
1232
|
if (HUF_isError(cSize)) { return cSize; }
|
|
1153
1233
|
if (cSize==0) { return 0; } /* uncompressible */
|
|
1154
1234
|
op += cSize;
|
|
@@ -1171,6 +1251,81 @@ typedef struct {
|
|
|
1171
1251
|
#define SUSPECT_INCOMPRESSIBLE_SAMPLE_SIZE 4096
|
|
1172
1252
|
#define SUSPECT_INCOMPRESSIBLE_SAMPLE_RATIO 10 /* Must be >= 2 */
|
|
1173
1253
|
|
|
1254
|
+
unsigned HUF_cardinality(const unsigned* count, unsigned maxSymbolValue)
|
|
1255
|
+
{
|
|
1256
|
+
unsigned cardinality = 0;
|
|
1257
|
+
unsigned i;
|
|
1258
|
+
|
|
1259
|
+
for (i = 0; i < maxSymbolValue + 1; i++) {
|
|
1260
|
+
if (count[i] != 0) cardinality += 1;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
return cardinality;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
unsigned HUF_minTableLog(unsigned symbolCardinality)
|
|
1267
|
+
{
|
|
1268
|
+
U32 minBitsSymbols = ZSTD_highbit32(symbolCardinality) + 1;
|
|
1269
|
+
return minBitsSymbols;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
unsigned HUF_optimalTableLog(
|
|
1273
|
+
unsigned maxTableLog,
|
|
1274
|
+
size_t srcSize,
|
|
1275
|
+
unsigned maxSymbolValue,
|
|
1276
|
+
void* workSpace, size_t wkspSize,
|
|
1277
|
+
HUF_CElt* table,
|
|
1278
|
+
const unsigned* count,
|
|
1279
|
+
int flags)
|
|
1280
|
+
{
|
|
1281
|
+
assert(srcSize > 1); /* Not supported, RLE should be used instead */
|
|
1282
|
+
assert(wkspSize >= sizeof(HUF_buildCTable_wksp_tables));
|
|
1283
|
+
|
|
1284
|
+
if (!(flags & HUF_flags_optimalDepth)) {
|
|
1285
|
+
/* cheap evaluation, based on FSE */
|
|
1286
|
+
return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 1);
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
{ BYTE* dst = (BYTE*)workSpace + sizeof(HUF_WriteCTableWksp);
|
|
1290
|
+
size_t dstSize = wkspSize - sizeof(HUF_WriteCTableWksp);
|
|
1291
|
+
size_t hSize, newSize;
|
|
1292
|
+
const unsigned symbolCardinality = HUF_cardinality(count, maxSymbolValue);
|
|
1293
|
+
const unsigned minTableLog = HUF_minTableLog(symbolCardinality);
|
|
1294
|
+
size_t optSize = ((size_t) ~0) - 1;
|
|
1295
|
+
unsigned optLog = maxTableLog, optLogGuess;
|
|
1296
|
+
|
|
1297
|
+
DEBUGLOG(6, "HUF_optimalTableLog: probing huf depth (srcSize=%zu)", srcSize);
|
|
1298
|
+
|
|
1299
|
+
/* Search until size increases */
|
|
1300
|
+
for (optLogGuess = minTableLog; optLogGuess <= maxTableLog; optLogGuess++) {
|
|
1301
|
+
DEBUGLOG(7, "checking for huffLog=%u", optLogGuess);
|
|
1302
|
+
|
|
1303
|
+
{ size_t maxBits = HUF_buildCTable_wksp(table, count, maxSymbolValue, optLogGuess, workSpace, wkspSize);
|
|
1304
|
+
if (ERR_isError(maxBits)) continue;
|
|
1305
|
+
|
|
1306
|
+
if (maxBits < optLogGuess && optLogGuess > minTableLog) break;
|
|
1307
|
+
|
|
1308
|
+
hSize = HUF_writeCTable_wksp(dst, dstSize, table, maxSymbolValue, (U32)maxBits, workSpace, wkspSize);
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
if (ERR_isError(hSize)) continue;
|
|
1312
|
+
|
|
1313
|
+
newSize = HUF_estimateCompressedSize(table, count, maxSymbolValue) + hSize;
|
|
1314
|
+
|
|
1315
|
+
if (newSize > optSize + 1) {
|
|
1316
|
+
break;
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
if (newSize < optSize) {
|
|
1320
|
+
optSize = newSize;
|
|
1321
|
+
optLog = optLogGuess;
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
assert(optLog <= HUF_TABLELOG_MAX);
|
|
1325
|
+
return optLog;
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1174
1329
|
/* HUF_compress_internal() :
|
|
1175
1330
|
* `workSpace_align4` must be aligned on 4-bytes boundaries,
|
|
1176
1331
|
* and occupies the same space as a table of HUF_WORKSPACE_SIZE_U64 unsigned */
|
|
@@ -1180,14 +1335,14 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1180
1335
|
unsigned maxSymbolValue, unsigned huffLog,
|
|
1181
1336
|
HUF_nbStreams_e nbStreams,
|
|
1182
1337
|
void* workSpace, size_t wkspSize,
|
|
1183
|
-
HUF_CElt* oldHufTable, HUF_repeat* repeat, int
|
|
1184
|
-
const int bmi2, unsigned suspectUncompressible)
|
|
1338
|
+
HUF_CElt* oldHufTable, HUF_repeat* repeat, int flags)
|
|
1185
1339
|
{
|
|
1186
1340
|
HUF_compress_tables_t* const table = (HUF_compress_tables_t*)HUF_alignUpWorkspace(workSpace, &wkspSize, ZSTD_ALIGNOF(size_t));
|
|
1187
1341
|
BYTE* const ostart = (BYTE*)dst;
|
|
1188
1342
|
BYTE* const oend = ostart + dstSize;
|
|
1189
1343
|
BYTE* op = ostart;
|
|
1190
1344
|
|
|
1345
|
+
DEBUGLOG(5, "HUF_compress_internal (srcSize=%zu)", srcSize);
|
|
1191
1346
|
HUF_STATIC_ASSERT(sizeof(*table) + HUF_WORKSPACE_MAX_ALIGNMENT <= HUF_WORKSPACE_SIZE);
|
|
1192
1347
|
|
|
1193
1348
|
/* checks & inits */
|
|
@@ -1201,16 +1356,17 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1201
1356
|
if (!huffLog) huffLog = HUF_TABLELOG_DEFAULT;
|
|
1202
1357
|
|
|
1203
1358
|
/* Heuristic : If old table is valid, use it for small inputs */
|
|
1204
|
-
if (
|
|
1359
|
+
if ((flags & HUF_flags_preferRepeat) && repeat && *repeat == HUF_repeat_valid) {
|
|
1205
1360
|
return HUF_compressCTable_internal(ostart, op, oend,
|
|
1206
1361
|
src, srcSize,
|
|
1207
|
-
nbStreams, oldHufTable,
|
|
1362
|
+
nbStreams, oldHufTable, flags);
|
|
1208
1363
|
}
|
|
1209
1364
|
|
|
1210
1365
|
/* If uncompressible data is suspected, do a smaller sampling first */
|
|
1211
1366
|
DEBUG_STATIC_ASSERT(SUSPECT_INCOMPRESSIBLE_SAMPLE_RATIO >= 2);
|
|
1212
|
-
if (
|
|
1367
|
+
if ((flags & HUF_flags_suspectUncompressible) && srcSize >= (SUSPECT_INCOMPRESSIBLE_SAMPLE_SIZE * SUSPECT_INCOMPRESSIBLE_SAMPLE_RATIO)) {
|
|
1213
1368
|
size_t largestTotal = 0;
|
|
1369
|
+
DEBUGLOG(5, "input suspected incompressible : sampling to check");
|
|
1214
1370
|
{ unsigned maxSymbolValueBegin = maxSymbolValue;
|
|
1215
1371
|
CHECK_V_F(largestBegin, HIST_count_simple (table->count, &maxSymbolValueBegin, (const BYTE*)src, SUSPECT_INCOMPRESSIBLE_SAMPLE_SIZE) );
|
|
1216
1372
|
largestTotal += largestBegin;
|
|
@@ -1227,6 +1383,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1227
1383
|
if (largest == srcSize) { *ostart = ((const BYTE*)src)[0]; return 1; } /* single symbol, rle */
|
|
1228
1384
|
if (largest <= (srcSize >> 7)+4) return 0; /* heuristic : probably not compressible enough */
|
|
1229
1385
|
}
|
|
1386
|
+
DEBUGLOG(6, "histogram detail completed (%zu symbols)", showU32(table->count, maxSymbolValue+1));
|
|
1230
1387
|
|
|
1231
1388
|
/* Check validity of previous table */
|
|
1232
1389
|
if ( repeat
|
|
@@ -1235,25 +1392,20 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1235
1392
|
*repeat = HUF_repeat_none;
|
|
1236
1393
|
}
|
|
1237
1394
|
/* Heuristic : use existing table for small inputs */
|
|
1238
|
-
if (
|
|
1395
|
+
if ((flags & HUF_flags_preferRepeat) && repeat && *repeat != HUF_repeat_none) {
|
|
1239
1396
|
return HUF_compressCTable_internal(ostart, op, oend,
|
|
1240
1397
|
src, srcSize,
|
|
1241
|
-
nbStreams, oldHufTable,
|
|
1398
|
+
nbStreams, oldHufTable, flags);
|
|
1242
1399
|
}
|
|
1243
1400
|
|
|
1244
1401
|
/* Build Huffman Tree */
|
|
1245
|
-
huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue);
|
|
1402
|
+
huffLog = HUF_optimalTableLog(huffLog, srcSize, maxSymbolValue, &table->wksps, sizeof(table->wksps), table->CTable, table->count, flags);
|
|
1246
1403
|
{ size_t const maxBits = HUF_buildCTable_wksp(table->CTable, table->count,
|
|
1247
1404
|
maxSymbolValue, huffLog,
|
|
1248
1405
|
&table->wksps.buildCTable_wksp, sizeof(table->wksps.buildCTable_wksp));
|
|
1249
1406
|
CHECK_F(maxBits);
|
|
1250
1407
|
huffLog = (U32)maxBits;
|
|
1251
|
-
|
|
1252
|
-
/* Zero unused symbols in CTable, so we can check it for validity */
|
|
1253
|
-
{
|
|
1254
|
-
size_t const ctableSize = HUF_CTABLE_SIZE_ST(maxSymbolValue);
|
|
1255
|
-
size_t const unusedSize = sizeof(table->CTable) - ctableSize * sizeof(HUF_CElt);
|
|
1256
|
-
ZSTD_memset(table->CTable + ctableSize, 0, unusedSize);
|
|
1408
|
+
DEBUGLOG(6, "bit distribution completed (%zu symbols)", showCTableBits(table->CTable + 1, maxSymbolValue+1));
|
|
1257
1409
|
}
|
|
1258
1410
|
|
|
1259
1411
|
/* Write table description header */
|
|
@@ -1266,7 +1418,7 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1266
1418
|
if (oldSize <= hSize + newSize || hSize + 12 >= srcSize) {
|
|
1267
1419
|
return HUF_compressCTable_internal(ostart, op, oend,
|
|
1268
1420
|
src, srcSize,
|
|
1269
|
-
nbStreams, oldHufTable,
|
|
1421
|
+
nbStreams, oldHufTable, flags);
|
|
1270
1422
|
} }
|
|
1271
1423
|
|
|
1272
1424
|
/* Use the new huffman table */
|
|
@@ -1278,93 +1430,35 @@ HUF_compress_internal (void* dst, size_t dstSize,
|
|
|
1278
1430
|
}
|
|
1279
1431
|
return HUF_compressCTable_internal(ostart, op, oend,
|
|
1280
1432
|
src, srcSize,
|
|
1281
|
-
nbStreams, table->CTable,
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
size_t HUF_compress1X_wksp (void* dst, size_t dstSize,
|
|
1286
|
-
const void* src, size_t srcSize,
|
|
1287
|
-
unsigned maxSymbolValue, unsigned huffLog,
|
|
1288
|
-
void* workSpace, size_t wkspSize)
|
|
1289
|
-
{
|
|
1290
|
-
return HUF_compress_internal(dst, dstSize, src, srcSize,
|
|
1291
|
-
maxSymbolValue, huffLog, HUF_singleStream,
|
|
1292
|
-
workSpace, wkspSize,
|
|
1293
|
-
NULL, NULL, 0, 0 /*bmi2*/, 0);
|
|
1433
|
+
nbStreams, table->CTable, flags);
|
|
1294
1434
|
}
|
|
1295
1435
|
|
|
1296
1436
|
size_t HUF_compress1X_repeat (void* dst, size_t dstSize,
|
|
1297
1437
|
const void* src, size_t srcSize,
|
|
1298
1438
|
unsigned maxSymbolValue, unsigned huffLog,
|
|
1299
1439
|
void* workSpace, size_t wkspSize,
|
|
1300
|
-
HUF_CElt* hufTable, HUF_repeat* repeat, int
|
|
1301
|
-
int bmi2, unsigned suspectUncompressible)
|
|
1440
|
+
HUF_CElt* hufTable, HUF_repeat* repeat, int flags)
|
|
1302
1441
|
{
|
|
1442
|
+
DEBUGLOG(5, "HUF_compress1X_repeat (srcSize = %zu)", srcSize);
|
|
1303
1443
|
return HUF_compress_internal(dst, dstSize, src, srcSize,
|
|
1304
1444
|
maxSymbolValue, huffLog, HUF_singleStream,
|
|
1305
1445
|
workSpace, wkspSize, hufTable,
|
|
1306
|
-
repeat,
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
/* HUF_compress4X_repeat():
|
|
1310
|
-
* compress input using 4 streams.
|
|
1311
|
-
* provide workspace to generate compression tables */
|
|
1312
|
-
size_t HUF_compress4X_wksp (void* dst, size_t dstSize,
|
|
1313
|
-
const void* src, size_t srcSize,
|
|
1314
|
-
unsigned maxSymbolValue, unsigned huffLog,
|
|
1315
|
-
void* workSpace, size_t wkspSize)
|
|
1316
|
-
{
|
|
1317
|
-
return HUF_compress_internal(dst, dstSize, src, srcSize,
|
|
1318
|
-
maxSymbolValue, huffLog, HUF_fourStreams,
|
|
1319
|
-
workSpace, wkspSize,
|
|
1320
|
-
NULL, NULL, 0, 0 /*bmi2*/, 0);
|
|
1446
|
+
repeat, flags);
|
|
1321
1447
|
}
|
|
1322
1448
|
|
|
1323
1449
|
/* HUF_compress4X_repeat():
|
|
1324
1450
|
* compress input using 4 streams.
|
|
1325
1451
|
* consider skipping quickly
|
|
1326
|
-
*
|
|
1452
|
+
* reuse an existing huffman compression table */
|
|
1327
1453
|
size_t HUF_compress4X_repeat (void* dst, size_t dstSize,
|
|
1328
1454
|
const void* src, size_t srcSize,
|
|
1329
1455
|
unsigned maxSymbolValue, unsigned huffLog,
|
|
1330
1456
|
void* workSpace, size_t wkspSize,
|
|
1331
|
-
HUF_CElt* hufTable, HUF_repeat* repeat, int
|
|
1457
|
+
HUF_CElt* hufTable, HUF_repeat* repeat, int flags)
|
|
1332
1458
|
{
|
|
1459
|
+
DEBUGLOG(5, "HUF_compress4X_repeat (srcSize = %zu)", srcSize);
|
|
1333
1460
|
return HUF_compress_internal(dst, dstSize, src, srcSize,
|
|
1334
1461
|
maxSymbolValue, huffLog, HUF_fourStreams,
|
|
1335
1462
|
workSpace, wkspSize,
|
|
1336
|
-
hufTable, repeat,
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
#ifndef ZSTD_NO_UNUSED_FUNCTIONS
|
|
1340
|
-
/** HUF_buildCTable() :
|
|
1341
|
-
* @return : maxNbBits
|
|
1342
|
-
* Note : count is used before tree is written, so they can safely overlap
|
|
1343
|
-
*/
|
|
1344
|
-
size_t HUF_buildCTable (HUF_CElt* tree, const unsigned* count, unsigned maxSymbolValue, unsigned maxNbBits)
|
|
1345
|
-
{
|
|
1346
|
-
HUF_buildCTable_wksp_tables workspace;
|
|
1347
|
-
return HUF_buildCTable_wksp(tree, count, maxSymbolValue, maxNbBits, &workspace, sizeof(workspace));
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
size_t HUF_compress1X (void* dst, size_t dstSize,
|
|
1351
|
-
const void* src, size_t srcSize,
|
|
1352
|
-
unsigned maxSymbolValue, unsigned huffLog)
|
|
1353
|
-
{
|
|
1354
|
-
U64 workSpace[HUF_WORKSPACE_SIZE_U64];
|
|
1355
|
-
return HUF_compress1X_wksp(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, workSpace, sizeof(workSpace));
|
|
1463
|
+
hufTable, repeat, flags);
|
|
1356
1464
|
}
|
|
1357
|
-
|
|
1358
|
-
size_t HUF_compress2 (void* dst, size_t dstSize,
|
|
1359
|
-
const void* src, size_t srcSize,
|
|
1360
|
-
unsigned maxSymbolValue, unsigned huffLog)
|
|
1361
|
-
{
|
|
1362
|
-
U64 workSpace[HUF_WORKSPACE_SIZE_U64];
|
|
1363
|
-
return HUF_compress4X_wksp(dst, dstSize, src, srcSize, maxSymbolValue, huffLog, workSpace, sizeof(workSpace));
|
|
1364
|
-
}
|
|
1365
|
-
|
|
1366
|
-
size_t HUF_compress (void* dst, size_t maxDstSize, const void* src, size_t srcSize)
|
|
1367
|
-
{
|
|
1368
|
-
return HUF_compress2(dst, maxDstSize, src, srcSize, 255, HUF_TABLELOG_DEFAULT);
|
|
1369
|
-
}
|
|
1370
|
-
#endif
|