2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 #include <boost/cstdint.hpp>
13 namespace gnu_gettext {
15 struct pj_winberger_hash {
17 typedef uint32_t state_type;
19 static const state_type initial_state = 0;
21 static state_type update_state(state_type value,char c)
23 value = (value << 4) + static_cast<unsigned char>(c);
24 uint32_t high = (value & 0xF0000000U);
26 value = (value ^ (high >> 24)) ^ high;
29 static state_type update_state(state_type value,char const *ptr)
32 value = update_state(value,*ptr++);
35 static state_type update_state(state_type value,char const *begin,char const *end)
38 value = update_state(value,*begin++);
43 inline pj_winberger_hash::state_type pj_winberger_hash_function(char const *ptr)
45 pj_winberger_hash::state_type state = pj_winberger_hash::initial_state;
46 state = pj_winberger_hash::update_state(state,ptr);
50 inline pj_winberger_hash::state_type pj_winberger_hash_function(char const *begin,char const *end)
52 pj_winberger_hash::state_type state = pj_winberger_hash::initial_state;
53 state = pj_winberger_hash::update_state(state,begin,end);
60 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4