| 1 | /* Copyright 2025 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | Distributed under MIT license. |
| 4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
| 5 | */ |
| 6 | |
| 7 | /* Basic common hash functions / constants. */ |
| 8 | |
| 9 | #ifndef THIRD_PARTY_BROTLI_ENC_HASH_BASE_H_ |
| 10 | #define THIRD_PARTY_BROTLI_ENC_HASH_BASE_H_cxx . . $ `c/enc/hash_base.h:10:9`! |
| 11 | |
| 12 | #include "../common/platform.h"cxx . . $ `<file>/c/common/platform.h`/ |
| 13 | |
| 14 | /* kHashMul32 multiplier has these properties: |
| 15 | * The multiplier must be odd. Otherwise we may lose the highest bit. |
| 16 | * No long streaks of ones or zeros. |
| 17 | * There is no effort to ensure that it is a prime, the oddity is enough |
| 18 | for this use. |
| 19 | * The number has been tuned heuristically against compression benchmarks. */ |
| 20 | static const uint32_tcxx . . $ uint32_t# kHashMul32cxx . . $ kHashMul32. = 0x1E35A7BD; |
| 21 | static const uint64_tcxx . . $ uint64_t# kHashMul64cxx . . $ kHashMul64. = |
| 22 | BROTLI_MAKE_UINT64_Tcxx . . $ `c/include/brotli/types.h:57:9`!(0x1FE35A7Bu, 0xD3579BD3u); |
| 23 | |
| 24 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# Hash14cxx . . $ Hash14(ca1608e2c87725e2).(const uint8_tcxx . . $ uint8_t#* data) { |
| 25 | uint32_tcxx . . $ uint32_t# h = BROTLI_UNALIGNED_LOAD32LEcxx . . $ `c/common/platform.h:379:9`!(data) * kHashMul32cxx . . $ kHashMul32.; |
| 26 | /* The higher bits contain more mixture from the multiplication, |
| 27 | so we take our results from there. */ |
| 28 | return h >> (32 - 14); |
| 29 | } |
| 30 | |
| 31 | static BROTLI_INLINEcxx . . $ `c/common/platform.h:119:9`! uint32_tcxx . . $ uint32_t# Hash15cxx . . $ Hash15(ca1608e2c87725e2).(const uint8_tcxx . . $ uint8_t#* data) { |
| 32 | 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 - 15); |
| 36 | } |
| 37 | |
| 38 | #endif // THIRD_PARTY_BROTLI_ENC_HASH_BASE_H_ |