Module: PulsarSdk::Producer::Murmur3
Overview
cpoy from github.com/funny-falcon/murmurhash3-ruby
Constant Summary collapse
- MASK32 =
0xffffffff
Instance Method Summary collapse
Instance Method Details
#hash(str, seed = 0) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pulsar_sdk/producer/router.rb', line 56 def hash(str, seed=0) h1 = seed numbers = str.unpack('V*C*') tailn = str.bytesize % 4 tail = numbers.slice!(numbers.size - tailn, tailn) for k1 in numbers h1 ^= mmix(k1) h1 = rotl(h1, 13) h1 = (h1*5 + 0xe6546b64) & MASK32 end unless tail.empty? k1 = 0 tail.reverse_each do |c1| k1 = (k1 << 8) | c1 end h1 ^= mmix(k1) end h1 ^= str.bytesize fmix(h1) end |
#int32_hash(i, seed = 0) ⇒ Object
52 53 54 |
# File 'lib/pulsar_sdk/producer/router.rb', line 52 def int32_hash(i, seed=0) hash([i].pack("V"), seed) end |