Coverage Report

Created: 2026-07-01 15:07

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