| 1 | /* NOLINT(build/header_guard) */cxx . . $ `<file>/c/enc/hash_forgetful_chain_inc.h`/ |
| 2 | /* Copyright 2016 Google Inc. All Rights Reserved. |
| 3 | |
| 4 | Distributed under MIT license. |
| 5 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 6 | */ |
| 7 | |
| 8 | /* template parameters: FN, BUCKET_BITS, NUM_BANKS, BANK_BITS, |
| 9 | NUM_LAST_DISTANCES_TO_CHECK */ |
| 10 | |
| 11 | /* A (forgetful) hash table to the data seen by the compressor, to |
| 12 | help create backward references to previous data. |
| 13 | |
| 14 | Hashes are stored in chains which are bucketed to groups. Group of chains |
| 15 | share a storage "bank". When more than "bank size" chain nodes are added, |
| 16 | oldest nodes are replaced; this way several chains may share a tail. */ |
| 17 | |
| 18 | #define HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`! HASHERcxx . . $ `c/enc/hash.h:296:9`!() |
| 19 | |
| 20 | #define BANK_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:20:9`! (1 << BANK_BITScxx . . $ `c/enc/hash.h:295:9`!) |
| 21 | |
| 22 | /* Number of hash buckets. */ |
| 23 | #define BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`! (1 << BUCKET_BITScxx . . $ `c/enc/hash.h:291:9`!) |
| 24 | |
| 25 | #define CAPPED_CHAINScxx . . $ `c/enc/hash_forgetful_chain_inc.h:25:9`! 0 |
| 26 | |
| 27 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t FNcxx . . $ `c/enc/hash.h:225:9`!(HashTypeLength)(void) { return 4; } |
| 28 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t FNcxx . . $ `c/enc/hash.h:225:9`!(StoreLookahead)(void) { return 4; } |
| 29 | |
| 30 | /* HashBytes is the function that chooses the bucket to place the address in.*/ |
| 31 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t FNcxx . . $ `c/enc/hash.h:225:9`!(HashBytes)(const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data) { |
| 32 | const uint32_tcxx . . $ uint32_t# h = BROTLI_UNALIGNED_LOAD32LEcxx . . $ `c/common/platform.h:379:9`!(data) * kHashMul32cxx . . $ kHashMul32.; |
| 33 | /* The higher bits contain more mixture from the multiplication, |
| 34 | so we take our results from there. */ |
| 35 | return h >> (32 - BUCKET_BITScxx . . $ `c/enc/hash.h:291:9`!); |
| 36 | } |
| 37 | |
| 38 | typedef struct FNcxx . . $ `c/enc/hash.h:225:9`!(Slot) { |
| 39 | uint16_tcxx . . $ uint16_t# deltacxx . . $ SlotH40#delta.; |
| 40 | uint16_tcxx . . $ uint16_t# nextcxx . . $ SlotH40#next.; |
| 41 | } FNcxx . . $ `c/enc/hash.h:225:9`!(Slot); |
| 42 | |
| 43 | typedef struct FNcxx . . $ `c/enc/hash.h:225:9`!(Bank) { |
| 44 | FNcxx . . $ `c/enc/hash.h:225:9`!(Slot) slotscxx . . $ BankH40#slots.[BANK_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:20:9`!]; |
| 45 | } FNcxx . . $ `c/enc/hash.h:225:9`!(Bank); |
| 46 | |
| 47 | typedef struct HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`! { |
| 48 | uint16_tcxx . . $ uint16_t# free_slot_idxcxx . . $ H40#free_slot_idx.[NUM_BANKScxx . . $ `c/enc/hash.h:294:9`!]; /* Up to 1KiB. Move to dynamic? */ |
| 49 | size_t max_hopscxx . . $ H40#max_hops.; |
| 50 | |
| 51 | /* Shortcuts. */ |
| 52 | void* extracxx . . $ H40#extra.[2]; |
| 53 | HasherCommoncxx . . $ HasherCommon#* commoncxx . . $ H40#common.; |
| 54 | |
| 55 | /* --- Dynamic size members --- */ |
| 56 | |
| 57 | /* uint32_t addr[BUCKET_SIZE]; */ |
| 58 | |
| 59 | /* uint16_t head[BUCKET_SIZE]; */ |
| 60 | |
| 61 | /* Truncated hash used for quick rejection of "distance cache" candidates. */ |
| 62 | /* uint8_t tiny_hash[65536];*/ |
| 63 | |
| 64 | /* FN(Bank) banks[NUM_BANKS]; */ |
| 65 | } HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!; |
| 66 | |
| 67 | static uint32_tcxx . . $ uint32_t#* FNcxx . . $ `c/enc/hash.h:225:9`!(Addr)(void* extra) { |
| 68 | return (uint32_tcxx . . $ uint32_t#*)extra; |
| 69 | } |
| 70 | |
| 71 | static uint16_tcxx . . $ uint16_t#* FNcxx . . $ `c/enc/hash.h:225:9`!(Head)(void* extra) { |
| 72 | return (uint16_tcxx . . $ uint16_t#*)(&FNcxx . . $ `c/enc/hash.h:225:9`!(Addr)(extra)[BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`!]); |
| 73 | } |
| 74 | |
| 75 | static uint8_tcxx . . $ uint8_t#* FNcxx . . $ `c/enc/hash.h:225:9`!(TinyHash)(void* extra) { |
| 76 | return (uint8_tcxx . . $ uint8_t#*)(&FNcxx . . $ `c/enc/hash.h:225:9`!(Head)(extra)[BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`!]); |
| 77 | } |
| 78 | |
| 79 | static FNcxx . . $ `c/enc/hash.h:225:9`!(Bank)* FNcxx . . $ `c/enc/hash.h:225:9`!(Banks)(void* extra) { |
| 80 | return (FNcxx . . $ `c/enc/hash.h:225:9`!(Bank)*)(extra); |
| 81 | } |
| 82 | |
| 83 | static void FNcxx . . $ `c/enc/hash.h:225:9`!(Initialize)( |
| 84 | HasherCommoncxx . . $ HasherCommon#* common, HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 85 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params) { |
| 86 | self->commoncxx . . $ H40#common. = common; |
| 87 | self->extracxx . . $ H40#extra.[0] = common->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[0]; |
| 88 | self->extracxx . . $ H40#extra.[1] = common->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[1]; |
| 89 | |
| 90 | self->max_hopscxx . . $ H40#max_hops. = (params->qualitycxx . . $ BrotliEncoderParams#quality. > 6 ? 7u : 8u) << (params->qualitycxx . . $ BrotliEncoderParams#quality. - 4); |
| 91 | } |
| 92 | |
| 93 | static void FNcxx . . $ `c/enc/hash.h:225:9`!(Prepare)( |
| 94 | HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! one_shot, |
| 95 | size_t input_size, const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data) { |
| 96 | uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! addr = FNcxx . . $ `c/enc/hash.h:225:9`!(Addr)(self->extracxx . . $ H40#extra.[0]); |
| 97 | uint16_tcxx . . $ uint16_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! head = FNcxx . . $ `c/enc/hash.h:225:9`!(Head)(self->extracxx . . $ H40#extra.[0]); |
| 98 | uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! tiny_hash = FNcxx . . $ `c/enc/hash.h:225:9`!(TinyHash)(self->extracxx . . $ H40#extra.[0]); |
| 99 | /* Partial preparation is 100 times slower (per socket). */ |
| 100 | size_t partial_prepare_threshold = BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`! >> 6; |
| 101 | if (one_shot && input_size <= partial_prepare_threshold) { |
| 102 | size_t i; |
| 103 | for (i = 0; i < input_size; ++i) { |
| 104 | size_t bucket = FNcxx . . $ `c/enc/hash.h:225:9`!(HashBytes)(&data[i]); |
| 105 | /* See InitEmpty comment. */ |
| 106 | addr[bucket] = 0xCCCCCCCC; |
| 107 | head[bucket] = 0xCCCC; |
| 108 | } |
| 109 | } else { |
| 110 | /* Fill |addr| array with 0xCCCCCCCC value. Because of wrapping, position |
| 111 | processed by hasher never reaches 3GB + 64M; this makes all new chains |
| 112 | to be terminated after the first node. */ |
| 113 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(addr, 0xCC, sizeof(uint32_tcxx . . $ uint32_t#) * BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`!); |
| 114 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(head, 0, sizeof(uint16_tcxx . . $ uint16_t#) * BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`!); |
| 115 | } |
| 116 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(tiny_hash, 0, sizeof(uint8_tcxx . . $ uint8_t#) * 65536); |
| 117 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(self->free_slot_idxcxx . . $ H40#free_slot_idx., 0, sizeof(self->free_slot_idxcxx . . $ H40#free_slot_idx.)); |
| 118 | } |
| 119 | |
| 120 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(HashMemAllocInBytes)( |
| 121 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! one_shot, |
| 122 | size_t input_size, size_t* alloc_size) { |
| 123 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(params); |
| 124 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(one_shot); |
| 125 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(input_size); |
| 126 | alloc_size[0] = sizeof(uint32_tcxx . . $ uint32_t#) * BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`! + |
| 127 | sizeof(uint16_tcxx . . $ uint16_t#) * BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`! + sizeof(uint8_tcxx . . $ uint8_t#) * 65536; |
| 128 | alloc_size[1] = sizeof(FNcxx . . $ `c/enc/hash.h:225:9`!(Bank)) * NUM_BANKScxx . . $ `c/enc/hash.h:294:9`!; |
| 129 | } |
| 130 | |
| 131 | /* Look at 4 bytes at &data[ix & mask]. Compute a hash from these, and prepend |
| 132 | node to corresponding chain; also update tiny_hash for current position. */ |
| 133 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 134 | const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, const size_t mask, const size_t ix) { |
| 135 | uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! addr = FNcxx . . $ `c/enc/hash.h:225:9`!(Addr)(self->extracxx . . $ H40#extra.[0]); |
| 136 | uint16_tcxx . . $ uint16_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! head = FNcxx . . $ `c/enc/hash.h:225:9`!(Head)(self->extracxx . . $ H40#extra.[0]); |
| 137 | uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! tiny_hash = FNcxx . . $ `c/enc/hash.h:225:9`!(TinyHash)(self->extracxx . . $ H40#extra.[0]); |
| 138 | FNcxx . . $ `c/enc/hash.h:225:9`!(Bank)* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! banks = FNcxx . . $ `c/enc/hash.h:225:9`!(Banks)(self->extracxx . . $ H40#extra.[1]); |
| 139 | const size_t key = FNcxx . . $ `c/enc/hash.h:225:9`!(HashBytes)(&data[ix & mask]); |
| 140 | const size_t bank = key & (NUM_BANKScxx . . $ `c/enc/hash.h:294:9`! - 1); |
| 141 | const size_t idx = self->free_slot_idxcxx . . $ H40#free_slot_idx.[bank]++ & (BANK_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:20:9`! - 1); |
| 142 | size_t delta = ix - addr[key]; |
| 143 | tiny_hash[(uint16_tcxx . . $ uint16_t#)ix] = (uint8_tcxx . . $ uint8_t#)key; |
| 144 | if (delta > 0xFFFF) delta = CAPPED_CHAINScxx . . $ `c/enc/hash_forgetful_chain_inc.h:25:9`! ? 0 : 0xFFFF; |
| 145 | banks[bank].slotscxx . . $ BankH40#slots.[idx].deltacxx . . $ SlotH40#delta. = (uint16_tcxx . . $ uint16_t#)delta; |
| 146 | banks[bank].slotscxx . . $ BankH40#slots.[idx].nextcxx . . $ SlotH40#next. = head[key]; |
| 147 | addr[key] = (uint32_tcxx . . $ uint32_t#)ix; |
| 148 | head[key] = (uint16_tcxx . . $ uint16_t#)idx; |
| 149 | } |
| 150 | |
| 151 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(StoreRange)( |
| 152 | HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 153 | const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, const size_t mask, |
| 154 | const size_t ix_start, const size_t ix_end) { |
| 155 | size_t i; |
| 156 | for (i = ix_start; i < ix_end; ++i) { |
| 157 | FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(self, data, mask, i); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(StitchToPreviousBlock)( |
| 162 | HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 163 | size_t num_bytes, size_t position, const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 164 | size_t ring_buffer_mask) { |
| 165 | if (num_bytes >= FNcxx . . $ `c/enc/hash.h:225:9`!(HashTypeLength)() - 1 && position >= 3) { |
| 166 | /* Prepare the hashes for three last bytes of the last write. |
| 167 | These could not be calculated before, since they require knowledge |
| 168 | of both the previous and the current block. */ |
| 169 | FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(self, ringbuffer, ring_buffer_mask, position - 3); |
| 170 | FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(self, ringbuffer, ring_buffer_mask, position - 2); |
| 171 | FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(self, ringbuffer, ring_buffer_mask, position - 1); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(PrepareDistanceCache)( |
| 176 | HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 177 | int* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! distance_cache) { |
| 178 | BROTLI_UNUSEDcxx . . $ `c/common/platform.h:514:9`!(self); |
| 179 | PrepareDistanceCachecxx . . $ PrepareDistanceCache(621ccea12ecf5b06).(distance_cache, NUM_LAST_DISTANCES_TO_CHECKcxx . . $ `c/enc/hash.h:293:9`!); |
| 180 | } |
| 181 | |
| 182 | /* Find a longest backward match of &data[cur_ix] up to the length of |
| 183 | max_length and stores the position cur_ix in the hash table. |
| 184 | |
| 185 | REQUIRES: FN(PrepareDistanceCache) must be invoked for current distance cache |
| 186 | values; if this method is invoked repeatedly with the same distance |
| 187 | cache values, it is enough to invoke FN(PrepareDistanceCache) once. |
| 188 | |
| 189 | Does not look for matches longer than max_length. |
| 190 | Does not look for matches further away than max_backward. |
| 191 | Writes the best match into |out|. |
| 192 | |out|->score is updated only if a better match is found. */ |
| 193 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(FindLongestMatch)( |
| 194 | HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 195 | const BrotliEncoderDictionarycxx . . $ BrotliEncoderDictionary#* dictionary, |
| 196 | const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, const size_t ring_buffer_mask, |
| 197 | const int* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! distance_cache, |
| 198 | const size_t cur_ix, const size_t max_length, const size_t max_backward, |
| 199 | const size_t dictionary_distance, const size_t max_distance, |
| 200 | HasherSearchResultcxx . . $ HasherSearchResult#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! out) { |
| 201 | uint32_tcxx . . $ uint32_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! addr = FNcxx . . $ `c/enc/hash.h:225:9`!(Addr)(self->extracxx . . $ H40#extra.[0]); |
| 202 | uint16_tcxx . . $ uint16_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! head = FNcxx . . $ `c/enc/hash.h:225:9`!(Head)(self->extracxx . . $ H40#extra.[0]); |
| 203 | uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! tiny_hashes = FNcxx . . $ `c/enc/hash.h:225:9`!(TinyHash)(self->extracxx . . $ H40#extra.[0]); |
| 204 | FNcxx . . $ `c/enc/hash.h:225:9`!(Bank)* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! banks = FNcxx . . $ `c/enc/hash.h:225:9`!(Banks)(self->extracxx . . $ H40#extra.[1]); |
| 205 | const size_t cur_ix_masked = cur_ix & ring_buffer_mask; |
| 206 | /* Don't accept a short copy from far away. */ |
| 207 | score_tcxx . . $ `c/enc/hash.h:57:9`! min_score = out->scorecxx . . $ HasherSearchResult#score.; |
| 208 | score_tcxx . . $ `c/enc/hash.h:57:9`! best_score = out->scorecxx . . $ HasherSearchResult#score.; |
| 209 | size_t best_len = out->lencxx . . $ HasherSearchResult#len.; |
| 210 | size_t i; |
| 211 | const size_t key = FNcxx . . $ `c/enc/hash.h:225:9`!(HashBytes)(&data[cur_ix_masked]); |
| 212 | const uint8_tcxx . . $ uint8_t# tiny_hash = (uint8_tcxx . . $ uint8_t#)(key); |
| 213 | out->lencxx . . $ HasherSearchResult#len. = 0; |
| 214 | out->len_code_deltacxx . . $ HasherSearchResult#len_code_delta. = 0; |
| 215 | |
| 216 | BROTLI_DCHECKcxx . . $ `c/common/platform.h:473:9`!(cur_ix_masked + max_length <= ring_buffer_mask); |
| 217 | |
| 218 | /* Try last distance first. */ |
| 219 | for (i = 0; i < NUM_LAST_DISTANCES_TO_CHECKcxx . . $ `c/enc/hash.h:293:9`!; ++i) { |
| 220 | const size_t backward = (size_t)distance_cache[i]; |
| 221 | size_t prev_ix = (cur_ix - backward); |
| 222 | /* For distance code 0 we want to consider 2-byte matches. */ |
| 223 | if (i > 0 && tiny_hashes[(uint16_tcxx . . $ uint16_t#)prev_ix] != tiny_hash) continue; |
| 224 | if (prev_ix >= cur_ix || backward > max_backward) { |
| 225 | continue; |
| 226 | } |
| 227 | prev_ix &= ring_buffer_mask; |
| 228 | { |
| 229 | const size_t len = FindMatchLengthWithLimitcxx . . $ FindMatchLengthWithLimit(c2ccccc71581acc8).(&data[prev_ix], |
| 230 | &data[cur_ix_masked], |
| 231 | max_length); |
| 232 | if (len >= 2) { |
| 233 | score_tcxx . . $ `c/enc/hash.h:57:9`! score = BackwardReferenceScoreUsingLastDistancecxx . . $ BackwardReferenceScoreUsingLastDistance(ecdaa1632f49f591).(len); |
| 234 | if (best_score < score) { |
| 235 | if (i != 0) score -= BackwardReferencePenaltyUsingLastDistancecxx . . $ BackwardReferencePenaltyUsingLastDistance(ecdaa1632f49f591).(i); |
| 236 | if (best_score < score) { |
| 237 | best_score = score; |
| 238 | best_len = len; |
| 239 | out->lencxx . . $ HasherSearchResult#len. = best_len; |
| 240 | out->distancecxx . . $ HasherSearchResult#distance. = backward; |
| 241 | out->scorecxx . . $ HasherSearchResult#score. = best_score; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | /* we require matches of len >4, so increase best_len to 3, so we can compare |
| 248 | * 4 bytes all the time. */ |
| 249 | if (best_len < 3) { |
| 250 | best_len = 3; |
| 251 | } |
| 252 | { |
| 253 | const size_t bank = key & (NUM_BANKScxx . . $ `c/enc/hash.h:294:9`! - 1); |
| 254 | size_t backward = 0; |
| 255 | size_t hops = self->max_hopscxx . . $ H40#max_hops.; |
| 256 | size_t delta = cur_ix - addr[key]; |
| 257 | size_t slot = head[key]; |
| 258 | while (hops--) { |
| 259 | size_t prev_ix; |
| 260 | size_t last = slot; |
| 261 | backward += delta; |
| 262 | if (backward > max_backward || (CAPPED_CHAINScxx . . $ `c/enc/hash_forgetful_chain_inc.h:25:9`! && !delta)) break; |
| 263 | prev_ix = (cur_ix - backward) & ring_buffer_mask; |
| 264 | slot = banks[bank].slotscxx . . $ BankH40#slots.[last].nextcxx . . $ SlotH40#next.; |
| 265 | delta = banks[bank].slotscxx . . $ BankH40#slots.[last].deltacxx . . $ SlotH40#delta.; |
| 266 | if (cur_ix_masked + best_len > ring_buffer_mask || |
| 267 | prev_ix + best_len > ring_buffer_mask || |
| 268 | /* compare 4 bytes ending at best_len + 1 */ |
| 269 | BrotliUnalignedRead32cxx . . $ BrotliUnalignedRead32(b11f534102b1ad6).(&data[cur_ix_masked + best_len - 3]) != |
| 270 | BrotliUnalignedRead32cxx . . $ BrotliUnalignedRead32(b11f534102b1ad6).(&data[prev_ix + best_len - 3])) { |
| 271 | continue; |
| 272 | } |
| 273 | { |
| 274 | const size_t len = FindMatchLengthWithLimitcxx . . $ FindMatchLengthWithLimit(c2ccccc71581acc8).(&data[prev_ix], |
| 275 | &data[cur_ix_masked], |
| 276 | max_length); |
| 277 | if (len >= 4) { |
| 278 | /* Comparing for >= 3 does not change the semantics, but just saves |
| 279 | for a few unnecessary binary logarithms in backward reference |
| 280 | score, since we are not interested in such short matches. */ |
| 281 | score_tcxx . . $ `c/enc/hash.h:57:9`! score = BackwardReferenceScorecxx . . $ BackwardReferenceScore(80bad76eed2d2579).(len, backward); |
| 282 | if (best_score < score) { |
| 283 | best_score = score; |
| 284 | best_len = len; |
| 285 | out->lencxx . . $ HasherSearchResult#len. = best_len; |
| 286 | out->distancecxx . . $ HasherSearchResult#distance. = backward; |
| 287 | out->scorecxx . . $ HasherSearchResult#score. = best_score; |
| 288 | } |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(self, data, ring_buffer_mask, cur_ix); |
| 293 | } |
| 294 | if (out->scorecxx . . $ HasherSearchResult#score. == min_score) { |
| 295 | SearchInStaticDictionarycxx . . $ SearchInStaticDictionary(e21d390e7ad53fe0).(dictionary, |
| 296 | self->commoncxx . . $ H40#common., &data[cur_ix_masked], max_length, dictionary_distance, |
| 297 | max_distance, out, BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!); |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | #undef BANK_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:20:9`! |
| 302 | #undef BUCKET_SIZEcxx . . $ `c/enc/hash_forgetful_chain_inc.h:23:9`! |
| 303 | #undef CAPPED_CHAINScxx . . $ `c/enc/hash_forgetful_chain_inc.h:25:9`! |
| 304 | |
| 305 | #undef HashForgetfulChaincxx . . $ `c/enc/hash_forgetful_chain_inc.h:18:9`! |