Coverage Report

Created: 2026-08-25 19:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/leveldb/util/hash.cc
Line
Count
Source
1
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file. See the AUTHORS file for names of contributors.
4
5
#include "util/hash.h"
6
7
#include <string.h>
8
9
#include "util/coding.h"
10
11
namespace leveldb {
12
13
25.3M
uint32_t Hash(const char* data, size_t n, uint32_t seed) {
14
  // Similar to murmur hash
15
25.3M
  const uint32_t m = 0xc6a4a793;
16
25.3M
  const uint32_t r = 24;
17
25.3M
  const char* limit = data + n;
18
25.3M
  uint32_t h = seed ^ (n * m);
19
20
  // Pick up four bytes at a time
21
78.6M
  while (limit - data >= 4) {
  Branch (21:10): [True: 53.2M, False: 25.3M]
22
53.2M
    uint32_t w = DecodeFixed32(data);
23
53.2M
    data += 4;
24
53.2M
    h += w;
25
53.2M
    h *= m;
26
53.2M
    h ^= (h >> 16);
27
53.2M
  }
28
29
  // Pick up remaining bytes
30
25.3M
  switch (limit - data) {
  Branch (30:11): [True: 6.72M, False: 18.6M]
31
116k
    case 3:
  Branch (31:5): [True: 116k, False: 25.2M]
32
116k
      h += static_cast<uint8_t>(data[2]) << 16;
33
116k
      [[fallthrough]];
34
2.60M
    case 2:
  Branch (34:5): [True: 2.48M, False: 22.8M]
35
2.60M
      h += static_cast<uint8_t>(data[1]) << 8;
36
2.60M
      [[fallthrough]];
37
18.6M
    case 1:
  Branch (37:5): [True: 16.0M, False: 9.32M]
38
18.6M
      h += static_cast<uint8_t>(data[0]);
39
18.6M
      h *= m;
40
18.6M
      h ^= (h >> r);
41
18.6M
      break;
42
25.3M
  }
43
25.3M
  return h;
44
25.3M
}
45
46
}  // namespace leveldb