hash.cc (2213B)
1 // Copyright 2018 The Abseil Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "absl/hash/internal/hash.h" 16 17 #include <cstddef> 18 #include <cstdint> 19 #include <type_traits> 20 21 #include "absl/base/attributes.h" 22 #include "absl/base/config.h" 23 #include "absl/hash/internal/low_level_hash.h" 24 25 namespace absl { 26 ABSL_NAMESPACE_BEGIN 27 namespace hash_internal { 28 29 uint64_t MixingHashState::CombineLargeContiguousImpl32( 30 uint64_t state, const unsigned char* first, size_t len) { 31 while (len >= PiecewiseChunkSize()) { 32 state = Mix( 33 state ^ hash_internal::CityHash32(reinterpret_cast<const char*>(first), 34 PiecewiseChunkSize()), 35 kMul); 36 len -= PiecewiseChunkSize(); 37 first += PiecewiseChunkSize(); 38 } 39 // Handle the remainder. 40 return CombineContiguousImpl(state, first, len, 41 std::integral_constant<int, 4>{}); 42 } 43 44 uint64_t MixingHashState::CombineLargeContiguousImpl64( 45 uint64_t state, const unsigned char* first, size_t len) { 46 while (len >= PiecewiseChunkSize()) { 47 state = Mix(state ^ Hash64(first, PiecewiseChunkSize()), kMul); 48 len -= PiecewiseChunkSize(); 49 first += PiecewiseChunkSize(); 50 } 51 // Handle the remainder. 52 return CombineContiguousImpl(state, first, len, 53 std::integral_constant<int, 8>{}); 54 } 55 56 ABSL_CONST_INIT const void* const MixingHashState::kSeed = &kSeed; 57 58 uint64_t MixingHashState::LowLevelHashImpl(const unsigned char* data, 59 size_t len) { 60 return LowLevelHashLenGt32(data, len, Seed(), &kStaticRandomData[0]); 61 } 62 63 } // namespace hash_internal 64 ABSL_NAMESPACE_END 65 } // namespace absl