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;
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;
84 size_t num_nodes = (size_t)1 << params->lgwin;
85 if (one_shot && input_size < num_nodes) {
86 num_nodes = input_size;
88 return sizeof(uint32_t) *
BUCKET_SIZE + 2 *
sizeof(uint32_t) * num_nodes;
94 return 2 * (pos & self->window_mask_);
100 return 2 * (pos & self->window_mask_) + 1;
115 const size_t cur_ix,
const size_t ring_buffer_mask,
const size_t max_length,
118 const size_t cur_ix_masked = cur_ix & ring_buffer_mask;
119 const size_t max_comp_len =
123 const uint32_t key =
FN(HashBytes)(&
data[cur_ix_masked]);
126 size_t prev_ix = buckets[key];
129 size_t node_left =
FN(LeftChildIndex)(self, cur_ix);
132 size_t node_right =
FN(RightChildIndex)(self, cur_ix);
135 size_t best_len_left = 0;
138 size_t best_len_right = 0;
139 size_t depth_remaining;
140 if (should_reroot_tree) {
141 buckets[key] = (uint32_t)cur_ix;
144 const size_t backward = cur_ix - prev_ix;
145 const size_t prev_ix_masked = prev_ix & ring_buffer_mask;
146 if (backward == 0 || backward > max_backward || depth_remaining == 0) {
147 if (should_reroot_tree) {
148 forest[node_left] = self->invalid_pos_;
149 forest[node_right] = self->invalid_pos_;
154 const size_t cur_len =
BROTLI_MIN(
size_t, best_len_left, best_len_right);
158 FindMatchLengthWithLimit(&
data[cur_ix_masked + cur_len],
159 &
data[prev_ix_masked + cur_len],
160 max_length - cur_len);
162 0 == memcmp(&
data[cur_ix_masked], &
data[prev_ix_masked],
len));
163 if (matches &&
len > *best_len) {
165 InitBackwardMatch(matches++, backward,
len);
167 if (
len >= max_comp_len) {
168 if (should_reroot_tree) {
169 forest[node_left] = forest[
FN(LeftChildIndex)(self, prev_ix)];
170 forest[node_right] = forest[
FN(RightChildIndex)(self, prev_ix)];
176 if (should_reroot_tree) {
177 forest[node_left] = (uint32_t)prev_ix;
179 node_left =
FN(RightChildIndex)(self, prev_ix);
180 prev_ix = forest[node_left];
182 best_len_right =
len;
183 if (should_reroot_tree) {
184 forest[node_right] = (uint32_t)prev_ix;
186 node_right =
FN(LeftChildIndex)(self, prev_ix);
187 prev_ix = forest[node_right];
205 const size_t ring_buffer_mask,
const size_t cur_ix,
206 const size_t max_length,
const size_t max_backward,
210 const size_t cur_ix_masked = cur_ix & ring_buffer_mask;
212 const size_t short_match_max_backward =
214 size_t stop = cur_ix - short_match_max_backward;
217 if (cur_ix < short_match_max_backward) { stop = 0; }
218 for (
i = cur_ix - 1;
i > stop && best_len <= 2; --
i) {
220 const size_t backward = cur_ix - prev_ix;
224 prev_ix &= ring_buffer_mask;
225 if (
data[cur_ix_masked] !=
data[prev_ix] ||
226 data[cur_ix_masked + 1] !=
data[prev_ix + 1]) {
231 FindMatchLengthWithLimit(&
data[prev_ix], &
data[cur_ix_masked],
233 if (
len > best_len) {
235 InitBackwardMatch(matches++, backward,
len);
239 if (best_len < max_length) {
240 matches =
FN(StoreAndFindMatches)(self,
data, cur_ix,
241 ring_buffer_mask, max_length, max_backward, &best_len, matches);
244 dict_matches[
i] = kInvalidMatch;
247 size_t minlen =
BROTLI_MAX(
size_t, 4, best_len + 1);
249 &
data[cur_ix_masked], minlen, max_length, &dict_matches[0])) {
253 for (l = minlen; l <= maxlen; ++l) {
254 uint32_t dict_id = dict_matches[l];
255 if (dict_id < kInvalidMatch) {
256 size_t distance = dictionary_distance + (dict_id >> 5) + 1;
257 if (distance <= params->dist.max_distance) {
258 InitDictionaryBackwardMatch(matches++, distance, l, dict_id & 31);
264 return (
size_t)(matches - orig_matches);
272 const size_t mask,
const size_t ix) {
281 const size_t ix_start,
const size_t ix_end) {
284 if (ix_start + 63 <= ix_end) {
287 if (ix_start + 512 <=
i) {
288 for (; j <
i; j += 8) {
289 FN(Store)(self,
data, mask, j);
292 for (;
i < ix_end; ++
i) {
293 FN(Store)(self,
data, mask,
i);
299 size_t num_bytes,
size_t position,
const uint8_t* ringbuffer,
300 size_t ringbuffer_mask) {
301 if (num_bytes >=
FN(HashTypeLength)() - 1 &&
307 const size_t i_end =
BROTLI_MIN(
size_t, position, i_start + num_bytes);
309 for (
i = i_start;
i < i_end; ++
i) {
314 const size_t max_backward =
321 FN(StoreAndFindMatches)(self, ringbuffer,
i, ringbuffer_mask,
329#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