Method: GetText::MO#hash_string
- Defined in:
- lib/gettext/mo.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.]
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/gettext/mo.rb', line 191 def hash_string(str) hval = 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 |