blob: d8c8f69c3db75ba2209ff9e9621404934ba99e4a (
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
52
53
54
55
56
57
58
59
60
61
|
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <boost/cstdint.hpp>
namespace boost {
namespace locale {
namespace gnu_gettext {
struct pj_winberger_hash {
typedef uint32_t state_type;
static const 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,char const *ptr)
{
while(*ptr)
value = update_state(value,*ptr++);
return value;
}
static state_type update_state(state_type value,char const *begin,char const *end)
{
while(begin!=end)
value = update_state(value,*begin++);
return value;
}
};
inline pj_winberger_hash::state_type pj_winberger_hash_function(char const *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(char const *begin,char const *end)
{
pj_winberger_hash::state_type state = pj_winberger_hash::initial_state;
state = pj_winberger_hash::update_state(state,begin,end);
return state;
}
}
}
}
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
|