Coverage Report

Created: 2023-09-25 06:27

/src/abseil-cpp/absl/hash/internal/hash.cc
Line
Count
Source (jump to first uncovered line)
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
namespace absl {
18
ABSL_NAMESPACE_BEGIN
19
namespace hash_internal {
20
21
uint64_t MixingHashState::CombineLargeContiguousImpl32(
22
0
    uint64_t state, const unsigned char* first, size_t len) {
23
0
  while (len >= PiecewiseChunkSize()) {
24
0
    state = Mix(state,
25
0
                hash_internal::CityHash32(reinterpret_cast<const char*>(first),
26
0
                                          PiecewiseChunkSize()));
27
0
    len -= PiecewiseChunkSize();
28
0
    first += PiecewiseChunkSize();
29
0
  }
30
  // Handle the remainder.
31
0
  return CombineContiguousImpl(state, first, len,
32
0
                               std::integral_constant<int, 4>{});
33
0
}
34
35
uint64_t MixingHashState::CombineLargeContiguousImpl64(
36
0
    uint64_t state, const unsigned char* first, size_t len) {
37
0
  while (len >= PiecewiseChunkSize()) {
38
0
    state = Mix(state, Hash64(first, PiecewiseChunkSize()));
39
0
    len -= PiecewiseChunkSize();
40
0
    first += PiecewiseChunkSize();
41
0
  }
42
  // Handle the remainder.
43
0
  return CombineContiguousImpl(state, first, len,
44
0
                               std::integral_constant<int, 8>{});
45
0
}
46
47
ABSL_CONST_INIT const void* const MixingHashState::kSeed = &kSeed;
48
49
// The salt array used by LowLevelHash. This array is NOT the mechanism used to
50
// make absl::Hash non-deterministic between program invocations.  See `Seed()`
51
// for that mechanism.
52
//
53
// Any random values are fine. These values are just digits from the decimal
54
// part of pi.
55
// https://en.wikipedia.org/wiki/Nothing-up-my-sleeve_number
56
constexpr uint64_t kHashSalt[5] = {
57
    uint64_t{0x243F6A8885A308D3}, uint64_t{0x13198A2E03707344},
58
    uint64_t{0xA4093822299F31D0}, uint64_t{0x082EFA98EC4E6C89},
59
    uint64_t{0x452821E638D01377},
60
};
61
62
uint64_t MixingHashState::LowLevelHashImpl(const unsigned char* data,
63
56
                                           size_t len) {
64
56
  return LowLevelHash(data, len, Seed(), kHashSalt);
65
56
}
66
67
}  // namespace hash_internal
68
ABSL_NAMESPACE_END
69
}  // namespace absl