module PulsarSdk::Producer::Murmur3
cpoy from github.com/funny-falcon/murmurhash3-ruby
Constants
- MASK32
Public Instance Methods
hash(str, seed=0)
click to toggle source
# 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)
click to toggle source
# File lib/pulsar_sdk/producer/router.rb, line 52 def int32_hash(i, seed=0) hash([i].pack("V"), seed) end
Private Instance Methods
fmix(h)
click to toggle source
# File lib/pulsar_sdk/producer/router.rb, line 84 def fmix(h) h &= MASK32 h ^= h >> 16 h = (h * 0x85ebca6b) & MASK32 h ^= h >> 13 h = (h * 0xc2b2ae35) & MASK32 h ^ (h >> 16) end
mmix(k1)
click to toggle source
# File lib/pulsar_sdk/producer/router.rb, line 93 def mmix(k1) k1 = (k1 * 0xcc9e2d51) & MASK32 k1 = rotl(k1, 15) (k1 * 0x1b873593) & MASK32 end
rotl(x, r)
click to toggle source
# File lib/pulsar_sdk/producer/router.rb, line 80 def rotl(x, r) ((x << r) | (x >> (32 - r))) & MASK32 end