| 1 | /* NOLINT(build/header_guard) */cxx . . $ `<file>/c/enc/hash_composite_inc.h`/ |
| 2 | /* Copyright 2018 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, HASHER_A, HASHER_B */ |
| 9 | |
| 10 | /* Composite hasher: This hasher allows to combine two other hashers, HASHER_A |
| 11 | and HASHER_B. */ |
| 12 | |
| 13 | #define HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`! HASHERcxx . . $ `c/enc/hash.h:354:9`!() |
| 14 | |
| 15 | #define FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(X) EXPAND_CATcxx . . $ `c/enc/hash.h:223:9`!(X, HASHER_Acxx . . $ `c/enc/hash.h:355:9`!) |
| 16 | #define FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(X) EXPAND_CATcxx . . $ `c/enc/hash.h:223:9`!(X, HASHER_Bcxx . . $ `c/enc/hash.h:356:9`!) |
| 17 | |
| 18 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t FNcxx . . $ `c/enc/hash.h:225:9`!(HashTypeLength)(void) { |
| 19 | size_t a = FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(HashTypeLength)(); |
| 20 | size_t b = FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(HashTypeLength)(); |
| 21 | return a > b ? a : b; |
| 22 | } |
| 23 | |
| 24 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! size_t FNcxx . . $ `c/enc/hash.h:225:9`!(StoreLookahead)(void) { |
| 25 | size_t a = FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(StoreLookahead)(); |
| 26 | size_t b = FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(StoreLookahead)(); |
| 27 | return a > b ? a : b; |
| 28 | } |
| 29 | |
| 30 | typedef struct HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`! { |
| 31 | HASHER_Acxx . . $ `c/enc/hash.h:355:9`! hacxx . . $ H35#ha.; |
| 32 | HASHER_Bcxx . . $ `c/enc/hash.h:356:9`! hbcxx . . $ H35#hb.; |
| 33 | HasherCommoncxx . . $ HasherCommon# ha_commoncxx . . $ H35#ha_common.; |
| 34 | HasherCommoncxx . . $ HasherCommon# hb_commoncxx . . $ H35#hb_common.; |
| 35 | |
| 36 | /* Shortcuts. */ |
| 37 | HasherCommoncxx . . $ HasherCommon#* commoncxx . . $ H35#common.; |
| 38 | |
| 39 | BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! freshcxx . . $ H35#fresh.; |
| 40 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* paramscxx . . $ H35#params.; |
| 41 | } HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!; |
| 42 | |
| 43 | static void FNcxx . . $ `c/enc/hash.h:225:9`!(Initialize)(HasherCommoncxx . . $ HasherCommon#* common, |
| 44 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params) { |
| 45 | self->commoncxx . . $ H35#common. = common; |
| 46 | |
| 47 | self->ha_commoncxx . . $ H35#ha_common. = *self->commoncxx . . $ H35#common.; |
| 48 | self->hb_commoncxx . . $ H35#hb_common. = *self->commoncxx . . $ H35#common.; |
| 49 | self->freshcxx . . $ H35#fresh. = BROTLI_TRUEcxx . . $ `c/include/brotli/types.h:51:9`!; |
| 50 | self->paramscxx . . $ H35#params. = params; |
| 51 | /* TODO(lode): Initialize of the hashers is deferred to Prepare (and params |
| 52 | remembered here) because we don't get the one_shot and input_size params |
| 53 | here that are needed to know the memory size of them. Instead provide |
| 54 | those params to all hashers FN(Initialize) */ |
| 55 | } |
| 56 | |
| 57 | static void FNcxx . . $ `c/enc/hash.h:225:9`!(Prepare)( |
| 58 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! one_shot, |
| 59 | size_t input_size, const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data) { |
| 60 | if (self->freshcxx . . $ H35#fresh.) { |
| 61 | self->freshcxx . . $ H35#fresh. = BROTLI_FALSEcxx . . $ `c/include/brotli/types.h:53:9`!; |
| 62 | self->ha_commoncxx . . $ H35#ha_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[0] = self->commoncxx . . $ H35#common.->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[0]; |
| 63 | self->ha_commoncxx . . $ H35#ha_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[1] = self->commoncxx . . $ H35#common.->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[1]; |
| 64 | self->ha_commoncxx . . $ H35#ha_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[2] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 65 | self->ha_commoncxx . . $ H35#ha_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[3] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 66 | self->hb_commoncxx . . $ H35#hb_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[0] = self->commoncxx . . $ H35#common.->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[2]; |
| 67 | self->hb_commoncxx . . $ H35#hb_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[1] = self->commoncxx . . $ H35#common.->extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[3]; |
| 68 | self->hb_commoncxx . . $ H35#hb_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[2] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 69 | self->hb_commoncxx . . $ H35#hb_common..extracxx . . $ $anonymous_type_5b62deaf4afff4b7_0#extra.[3] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 70 | |
| 71 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(Initialize)(&self->ha_commoncxx . . $ H35#ha_common., &self->hacxx . . $ H35#ha., self->paramscxx . . $ H35#params.); |
| 72 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(Initialize)(&self->hb_commoncxx . . $ H35#hb_common., &self->hbcxx . . $ H35#hb., self->paramscxx . . $ H35#params.); |
| 73 | } |
| 74 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(Prepare)(&self->hacxx . . $ H35#ha., one_shot, input_size, data); |
| 75 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(Prepare)(&self->hbcxx . . $ H35#hb., one_shot, input_size, data); |
| 76 | } |
| 77 | |
| 78 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(HashMemAllocInBytes)( |
| 79 | const BrotliEncoderParamscxx . . $ BrotliEncoderParams#* params, BROTLI_BOOLcxx . . $ `c/include/brotli/types.h:49:9`! one_shot, |
| 80 | size_t input_size, size_t* alloc_size) { |
| 81 | size_t alloc_size_a[4] = {0}; |
| 82 | size_t alloc_size_b[4] = {0}; |
| 83 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(HashMemAllocInBytes)(params, one_shot, input_size, alloc_size_a); |
| 84 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(HashMemAllocInBytes)(params, one_shot, input_size, alloc_size_b); |
| 85 | /* Should never happen. */ |
| 86 | if (alloc_size_a[2] != 0 || alloc_size_a[3] != 0) exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!); |
| 87 | if (alloc_size_b[2] != 0 || alloc_size_b[3] != 0) exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!); |
| 88 | alloc_size[0] = alloc_size_a[0]; |
| 89 | alloc_size[1] = alloc_size_a[1]; |
| 90 | alloc_size[2] = alloc_size_b[0]; |
| 91 | alloc_size[3] = alloc_size_b[1]; |
| 92 | } |
| 93 | |
| 94 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(Store)(HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 95 | const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, const size_t mask, const size_t ix) { |
| 96 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(Store)(&self->hacxx . . $ H35#ha., data, mask, ix); |
| 97 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(Store)(&self->hbcxx . . $ H35#hb., data, mask, ix); |
| 98 | } |
| 99 | |
| 100 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(StoreRange)( |
| 101 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, |
| 102 | const size_t mask, const size_t ix_start, |
| 103 | const size_t ix_end) { |
| 104 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(StoreRange)(&self->hacxx . . $ H35#ha., data, mask, ix_start, ix_end); |
| 105 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(StoreRange)(&self->hbcxx . . $ H35#hb., data, mask, ix_start, ix_end); |
| 106 | } |
| 107 | |
| 108 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(StitchToPreviousBlock)( |
| 109 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 110 | size_t num_bytes, size_t position, const uint8_tcxx . . $ uint8_t#* ringbuffer, |
| 111 | size_t ring_buffer_mask) { |
| 112 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(StitchToPreviousBlock)(&self->hacxx . . $ H35#ha., num_bytes, position, |
| 113 | ringbuffer, ring_buffer_mask); |
| 114 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(StitchToPreviousBlock)(&self->hbcxx . . $ H35#hb., num_bytes, position, |
| 115 | ringbuffer, ring_buffer_mask); |
| 116 | } |
| 117 | |
| 118 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(PrepareDistanceCache)( |
| 119 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, int* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! distance_cache) { |
| 120 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(PrepareDistanceCache)(&self->hacxx . . $ H35#ha., distance_cache); |
| 121 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(PrepareDistanceCache)(&self->hbcxx . . $ H35#hb., distance_cache); |
| 122 | } |
| 123 | |
| 124 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! void FNcxx . . $ `c/enc/hash.h:225:9`!(FindLongestMatch)( |
| 125 | HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`!* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! self, |
| 126 | const BrotliEncoderDictionarycxx . . $ BrotliEncoderDictionary#* dictionary, |
| 127 | const uint8_tcxx . . $ uint8_t#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! data, const size_t ring_buffer_mask, |
| 128 | const int* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! distance_cache, const size_t cur_ix, |
| 129 | const size_t max_length, const size_t max_backward, |
| 130 | const size_t dictionary_distance, const size_t max_distance, |
| 131 | HasherSearchResultcxx . . $ HasherSearchResult#* BROTLI_RESTRICTcxx . . $ `c/common/platform.h:82:9`! out) { |
| 132 | FN_Acxx . . $ `c/enc/hash_composite_inc.h:15:9`!(FindLongestMatch)(&self->hacxx . . $ H35#ha., dictionary, data, ring_buffer_mask, |
| 133 | distance_cache, cur_ix, max_length, max_backward, dictionary_distance, |
| 134 | max_distance, out); |
| 135 | FN_Bcxx . . $ `c/enc/hash_composite_inc.h:16:9`!(FindLongestMatch)(&self->hbcxx . . $ H35#hb., dictionary, data, ring_buffer_mask, |
| 136 | distance_cache, cur_ix, max_length, max_backward, dictionary_distance, |
| 137 | max_distance, out); |
| 138 | } |
| 139 | |
| 140 | #undef HashCompositecxx . . $ `c/enc/hash_composite_inc.h:13:9`! |