LIEF: Library to Instrument Executable Formats
Version 1.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
lief-install
x86_64
static
include
frozen
bits
hash_string.h
Go to the documentation of this file.
1
#ifndef FROZEN_LETITGO_BITS_HASH_STRING_H
2
#define FROZEN_LETITGO_BITS_HASH_STRING_H
3
4
#include <cstddef>
5
6
namespace
frozen
{
7
8
template
<
typename
String>
9
constexpr
std::size_t
hash_string
(
const
String& value) {
10
std::size_t d = 5381;
11
for
(
const
auto
& c : value)
12
d = d * 33 +
static_cast<
std::size_t
>
(c);
13
return
d;
14
}
15
16
// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
17
// With the lowest bits removed, based on experimental setup.
18
template
<
typename
String>
19
constexpr
std::size_t
hash_string
(
const
String& value, std::size_t seed) {
20
std::size_t d = (0x811c9dc5 ^ seed) *
static_cast<
std::size_t
>
(0x01000193);
21
for
(
const
auto
& c : value)
22
d = (d ^
static_cast<
std::size_t
>
(c)) *
static_cast<
std::size_t
>
(0x01000193);
23
return
d >> 8 ;
24
}
25
26
}
// namespace frozen
27
28
#endif
// FROZEN_LETITGO_BITS_HASH_STRING_H
frozen
Definition
algorithm.h:30
frozen::hash_string
constexpr std::size_t hash_string(const String &value)
Definition
hash_string.h:9
Generated by
1.17.0