18#define HashToBinaryTree HASHER()
20#define BUCKET_SIZE (1 << BUCKET_BITS)
28 uint32_t
h = BROTLI_UNALIGNED_LOAD32LE(
data) * kHashMul32;
57static void FN(Initialize)(
60 self->buckets_ = (uint32_t*)common->extra[0];
61 self->forest_ = (uint32_t*)common->extra[1];
63 self->window_mask_ = (1u << params->lgwin) - 1u;
64 self->invalid_pos_ = (uint32_t)(0 - self->window_mask_);
67static void FN(Prepare)
70 uint32_t invalid_pos = self->invalid_pos_;
77 buckets[
i] = invalid_pos;
83 size_t input_size,
size_t* alloc_size) {
84 size_t num_nodes = (size_t)1 << params->lgwin;
85 if (one_shot && input_size < num_nodes) {
86 num_nodes = input_size;
89 alloc_size[1] = 2 *
sizeof(uint32_t) * num_nodes;
95 return 2 * (pos & self->window_mask_);
101 return 2 * (pos & self->window_mask_) + 1;
116 const size_t cur_ix,
const size_t ring_buffer_mask,
const size_t max_length,
119 const size_t cur_ix_masked = cur_ix & ring_buffer_mask;
120 const size_t max_comp_len =
124 const uint32_t key =
FN(HashBytes)(&
data[cur_ix_masked]);
127 size_t prev_ix = buckets[key];
130 size_t node_left =
FN(LeftChildIndex)(self, cur_ix);
133 size_t node_right =
FN(RightChildIndex)(self, cur_ix);
136 size_t best_len_left = 0;
139 size_t best_len_right = 0;
140 size_t depth_remaining;
141 if (should_reroot_tree) {
142 buckets[key] = (uint32_t)cur_ix;
145 const size_t backward = cur_ix - prev_ix;
146 const size_t prev_ix_masked = prev_ix & ring_buffer_mask;
147 if (backward == 0 || backward > max_backward || depth_remaining == 0) {
148 if (should_reroot_tree) {
149 forest[node_left] = self->invalid_pos_;
150 forest[node_right] = self->invalid_pos_;
155 const size_t cur_len =
BROTLI_MIN(
size_t, best_len_left, best_len_right);
159 FindMatchLengthWithLimit(&
data[cur_ix_masked + cur_len],
160 &
data[prev_ix_masked + cur_len],
161 max_length - cur_len);
163 0 == memcmp(&
data[cur_ix_masked], &
data[prev_ix_masked],
len));
164 if (matches &&
len > *best_len) {
166 InitBackwardMatch(matches++, backward,
len);
168 if (
len >= max_comp_len) {
169 if (should_reroot_tree) {
170 forest[node_left] = forest[
FN(LeftChildIndex)(self, prev_ix)];
171 forest[node_right] = forest[
FN(RightChildIndex)(self, prev_ix)];
177 if (should_reroot_tree) {
178 forest[node_left] = (uint32_t)prev_ix;
180 node_left =
FN(RightChildIndex)(self, prev_ix);
181 prev_ix = forest[node_left];
183 best_len_right =
len;
184 if (should_reroot_tree) {
185 forest[node_right] = (uint32_t)prev_ix;
187 node_right =
FN(LeftChildIndex)(self, prev_ix);
188 prev_ix = forest[node_right];
206 const size_t ring_buffer_mask,
const size_t cur_ix,
207 const size_t max_length,
const size_t max_backward,
211 const size_t cur_ix_masked = cur_ix & ring_buffer_mask;
213 const size_t short_match_max_backward =
215 size_t stop = cur_ix - short_match_max_backward;
218 if (cur_ix < short_match_max_backward) { stop = 0; }
219 for (
i = cur_ix - 1;
i > stop && best_len <= 2; --
i) {
221 const size_t backward = cur_ix - prev_ix;
225 prev_ix &= ring_buffer_mask;
226 if (
data[cur_ix_masked] !=
data[prev_ix] ||
227 data[cur_ix_masked + 1] !=
data[prev_ix + 1]) {
232 FindMatchLengthWithLimit(&
data[prev_ix], &
data[cur_ix_masked],
234 if (
len > best_len) {
236 InitBackwardMatch(matches++, backward,
len);
240 if (best_len < max_length) {
241 matches =
FN(StoreAndFindMatches)(self,
data, cur_ix,
242 ring_buffer_mask, max_length, max_backward, &best_len, matches);
245 dict_matches[
i] = kInvalidMatch;
248 size_t minlen =
BROTLI_MAX(
size_t, 4, best_len + 1);
250 &
data[cur_ix_masked], minlen, max_length, &dict_matches[0])) {
254 for (l = minlen; l <= maxlen; ++l) {
255 uint32_t dict_id = dict_matches[l];
256 if (dict_id < kInvalidMatch) {
257 size_t distance = dictionary_distance + (dict_id >> 5) + 1;
258 if (distance <= params->dist.max_distance) {
259 InitDictionaryBackwardMatch(matches++, distance, l, dict_id & 31);
265 return (
size_t)(matches - orig_matches);
273 const size_t mask,
const size_t ix) {
282 const size_t ix_start,
const size_t ix_end) {
285 if (ix_start + 63 <= ix_end) {
288 if (ix_start + 512 <=
i) {
289 for (; j <
i; j += 8) {
290 FN(Store)(self,
data, mask, j);
293 for (;
i < ix_end; ++
i) {
294 FN(Store)(self,
data, mask,
i);
300 size_t num_bytes,
size_t position,
const uint8_t* ringbuffer,
301 size_t ringbuffer_mask) {
302 if (num_bytes >=
FN(HashTypeLength)() - 1 &&
308 const size_t i_end =
BROTLI_MIN(
size_t, position, i_start + num_bytes);
310 for (
i = i_start;
i < i_end; ++
i) {
315 const size_t max_backward =
322 FN(StoreAndFindMatches)(self, ringbuffer,
i, ringbuffer_mask,
330#undef HashToBinaryTree
static const void * data
Definition XzCrc64.c:50
#define BROTLI_WINDOW_GAP
Definition constants.h:102
#define FN(X)
Definition backward_references.c:51
#define MAX_TREE_SEARCH_DEPTH
Definition hash.h:233
#define BUCKET_BITS
Definition hash.h:232
#define MAX_TREE_COMP_LENGTH
Definition hash.h:234
#define BUCKET_SIZE
Definition hash_to_binary_tree_inc.h:20
#define HashToBinaryTree
Definition hash_to_binary_tree_inc.h:18
#define HQ_ZOPFLIFICATION_QUALITY
Definition quality.h:20
BROTLI_BOOL BrotliFindAllStaticDictionaryMatches(const BrotliEncoderDictionary *dictionary, const uint8_t *data, size_t min_length, size_t max_length, uint32_t *matches)
Definition static_dict.c:77
#define BROTLI_MAX_STATIC_DICTIONARY_MATCH_LEN
Definition static_dict.h:21
Definition encoder_dict.h:20
Definition hash_to_binary_tree_inc.h:34
size_t window_mask_
Definition hash_to_binary_tree_inc.h:36
uint32_t * forest_
Definition hash_to_binary_tree_inc.h:54
uint32_t * buckets_
Definition hash_to_binary_tree_inc.h:41
uint32_t invalid_pos_
Definition hash_to_binary_tree_inc.h:46
Definition poolTests.c:28
Definition zstd_decompress.c:306
#define TO_BROTLI_BOOL(X)
Definition types.h:55
#define BROTLI_BOOL
Definition types.h:49
#define h(i)
Definition sha256.c:48
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
struct dictionary_s dictionary