mmh3 0.1.0 → 0.2.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 +5 -0
- data/lib/mmh3.rb +116 -1
- data/lib/mmh3/version.rb +1 -1
- data/mmh3.gemspec +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f75743b47a08fe6ab088a1176cad6746e95dc740715fcd1249d63ab66d9b5a9
|
4
|
+
data.tar.gz: 53b77cea35c4b49828e338af56ed37bfa714c467643408208d9cd9fbd7d7a104
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26e434a6c91c6d84136c7aba6afb729beb2423ebc5e1db647569680c96ca78ab2a8f825fd639bafa8cc2a06f717e958a924ec8d459f58c41b5eb0cf70d4f3259
|
7
|
+
data.tar.gz: 1d627f4d5f6aceb7f38db402a1fe339e6c06f8b46a5714ffb8deb565ae40773896de3d2946f4fbf8805807fc1d003a1c070d9156531c3778b86eed55d0124cd9
|
data/CHANGELOG.md
ADDED
data/lib/mmh3.rb
CHANGED
@@ -45,10 +45,117 @@ module Mmh3
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
# Generate a 128-bit hash value for x64 architecture.
|
49
|
+
#
|
50
|
+
# @param key [String] Key for hash value.
|
51
|
+
# @param seed [Integer] Seed for hash value.
|
52
|
+
#
|
53
|
+
# @return [Integer] Returns hash value.
|
54
|
+
def hash128(key, seed = 0)
|
55
|
+
keyb = key.to_s.bytes
|
56
|
+
key_len = keyb.size
|
57
|
+
n_blocks = key_len / 16
|
58
|
+
|
59
|
+
h1 = seed
|
60
|
+
h2 = seed
|
61
|
+
c1 = 0x87c37b91114253d5
|
62
|
+
c2 = 0x4cf5ad432745937f
|
63
|
+
|
64
|
+
(0...n_blocks * 8).step(8) do |bstart|
|
65
|
+
k1 = block64(keyb, bstart, 0)
|
66
|
+
k2 = block64(keyb, bstart, 8)
|
67
|
+
|
68
|
+
k1 = (k1 * c1) & 0xFFFFFFFFFFFFFFFF
|
69
|
+
k1 = rotl64(k1, 31)
|
70
|
+
k1 = (k1 * c2) & 0xFFFFFFFFFFFFFFFF
|
71
|
+
h1 ^= k1
|
72
|
+
|
73
|
+
h1 = rotl64(h1, 27)
|
74
|
+
h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
|
75
|
+
h1 = (h1 * 5 + 0x52dce729) & 0xFFFFFFFFFFFFFFFF
|
76
|
+
|
77
|
+
k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
|
78
|
+
k2 = rotl64(k2, 33)
|
79
|
+
k2 = (k2 * c1) & 0xFFFFFFFFFFFFFFFF
|
80
|
+
h2 ^= k2
|
81
|
+
|
82
|
+
h2 = rotl64(h2, 31)
|
83
|
+
h2 = (h2 + h1) & 0xFFFFFFFFFFFFFFFF
|
84
|
+
h2 = (h2 * 5 + 0x38495ab5) & 0xFFFFFFFFFFFFFFFF
|
85
|
+
end
|
86
|
+
|
87
|
+
tail_id = n_blocks * 16
|
88
|
+
tail_sz = key_len & 15
|
89
|
+
|
90
|
+
k2 = 0
|
91
|
+
k2 ^= keyb[tail_id + 14] << 48 if tail_sz >= 15
|
92
|
+
k2 ^= keyb[tail_id + 13] << 40 if tail_sz >= 14
|
93
|
+
k2 ^= keyb[tail_id + 12] << 32 if tail_sz >= 13
|
94
|
+
k2 ^= keyb[tail_id + 11] << 24 if tail_sz >= 12
|
95
|
+
k2 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
|
96
|
+
k2 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
|
97
|
+
k2 ^= keyb[tail_id + 8] if tail_sz >= 9
|
98
|
+
|
99
|
+
if tail_sz > 8
|
100
|
+
k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
|
101
|
+
k2 = rotl64(k2, 33)
|
102
|
+
k2 = (k2 * c1) & 0xFFFFFFFFFFFFFFFF
|
103
|
+
h2 ^= k2
|
104
|
+
end
|
105
|
+
|
106
|
+
k1 = 0
|
107
|
+
k1 ^= keyb[tail_id + 7] << 56 if tail_sz >= 8
|
108
|
+
k1 ^= keyb[tail_id + 6] << 48 if tail_sz >= 7
|
109
|
+
k1 ^= keyb[tail_id + 5] << 40 if tail_sz >= 6
|
110
|
+
k1 ^= keyb[tail_id + 4] << 32 if tail_sz >= 5
|
111
|
+
k1 ^= keyb[tail_id + 3] << 24 if tail_sz >= 4
|
112
|
+
k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
|
113
|
+
k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
|
114
|
+
k1 ^= keyb[tail_id] if tail_sz >= 1
|
115
|
+
|
116
|
+
if tail_sz > 0
|
117
|
+
k1 = (k1 * c1) & 0xFFFFFFFFFFFFFFFF
|
118
|
+
k1 = rotl64(k1, 31)
|
119
|
+
k1 = (k1 * c2) & 0xFFFFFFFFFFFFFFFF
|
120
|
+
h1 ^= k1
|
121
|
+
end
|
122
|
+
|
123
|
+
h1 ^= key_len
|
124
|
+
h2 ^= key_len
|
125
|
+
|
126
|
+
h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
|
127
|
+
h2 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
|
128
|
+
|
129
|
+
h1 = fmix64(h1)
|
130
|
+
h2 = fmix64(h2)
|
131
|
+
|
132
|
+
h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
|
133
|
+
h2 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
|
134
|
+
|
135
|
+
h2 << 64 | h1
|
136
|
+
end
|
137
|
+
|
138
|
+
# private
|
139
|
+
|
140
|
+
def block64(kb, bstart, offset)
|
141
|
+
kb[2 * bstart + (7 + offset)] << 56 |
|
142
|
+
kb[2 * bstart + (6 + offset)] << 48 |
|
143
|
+
kb[2 * bstart + (5 + offset)] << 40 |
|
144
|
+
kb[2 * bstart + (4 + offset)] << 32 |
|
145
|
+
kb[2 * bstart + (3 + offset)] << 24 |
|
146
|
+
kb[2 * bstart + (2 + offset)] << 16 |
|
147
|
+
kb[2 * bstart + (1 + offset)] << 8 |
|
148
|
+
kb[2 * bstart + offset]
|
149
|
+
end
|
150
|
+
|
48
151
|
def rotl32(x, r)
|
49
152
|
(x << r | x >> (32 - r)) & 0xFFFFFFFF
|
50
153
|
end
|
51
154
|
|
155
|
+
def rotl64(x, r)
|
156
|
+
(x << r | x >> (64 - r)) & 0xFFFFFFFFFFFFFFFF
|
157
|
+
end
|
158
|
+
|
52
159
|
def scramble32(k)
|
53
160
|
k = (k * 0xcc9e2d51) & 0xFFFFFFFF
|
54
161
|
k = rotl32(k, 15)
|
@@ -63,5 +170,13 @@ module Mmh3
|
|
63
170
|
h ^ (h >> 16)
|
64
171
|
end
|
65
172
|
|
66
|
-
|
173
|
+
def fmix64(h)
|
174
|
+
h ^= h >> 33
|
175
|
+
h = (h * 0xff51afd7ed558ccd) & 0xFFFFFFFFFFFFFFFF
|
176
|
+
h ^= h >> 33
|
177
|
+
h = (h * 0xc4ceb9fe1a85ec53) & 0xFFFFFFFFFFFFFFFF
|
178
|
+
h ^ (h >> 33)
|
179
|
+
end
|
180
|
+
|
181
|
+
private_class_method :block64, :rotl32, :rotl64, :scramble32, :fmix32, :fmix64
|
67
182
|
end
|
data/lib/mmh3/version.rb
CHANGED
data/mmh3.gemspec
CHANGED
@@ -14,6 +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['documentation_url'] = 'https://rubydoc.info/gems/mmh3'
|
17
18
|
|
18
19
|
# Specify which files should be added to the gem when it is released.
|
19
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.2.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-
|
11
|
+
date: 2020-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A pure Ruby implementation of MurmurHash3
|
14
14
|
email:
|
@@ -20,6 +20,7 @@ files:
|
|
20
20
|
- ".github/workflows/build.yml"
|
21
21
|
- ".gitignore"
|
22
22
|
- ".rspec"
|
23
|
+
- CHANGELOG.md
|
23
24
|
- Gemfile
|
24
25
|
- LICENSE.txt
|
25
26
|
- README.md
|
@@ -36,6 +37,7 @@ metadata:
|
|
36
37
|
homepage_uri: https://github.com/yoshoku/mmh3
|
37
38
|
source_code_uri: https://github.com/yoshoku/mmh3
|
38
39
|
changelog_uri: https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md
|
40
|
+
documentation_url: https://rubydoc.info/gems/mmh3
|
39
41
|
post_install_message:
|
40
42
|
rdoc_options: []
|
41
43
|
require_paths:
|