Module: MurmurHash3::PureRuby128
- Includes:
- Alias128
- Defined in:
- lib/murmurhash3/pure_ruby.rb
Constant Summary collapse
- MASK64 =
0xffff_ffff_ffff_ffff
- C1_128 =
0x87c37b91_114253d5
- C2_128 =
0x4cf5ad43_2745937f
Instance Method Summary collapse
- #murmur3_128__mmix1(k1) ⇒ Object
- #murmur3_128__mmix2(k2) ⇒ Object
- #murmur3_128_fmix(h) ⇒ Object
- #murmur3_128_int32_hash(i, seed = 0) ⇒ Object
- #murmur3_128_int64_hash(i, seed = 0) ⇒ Object
- #murmur3_128_rotl(x, r) ⇒ Object
- #murmur3_128_str_base64digest(str, seed = 0) ⇒ Object
- #murmur3_128_str_digest(str, seed = 0) ⇒ Object
- #murmur3_128_str_hash(str, seed = 0) ⇒ Object
- #murmur3_128_str_hexdigest(str, seed = 0) ⇒ Object
Methods included from Alias128
Instance Method Details
#murmur3_128__mmix1(k1) ⇒ Object
88 89 90 91 92 |
# File 'lib/murmurhash3/pure_ruby.rb', line 88 def murmur3_128__mmix1(k1) k1 = (k1 * C1_128) & MASK64 k1 = murmur3_128_rotl(k1, 31) (k1 * C2_128) & MASK64 end |
#murmur3_128__mmix2(k2) ⇒ Object
94 95 96 97 98 |
# File 'lib/murmurhash3/pure_ruby.rb', line 94 def murmur3_128__mmix2(k2) k2 = (k2 * C2_128) & MASK64 k2 = murmur3_128_rotl(k2, 33) (k2 * C1_128) & MASK64 end |
#murmur3_128_fmix(h) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/murmurhash3/pure_ruby.rb', line 77 def murmur3_128_fmix(h) h &= MASK64 h ^= h >> 33 h = (h * 0xff51afd7_ed558ccd) & MASK64 h ^= h >> 33 h = (h * 0xc4ceb9fe_1a85ec53) & MASK64 h ^ (h >> 33) end |
#murmur3_128_int32_hash(i, seed = 0) ⇒ Object
144 145 146 |
# File 'lib/murmurhash3/pure_ruby.rb', line 144 def murmur3_128_int32_hash(i, seed=0) str_hash([i].pack("V"), seed) end |
#murmur3_128_int64_hash(i, seed = 0) ⇒ Object
148 149 150 |
# File 'lib/murmurhash3/pure_ruby.rb', line 148 def murmur3_128_int64_hash(i, seed=0) str_hash([i].pack("Q<"), seed) end |
#murmur3_128_rotl(x, r) ⇒ Object
73 74 75 |
# File 'lib/murmurhash3/pure_ruby.rb', line 73 def murmur3_128_rotl(x, r) ((x << r) | (x >> (64 - r))) & MASK64 end |
#murmur3_128_str_base64digest(str, seed = 0) ⇒ Object
160 161 162 |
# File 'lib/murmurhash3/pure_ruby.rb', line 160 def murmur3_128_str_base64digest(str, seed=0) [str_hash(str, seed).pack("V4")].pack('m').chomp! end |
#murmur3_128_str_digest(str, seed = 0) ⇒ Object
152 153 154 |
# File 'lib/murmurhash3/pure_ruby.rb', line 152 def murmur3_128_str_digest(str, seed=0) str_hash(str, seed).pack("V4") end |
#murmur3_128_str_hash(str, seed = 0) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/murmurhash3/pure_ruby.rb', line 100 def murmur3_128_str_hash(str, seed=0) h1 = h2 = seed fast_part = ((str.bytesize / 16) * 16) numbers = str.byteslice(0, fast_part).unpack('Q<*') tail = str.byteslice(fast_part, str.bytesize - fast_part).unpack('C*') numbers.each_slice(2) do |k1, k2| h1 ^= murmur3_128__mmix1(k1) h1 = murmur3_128_rotl(h1, 27) h1 = (h1 + h2) & MASK64 h1 = (h1*5 + 0x52dce729) & MASK64 h2 ^= murmur3_128__mmix2(k2) h2 = murmur3_128_rotl(h2, 31) h2 = (h1 + h2) & MASK64 h2 = (h2*5 + 0x38495ab5) & MASK64 end unless tail.empty? if tail.size > 8 k2 = 0 tail[8,8].reverse_each do |c2| k2 = (k2 << 8) | c2 end h2 ^= murmur3_128__mmix2(k2) end k1 = 0 tail[0,8].reverse_each do |c1| k1 = (k1 << 8) | c1 end h1 ^= murmur3_128__mmix1(k1) end h1 ^= str.bytesize h2 ^= str.bytesize h1 = (h1 + h2) & MASK64 h2 = (h1 + h2) & MASK64 h1 = murmur3_128_fmix(h1) h2 = murmur3_128_fmix(h2) h1 = (h1 + h2) & MASK64 h2 = (h1 + h2) & MASK64 [h1 & 0xffffffff, h1 >> 32, h2 & 0xffffffff, h2 >> 32] end |
#murmur3_128_str_hexdigest(str, seed = 0) ⇒ Object
156 157 158 |
# File 'lib/murmurhash3/pure_ruby.rb', line 156 def murmur3_128_str_hexdigest(str, seed=0) str_hash(str, seed).pack("V4").unpack("H*")[0] end |