• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/include/spike/crypto/jenkinshash.hpp
1
/*  constexpr Jenkins one at time class
2

3
    Copyright 2018-2023 Lukas Cone
4
    Algorithm by Bob Jenkins
5

6
    Licensed under the Apache License, Version 2.0 (the "License");
7
    you may not use this file except in compliance with the License.
8
    You may obtain a copy of the License at
9

10
        http://www.apache.org/licenses/LICENSE-2.0
11

12
    Unless required by applicable law or agreed to in writing, software
13
    distributed under the License is distributed on an "AS IS" BASIS,
14
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
    See the License for the specific language governing permissions and
16
    limitations under the License.
17
*/
18

19
#pragma once
20
#ifdef _MSC_VER
21
#pragma warning(push)
22
#pragma warning(disable : 4307)
23
#endif
24
#include "spike/type/detail/sc_type.hpp"
25
#include <string_view>
26

27
template <typename T = uint64>
28
constexpr uint32 JenkinsHash_(std::string_view input) {
29
  T result = 0;
30

31
  for (const auto c : input) {
3,585✔
32
    const T cChar = static_cast<uint8>(c);
3,095✔
33
    result += cChar;
3,095✔
34
    result += result << 10;
35
    result ^= result >> 6;
3,095✔
36
    result = static_cast<uint32>(result);
37
  }
38

39
  result += result << 3;
40
  result ^= result >> 11;
490✔
41
  result += result << 15;
42

43
  return static_cast<uint32>(result);
213✔
44
}
45

46
template <typename I> struct JenHash_t {
47
  constexpr JenHash_t() : value_() {}
1,432✔
48
  constexpr JenHash_t(JenHash_t &&) = default;
49
  constexpr JenHash_t(const JenHash_t &) = default;
50
  constexpr explicit JenHash_t(uint32 in) : value_(in) {}
262✔
51
  template <size_t n>
52
  constexpr JenHash_t(const char (&input)[n])
281✔
53
      : value_(JenkinsHash_<I>({input, n - 1})) {}
281✔
54
  constexpr JenHash_t(std::string_view input)
×
55
      : value_(JenkinsHash_<I>(input)) {}
×
56

57
  constexpr JenHash_t &operator=(const JenHash_t &) = default;
58
  constexpr JenHash_t &operator=(JenHash_t &&) = default;
59

60
  constexpr auto raw() const { return value_; }
×
61

62
  constexpr bool operator==(JenHash_t o) const { return o.value_ == value_; }
14,317✔
63
  constexpr bool operator==(uint32 o) const { return o == value_; }
64
  constexpr friend bool operator==(uint32 o, JenHash_t h) { return h == o; }
65

66
  constexpr bool operator!=(JenHash_t o) const { return o.value_ != value_; }
94✔
67
  constexpr bool operator!=(uint32 o) const { return o != value_; }
1✔
68
  constexpr friend bool operator!=(uint32 o, JenHash_t h) { return h != o; }
69

70
  constexpr bool operator<(JenHash_t o) const { return o.value_ < value_; }
1,247✔
71
  constexpr bool operator>(JenHash_t o) const { return o.value_ > value_; }
72

73
private:
74
  uint32 value_;
75
};
76

77
using JenHash = JenHash_t<uint64>;
78
using JenHashCannon = JenHash_t<uint32>;
79

80
namespace es::jenhash_literals {
81
inline constexpr JenHash operator""_jh(const char *str, size_t len) noexcept {
82
  return JenHash{{str, len}};
83
}
84

85
inline constexpr JenHashCannon operator""_jhc(const char *str,
86
                                              size_t len) noexcept {
87
  return JenHashCannon{{str, len}};
88
}
89
} // namespace es::jenhash_literals
90

91
static_assert(JenHash("bug") == 0x54908567, "JenkinsHash Failed");
92
static_assert(JenHashCannon("bug") == 0xF37C8567, "JOAAT Failed");
93

94
#ifdef _MSC_VER
95
#pragma warning(pop)
96
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc