10#ifndef BROTLI_ENC_HASH_H_
11#define BROTLI_ENC_HASH_H_
18#include <brotli/types.h>
26#if defined(__cplusplus) || defined(c_plusplus)
45static const uint32_t kCutoffTransformsCount = 10;
48static const uint64_t kCutoffTransforms =
64static const uint32_t kHashMul32 = 0x1E35A7BD;
66static const uint64_t kHashMul64Long =
70 uint32_t
h = BROTLI_UNALIGNED_LOAD32LE(
data) * kHashMul32;
73 return h >> (32 - 14);
78 if (num_distances > 4) {
79 int last_distance = distance_cache[0];
80 distance_cache[4] = last_distance - 1;
81 distance_cache[5] = last_distance + 1;
82 distance_cache[6] = last_distance - 2;
83 distance_cache[7] = last_distance + 2;
84 distance_cache[8] = last_distance - 3;
85 distance_cache[9] = last_distance + 3;
86 if (num_distances > 10) {
87 int next_last_distance = distance_cache[1];
88 distance_cache[10] = next_last_distance - 1;
89 distance_cache[11] = next_last_distance + 1;
90 distance_cache[12] = next_last_distance - 2;
91 distance_cache[13] = next_last_distance + 2;
92 distance_cache[14] = next_last_distance - 3;
93 distance_cache[15] = next_last_distance + 3;
98#define BROTLI_LITERAL_BYTE_SCORE 135
99#define BROTLI_DISTANCE_BIT_PENALTY 30
101#define BROTLI_SCORE_BASE (BROTLI_DISTANCE_BIT_PENALTY * 8 * sizeof(size_t))
120 size_t copy_length,
size_t backward_reference_offset) {
126 size_t copy_length) {
132 size_t distance_short_code) {
133 return (
score_t)39 + ((0x1CA10 >> (distance_short_code & 0xE)) & 0xE);
138 const uint8_t*
data,
size_t max_length,
size_t max_backward,
145 if (
len > max_length) {
151 if (matchlen +
dictionary->cutoffTransformsCount <=
len || matchlen == 0) {
155 size_t cut =
len - matchlen;
156 size_t transform_id = (cut << 2) +
157 (
size_t)((
dictionary->cutoffTransforms >> (cut * 6)) & 0x3F);
158 backward = max_backward + 1 + word_idx +
159 (transform_id <<
dictionary->words->size_bits_by_length[
len]);
161 if (backward > max_distance) {
164 score = BackwardReferenceScore(matchlen, backward);
165 if (score < out->score) {
169 out->len_code_delta = (
int)
len - (
int)matchlen;
170 out->distance = backward;
178 size_t max_backward,
size_t max_distance,
185 key = Hash14(
data) << 1;
186 for (
i = 0;
i < (shallow ? 1u : 2u); ++
i, ++key) {
188 if (
dictionary->hash_table_lengths[key] != 0) {
189 BROTLI_BOOL item_matches = TestStaticDictionaryItem(
192 max_length, max_backward, max_distance, out);
206 size_t dist,
size_t len) {
212 size_t dist,
size_t len,
size_t len_code) {
215 (uint32_t)((
len << 5) | (
len == len_code ? 0 : len_code));
224 return code ?
code : BackwardMatchLength(self);
227#define EXPAND_CAT(a, b) CAT(a, b)
228#define CAT(a, b) a ## b
229#define FN(X) EXPAND_CAT(X, HASHER())
232#define BUCKET_BITS 17
233#define MAX_TREE_SEARCH_DEPTH 64
234#define MAX_TREE_COMP_LENGTH 128
236#undef MAX_TREE_SEARCH_DEPTH
237#undef MAX_TREE_COMP_LENGTH
241#define MAX_NUM_MATCHES_H10 128
248#define BUCKET_BITS 16
249#define BUCKET_SWEEP_BITS 0
251#define USE_DICTIONARY 1
253#undef BUCKET_SWEEP_BITS
258#define BUCKET_SWEEP_BITS 1
259#define USE_DICTIONARY 0
262#undef BUCKET_SWEEP_BITS
267#define BUCKET_BITS 17
268#define BUCKET_SWEEP_BITS 2
269#define USE_DICTIONARY 1
273#undef BUCKET_SWEEP_BITS
285#define BUCKET_BITS 15
287#define NUM_LAST_DISTANCES_TO_CHECK 4
293#undef NUM_LAST_DISTANCES_TO_CHECK
295#define NUM_LAST_DISTANCES_TO_CHECK 10
299#undef NUM_LAST_DISTANCES_TO_CHECK
303#define NUM_LAST_DISTANCES_TO_CHECK 16
309#undef NUM_LAST_DISTANCES_TO_CHECK
316#define BUCKET_BITS 20
317#define BUCKET_SWEEP_BITS 2
319#define USE_DICTIONARY 0
323#undef BUCKET_SWEEP_BITS
329#define HASHER() HROLLING_FAST
332#define NUMBUCKETS 16777216
333#define MASK ((NUMBUCKETS * 64) - 1)
339#define HASHER() HROLLING
350#define HASHER_B HROLLING_FAST
358#define HASHER_B HROLLING_FAST
366#define HASHER_B HROLLING
376#define FOR_SIMPLE_HASHERS(H) H(2) H(3) H(4) H(5) H(6) H(40) H(41) H(42) H(54)
377#define FOR_COMPOSITE_HASHERS(H) H(35) H(55) H(65)
378#define FOR_GENERIC_HASHERS(H) FOR_SIMPLE_HASHERS(H) FOR_COMPOSITE_HASHERS(H)
379#define FOR_ALL_HASHERS(H) FOR_GENERIC_HASHERS(H) H(10)
411 return HashMemAllocInBytesH ## N(params, one_shot, input_size);
426 ChooseHasher(params, ¶ms->
hasher);
427 alloc_size = HasherSize(params, one_shot, input_size);
432#define INITIALIZE_(N) \
434 InitializeH ## N(&hasher->common, \
435 &hasher->privat._H ## N, params); \
450 &hasher->privat._H ## N, \
451 one_shot, input_size, data); \
469 HasherSetup(m, hasher, params,
data, position, input_size, is_last);
474 StitchToPreviousBlockH ## N( \
475 &hasher->privat._H ## N, \
476 input_size, position, data, mask); \
484#if defined(__cplusplus) || defined(c_plusplus)
#define score_t
Definition hash.h:59
struct BackwardMatch BackwardMatch
#define BROTLI_SCORE_BASE
Definition hash.h:101
#define FOR_ALL_HASHERS(H)
Definition hash.h:379
#define BROTLI_LITERAL_BYTE_SCORE
Definition hash.h:98
#define score_t
Definition hash.h:43
#define BROTLI_DISTANCE_BIT_PENALTY
Definition hash.h:99
#define MEMBER_(N)
Definition hash.h:385
struct HasherSearchResult HasherSearchResult
#define BROTLI_ALLOC(M, T, N)
Definition memory.h:44
#define BROTLI_FREE(M, P)
Definition memory.h:48
#define BROTLI_IS_OOM(M)
Definition memory.h:54
#define BROTLI_IS_NULL(A)
Definition memory.h:68
uint32_t length_and_code
Definition hash.h:202
uint32_t distance
Definition hash.h:201
Definition encoder_dict.h:20
BrotliHasherParams hasher
Definition params.h:41
int type
Definition params.h:16
BrotliHasherParams params
Definition hash.h:37
size_t dict_num_matches
Definition hash.h:35
void * extra
Definition hash.h:32
BROTLI_BOOL is_prepared_
Definition hash.h:40
size_t dict_num_lookups
Definition hash.h:34
HasherCommon common
Definition hash.h:382
score_t score
Definition hash.h:54
size_t distance
Definition hash.h:53
size_t len
Definition hash.h:52
int len_code_delta
Definition hash.h:55
Definition poolTests.c:28
Definition zstd_decompress.c:306
const char * data
Definition invalidDictionaries.c:32
#define BROTLI_TRUE
Definition types.h:51
#define BROTLI_MAKE_UINT64_T(high, low)
Definition types.h:57
#define BROTLI_FALSE
Definition types.h:53
#define BROTLI_BOOL
Definition types.h:49
#define h(i)
Definition sha256.c:48
const lzma_allocator const uint8_t size_t uint8_t * out
Definition block.h:528
lzma_index ** i
Definition index.h:629
#define NULL
Definition getopt1.c:37
static uint32_t const uint8_t uint32_t len
Definition memcmplen.h:44