mmh3 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/lib/mmh3.rb +156 -4
- data/lib/mmh3/version.rb +1 -1
- data/mmh3.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b3781157663073fc2ddf9f5af0f58f28e4ef31af58cbc5ac081327b9aba327e
|
4
|
+
data.tar.gz: bb4cdba03cab5d309509947f917f884392a23d386a1f072a7322d2ee250dc91f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7fa5acfc24334d26726ac8c32f3ebbeb710012056d71ab35fa73a72ef9067e1bdc76c02e1ec7afb8f3d2f7d522fc0289231fe88cc7f622bd12149aad6ce7a42
|
7
|
+
data.tar.gz: c2be744d61934671e2c0ad18b842f178daab06f411f3164d77989fa9b9f347db707aff66dc186ff4bd93374b125d8968979429dc91ac7f5c39e704e14222cd96
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# 0.3.0
|
2
|
+
- Add option to hash128 method for generating a 128-bit hash value in x86 architecture.
|
3
|
+
|
1
4
|
# 0.2.0
|
2
|
-
- Add hash128 method for generating a 128-bit hash value in
|
5
|
+
- Add hash128 method for generating a 128-bit hash value in x64 architecture.
|
3
6
|
|
4
7
|
# 0.1.0
|
5
8
|
- First release.
|
data/lib/mmh3.rb
CHANGED
@@ -45,13 +45,22 @@ module Mmh3
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# Generate a 128-bit hash value
|
48
|
+
# Generate a 128-bit hash value.
|
49
49
|
#
|
50
50
|
# @param key [String] Key for hash value.
|
51
51
|
# @param seed [Integer] Seed for hash value.
|
52
|
+
# @param x64arch [Boolean] Flag indicating whether to generate hash value for x64 architecture.
|
52
53
|
#
|
53
54
|
# @return [Integer] Returns hash value.
|
54
|
-
def hash128(key, seed = 0)
|
55
|
+
def hash128(key, seed = 0, x64arch = true)
|
56
|
+
return hash128_x86(key, seed) if x64arch == false
|
57
|
+
|
58
|
+
hash128_x64(key, seed)
|
59
|
+
end
|
60
|
+
|
61
|
+
# private
|
62
|
+
|
63
|
+
def hash128_x64(key, seed = 0)
|
55
64
|
keyb = key.to_s.bytes
|
56
65
|
key_len = keyb.size
|
57
66
|
n_blocks = key_len / 16
|
@@ -135,7 +144,150 @@ module Mmh3
|
|
135
144
|
h2 << 64 | h1
|
136
145
|
end
|
137
146
|
|
138
|
-
|
147
|
+
def hash128_x86(key, seed = 0)
|
148
|
+
keyb = key.to_s.bytes
|
149
|
+
key_len = keyb.size
|
150
|
+
n_blocks = key_len / 16
|
151
|
+
|
152
|
+
h1 = seed
|
153
|
+
h2 = seed
|
154
|
+
h3 = seed
|
155
|
+
h4 = seed
|
156
|
+
c1 = 0x239b961b
|
157
|
+
c2 = 0xab0e9789
|
158
|
+
c3 = 0x38b34ae5
|
159
|
+
c4 = 0xa1e38b93
|
160
|
+
|
161
|
+
(0...n_blocks * 16).step(16) do |bstart|
|
162
|
+
k1 = block32(keyb, bstart, 0)
|
163
|
+
k2 = block32(keyb, bstart, 4)
|
164
|
+
k3 = block32(keyb, bstart, 8)
|
165
|
+
k4 = block32(keyb, bstart, 12)
|
166
|
+
|
167
|
+
k1 = (k1 * c1) & 0xFFFFFFFF
|
168
|
+
k1 = rotl32(k1, 15)
|
169
|
+
k1 = (k1 * c2) & 0xFFFFFFFF
|
170
|
+
h1 ^= k1
|
171
|
+
|
172
|
+
h1 = rotl32(h1, 19)
|
173
|
+
h1 = (h1 + h2) & 0xFFFFFFFF
|
174
|
+
h1 = (h1 * 5 + 0x561ccd1b) & 0xFFFFFFFF
|
175
|
+
|
176
|
+
k2 = (k2 * c2) & 0xFFFFFFFF
|
177
|
+
k2 = rotl32(k2, 16)
|
178
|
+
k2 = (k2 * c3) & 0xFFFFFFFF
|
179
|
+
h2 ^= k2
|
180
|
+
|
181
|
+
h2 = rotl32(h2, 17)
|
182
|
+
h2 = (h2 + h3) & 0xFFFFFFFF
|
183
|
+
h2 = (h2 * 5 + 0x0bcaa747) & 0xFFFFFFFF
|
184
|
+
|
185
|
+
k3 = (k3 * c3) & 0xFFFFFFFF
|
186
|
+
k3 = rotl32(k3, 17)
|
187
|
+
k3 = (k3 * c4) & 0xFFFFFFFF
|
188
|
+
h3 ^= k3
|
189
|
+
|
190
|
+
h3 = rotl32(h3, 15)
|
191
|
+
h3 = (h3 + h4) & 0xFFFFFFFF
|
192
|
+
h3 = (h3 * 5 + 0x96cd1c35) & 0xFFFFFFFF
|
193
|
+
|
194
|
+
k4 = (k4 * c4) & 0xFFFFFFFF
|
195
|
+
k4 = rotl32(k4, 18)
|
196
|
+
k4 = (k4 * c1) & 0xFFFFFFFF
|
197
|
+
h4 ^= k4
|
198
|
+
|
199
|
+
h4 = rotl32(h4, 13)
|
200
|
+
h4 = (h4 + h1) & 0xFFFFFFFF
|
201
|
+
h4 = (h4 * 5 + 0x32ac3b17) & 0xFFFFFFFF
|
202
|
+
end
|
203
|
+
|
204
|
+
tail_id = n_blocks * 16
|
205
|
+
tail_sz = key_len & 15
|
206
|
+
|
207
|
+
k4 = 0
|
208
|
+
k4 ^= keyb[tail_id + 14] << 16 if tail_sz >= 15
|
209
|
+
k4 ^= keyb[tail_id + 13] << 8 if tail_sz >= 14
|
210
|
+
k4 ^= keyb[tail_id + 12] if tail_sz >= 13
|
211
|
+
|
212
|
+
if tail_sz > 12
|
213
|
+
k4 = (k4 * c4) & 0xFFFFFFFF
|
214
|
+
k4 = rotl32(k4, 18)
|
215
|
+
k4 = (k4 * c1) & 0xFFFFFFFF
|
216
|
+
h4 ^= k4
|
217
|
+
end
|
218
|
+
|
219
|
+
k3 = 0
|
220
|
+
k3 ^= keyb[tail_id + 11] << 24 if tail_sz >= 12
|
221
|
+
k3 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
|
222
|
+
k3 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
|
223
|
+
k3 ^= keyb[tail_id + 8] if tail_sz >= 9
|
224
|
+
|
225
|
+
if tail_sz > 8
|
226
|
+
k3 = (k3 * c3) & 0xFFFFFFFF
|
227
|
+
k3 = rotl32(k3, 17)
|
228
|
+
k3 = (k3 * c4) & 0xFFFFFFFF
|
229
|
+
h3 ^= k3
|
230
|
+
end
|
231
|
+
|
232
|
+
k2 = 0
|
233
|
+
k2 ^= keyb[tail_id + 7] << 24 if tail_sz >= 8
|
234
|
+
k2 ^= keyb[tail_id + 6] << 16 if tail_sz >= 7
|
235
|
+
k2 ^= keyb[tail_id + 5] << 8 if tail_sz >= 6
|
236
|
+
k2 ^= keyb[tail_id + 4] if tail_sz >= 5
|
237
|
+
|
238
|
+
if tail_sz > 4
|
239
|
+
k2 = (k2 * c2) & 0xFFFFFFFF
|
240
|
+
k2 = rotl32(k2, 16)
|
241
|
+
k2 = (k2 * c3) & 0xFFFFFFFF
|
242
|
+
h2 ^= k2
|
243
|
+
end
|
244
|
+
|
245
|
+
k1 = 0
|
246
|
+
k1 ^= keyb[tail_id + 3] << 24 if tail_sz >= 4
|
247
|
+
k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
|
248
|
+
k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
|
249
|
+
k1 ^= keyb[tail_id] if tail_sz >= 1
|
250
|
+
|
251
|
+
if tail_sz > 0
|
252
|
+
k1 = (k1 * c1) & 0xFFFFFFFF
|
253
|
+
k1 = rotl32(k1, 15)
|
254
|
+
k1 = (k1 * c2) & 0xFFFFFFFF
|
255
|
+
h1 ^= k1
|
256
|
+
end
|
257
|
+
|
258
|
+
h1 ^= key_len
|
259
|
+
h2 ^= key_len
|
260
|
+
h3 ^= key_len
|
261
|
+
h4 ^= key_len
|
262
|
+
|
263
|
+
h1 = (h1 + h2) & 0xFFFFFFFF
|
264
|
+
h1 = (h1 + h3) & 0xFFFFFFFF
|
265
|
+
h1 = (h1 + h4) & 0xFFFFFFFF
|
266
|
+
h2 = (h1 + h2) & 0xFFFFFFFF
|
267
|
+
h3 = (h1 + h3) & 0xFFFFFFFF
|
268
|
+
h4 = (h1 + h4) & 0xFFFFFFFF
|
269
|
+
|
270
|
+
h1 = fmix32(h1)
|
271
|
+
h2 = fmix32(h2)
|
272
|
+
h3 = fmix32(h3)
|
273
|
+
h4 = fmix32(h4)
|
274
|
+
|
275
|
+
h1 = (h1 + h2) & 0xFFFFFFFF
|
276
|
+
h1 = (h1 + h3) & 0xFFFFFFFF
|
277
|
+
h1 = (h1 + h4) & 0xFFFFFFFF
|
278
|
+
h2 = (h1 + h2) & 0xFFFFFFFF
|
279
|
+
h3 = (h1 + h3) & 0xFFFFFFFF
|
280
|
+
h4 = (h1 + h4) & 0xFFFFFFFF
|
281
|
+
|
282
|
+
h4 << 96 | h3 << 64 | h2 << 32 | h1
|
283
|
+
end
|
284
|
+
|
285
|
+
def block32(kb, bstart, offset)
|
286
|
+
kb[bstart + offset + 3] << 24 |
|
287
|
+
kb[bstart + offset + 2] << 16 |
|
288
|
+
kb[bstart + offset + 1] << 8 |
|
289
|
+
kb[bstart + offset]
|
290
|
+
end
|
139
291
|
|
140
292
|
def block64(kb, bstart, offset)
|
141
293
|
kb[2 * bstart + (7 + offset)] << 56 |
|
@@ -178,5 +330,5 @@ module Mmh3
|
|
178
330
|
h ^ (h >> 33)
|
179
331
|
end
|
180
332
|
|
181
|
-
private_class_method :block64, :rotl32, :rotl64, :scramble32, :fmix32, :fmix64
|
333
|
+
private_class_method :hash128_x64, :hash128_x86, :block32, :block64, :rotl32, :rotl64, :scramble32, :fmix32, :fmix64
|
182
334
|
end
|
data/lib/mmh3/version.rb
CHANGED
data/mmh3.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.metadata['homepage_uri'] = spec.homepage
|
15
15
|
spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/mmh3'
|
16
16
|
spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md'
|
17
|
-
spec.metadata['
|
17
|
+
spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/mmh3'
|
18
18
|
|
19
19
|
# Specify which files should be added to the gem when it is released.
|
20
20
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mmh3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A pure Ruby implementation of MurmurHash3
|
14
14
|
email:
|
@@ -37,7 +37,7 @@ metadata:
|
|
37
37
|
homepage_uri: https://github.com/yoshoku/mmh3
|
38
38
|
source_code_uri: https://github.com/yoshoku/mmh3
|
39
39
|
changelog_uri: https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md
|
40
|
-
|
40
|
+
documentation_uri: https://rubydoc.info/gems/mmh3
|
41
41
|
post_install_message:
|
42
42
|
rdoc_options: []
|
43
43
|
require_paths:
|