1 // 2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) 3 // 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) 7 // 8 9 #include <boost/cstdint.hpp> 10 11 namespace boost { 12 namespace locale { 13 namespace gnu_gettext { 14 15 struct pj_winberger_hash { 16 17 typedef uint32_t state_type; 18 19 static const state_type initial_state = 0; 20 update_stateboost::locale::gnu_gettext::pj_winberger_hash21 static state_type update_state(state_type value,char c) 22 { 23 value = (value << 4) + static_cast<unsigned char>(c); 24 uint32_t high = (value & 0xF0000000U); 25 if(high!=0) 26 value = (value ^ (high >> 24)) ^ high; 27 return value; 28 } update_stateboost::locale::gnu_gettext::pj_winberger_hash29 static state_type update_state(state_type value,char const *ptr) 30 { 31 while(*ptr) 32 value = update_state(value,*ptr++); 33 return value; 34 } update_stateboost::locale::gnu_gettext::pj_winberger_hash35 static state_type update_state(state_type value,char const *begin,char const *end) 36 { 37 while(begin!=end) 38 value = update_state(value,*begin++); 39 return value; 40 } 41 }; 42 pj_winberger_hash_function(char const * ptr)43 inline pj_winberger_hash::state_type pj_winberger_hash_function(char const *ptr) 44 { 45 pj_winberger_hash::state_type state = pj_winberger_hash::initial_state; 46 state = pj_winberger_hash::update_state(state,ptr); 47 return state; 48 } 49 pj_winberger_hash_function(char const * begin,char const * end)50 inline pj_winberger_hash::state_type pj_winberger_hash_function(char const *begin,char const *end) 51 { 52 pj_winberger_hash::state_type state = pj_winberger_hash::initial_state; 53 state = pj_winberger_hash::update_state(state,begin,end); 54 return state; 55 } 56 } 57 } 58 } 59 60 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 61 62