Method: GetText::MoFile#hash_string
- Defined in:
- lib/gettext/runtime/mofile.rb
#hash_string(str) ⇒ Object
From gettext-0.12.1/gettext-runtime/intl/hash-string.h Defines the so called ‘hashpjw’ function by P.J. Weinberger [see Aho/Sethi/Ullman, COMPILERS: Principles, Techniques and Tools, 1986, 1987 Bell Telephone Laboratories, Inc.]
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/gettext/runtime/mofile.rb', line 186 def hash_string(str) hval = 0 i = 0 str.each_byte do |b| break if b == '\0' hval <<= 4 hval += b.to_i g = hval & (0xf << (HASHWORDBITS - 4)) if (g != 0) hval ^= g >> (HASHWORDBITS - 8) hval ^= g end end hval end |