Coverage Report

Created: 2026-06-12 16:48

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
1.71M
uint32_t Hash(const char* data, size_t n, uint32_t seed) {
14
  // Similar to murmur hash
15
1.71M
  const uint32_t m = 0xc6a4a793;
16
1.71M
  const uint32_t r = 24;
17
1.71M
  const char* limit = data + n;
18
1.71M
  uint32_t h = seed ^ (n * m);
19
20
  // Pick up four bytes at a time
21
1.72M
  while (limit - data >= 4) {
  Branch (21:10): [True: 7.76k, False: 1.71M]
22
7.76k
    uint32_t w = DecodeFixed32(data);
23
7.76k
    data += 4;
24
7.76k
    h += w;
25
7.76k
    h *= m;
26
7.76k
    h ^= (h >> 16);
27
7.76k
  }
28
29
  // Pick up remaining bytes
30
1.71M
  switch (limit - data) {
  Branch (30:11): [True: 3.36k, False: 1.71M]
31
344
    case 3:
  Branch (31:5): [True: 344, False: 1.71M]
32
344
      h += static_cast<uint8_t>(data[2]) << 16;
33
344
      [[fallthrough]];
34
1.71M
    case 2:
  Branch (34:5): [True: 1.71M, False: 3.70k]
35
1.71M
      h += static_cast<uint8_t>(data[1]) << 8;
36
1.71M
      [[fallthrough]];
37
1.71M
    case 1:
  Branch (37:5): [True: 0, False: 1.71M]
38
1.71M
      h += static_cast<uint8_t>(data[0]);
39
1.71M
      h *= m;
40
1.71M
      h ^= (h >> r);
41
1.71M
      break;
42
1.71M
  }
43
1.71M
  return h;
44
1.71M
}
45
46
}  // namespace leveldb