blob: 702ea7aece6a163fd4d24ddfda62468faf26a43c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <cstdint>
namespace boost { namespace locale { namespace gnu_gettext {
struct pj_winberger_hash {
typedef uint32_t state_type;
static constexpr state_type initial_state = 0;
static state_type update_state(state_type value, char c)
{
value = (value << 4) + static_cast<unsigned char>(c);
uint32_t high = (value & 0xF0000000U);
if(high != 0)
value = (value ^ (high >> 24)) ^ high;
return value;
}
static state_type update_state(state_type value, const char* ptr)
{
while(*ptr)
value = update_state(value, *ptr++);
return value;
}
static state_type update_state(state_type value, const char* begin, const char* end)
{
while(begin != end)
value = update_state(value, *begin++);
return value;
}
};
inline pj_winberger_hash::state_type pj_winberger_hash_function(const char* ptr)
{
pj_winberger_hash::state_type state = pj_winberger_hash::initial_state;
state = pj_winberger_hash::update_state(state, ptr);
return state;
}
inline pj_winberger_hash::state_type pj_winberger_hash_function(const char* begin, const char* end)
{
pj_winberger_hash::state_type state = pj_winberger_hash::initial_state;
state = pj_winberger_hash::update_state(state, begin, end);
return state;
}
}}} // namespace boost::locale::gnu_gettext
|