Coverage Report

Created: 2023-03-02 15:38

/src/re2/util/mix.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright 2016 The RE2 Authors.  All Rights Reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
5
#ifndef UTIL_MIX_H_
6
#define UTIL_MIX_H_
7
8
#include <stddef.h>
9
#include <limits>
10
11
namespace re2 {
12
13
// Silence "truncation of constant value" warning for kMul in 32-bit mode.
14
// Since this is a header file, push and then pop to limit the scope.
15
#ifdef _MSC_VER
16
#pragma warning(push)
17
#pragma warning(disable: 4309)
18
#endif
19
20
class HashMix {
21
 public:
22
0
  HashMix() : hash_(1) {}
23
623k
  explicit HashMix(size_t val) : hash_(val + 83) {}
24
12.3M
  void Mix(size_t val) {
25
12.3M
    static const size_t kMul = static_cast<size_t>(0xdc3eb94af8ab4c93ULL);
26
12.3M
    hash_ *= kMul;
27
12.3M
    hash_ = ((hash_ << 19) |
28
12.3M
             (hash_ >> (std::numeric_limits<size_t>::digits - 19))) + val;
29
12.3M
  }
30
623k
  size_t get() const { return hash_; }
31
 private:
32
  size_t hash_;
33
};
34
35
#ifdef _MSC_VER
36
#pragma warning(pop)
37
#endif
38
39
}  // namespace re2
40
41
#endif  // UTIL_MIX_H_