mmh3 0.3.0 → 1.0.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/README.md +13 -6
- data/lib/mmh3.rb +16 -5
- data/lib/mmh3/version.rb +1 -1
- metadata +2 -4
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1702ed3a4591c78df8c10a33e20c5d1a64c8a10603119f7ce445e00d1f9fa7
|
4
|
+
data.tar.gz: 4007d57ada806c9856470c365837cda90329eae0876f2583ccef5451763aa0ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48d67b0d0b56410512a1c55eaeab3af85068ca269b869dd6bf53f91cbc51ca003ec83daf7822567bcb62dd8de2c717a5cb16f797c79f89a3e8bc15949e7c1f2
|
7
|
+
data.tar.gz: 90ac92b83d9ed6c04da3832c226988792b9362a164c7baa7695cb2201dbd8ac5cb4e8f275300b0403711fd15075d128103da589053c5335326787c6903993662
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# Mmh3
|
2
2
|
|
3
|
-
![Ruby](https://github.com/yoshoku/mmh3/workflows/Ruby/badge.svg)
|
3
|
+
[![Ruby](https://github.com/yoshoku/mmh3/workflows/Ruby/badge.svg)](https://github.com/yoshoku/mmh3/actions?query=workflow%3ARuby)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/mmh3.svg)](https://badge.fury.io/rb/mmh3)
|
5
|
+
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://rubydoc.info/gems/mmh3)
|
5
6
|
|
6
7
|
A pure Ruby implementation of [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash).
|
7
8
|
|
@@ -24,11 +25,17 @@ Or install it yourself as:
|
|
24
25
|
## Usage
|
25
26
|
|
26
27
|
```ruby
|
27
|
-
require 'mmh3'
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
irb(main):001:0> require 'mmh3'
|
29
|
+
=> true
|
30
|
+
irb(main):002:0> Mmh3.hash32('Hello, world', seed: 3)
|
31
|
+
=> 1659891412
|
32
|
+
irb(main):003:0> Mmh3.hash128('Hello, world', seed: 8)
|
33
|
+
=> 87198040132278428547135563345531192982
|
34
|
+
irb(main):004:0> Mmh3.hash32('Hello, world')
|
35
|
+
=> 1785891924
|
36
|
+
irb(main):005:0> Mmh3.hash32('Hello, world', seed: 0)
|
37
|
+
=> 1785891924
|
38
|
+
irb(main):006:0>
|
32
39
|
```
|
33
40
|
|
34
41
|
## Contributing
|
data/lib/mmh3.rb
CHANGED
@@ -10,18 +10,23 @@ module Mmh3
|
|
10
10
|
|
11
11
|
# Generate a 32-bit hash value.
|
12
12
|
#
|
13
|
+
# @example
|
14
|
+
# require 'mmh3'
|
15
|
+
#
|
16
|
+
# puts Mmh3.hash32('Hello, world') # => 1785891924
|
17
|
+
#
|
13
18
|
# @param key [String] Key for hash value.
|
14
19
|
# @param seed [Integer] Seed for hash value.
|
15
20
|
#
|
16
21
|
# @return [Integer] Returns hash value.
|
17
|
-
def hash32(key, seed
|
22
|
+
def hash32(key, seed: 0)
|
18
23
|
keyb = key.to_s.bytes
|
19
24
|
key_len = keyb.size
|
20
25
|
n_blocks = key_len / 4
|
21
26
|
|
22
27
|
h = seed
|
23
28
|
(0...n_blocks * 4).step(4) do |bstart|
|
24
|
-
k = keyb
|
29
|
+
k = block32(keyb, bstart, 0)
|
25
30
|
h ^= scramble32(k)
|
26
31
|
h = rotl32(h, 13)
|
27
32
|
h = (h * 5 + 0xe6546b64) & 0xFFFFFFFF
|
@@ -32,8 +37,9 @@ module Mmh3
|
|
32
37
|
|
33
38
|
k = 0
|
34
39
|
k ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
|
35
|
-
k ^= keyb[tail_id + 1] <<
|
36
|
-
k ^= keyb[tail_id + 0]
|
40
|
+
k ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
|
41
|
+
k ^= keyb[tail_id + 0] if tail_sz >= 1
|
42
|
+
|
37
43
|
h ^= scramble32(k) if tail_sz.positive?
|
38
44
|
|
39
45
|
h = fmix32(h ^ key_len)
|
@@ -47,12 +53,17 @@ module Mmh3
|
|
47
53
|
|
48
54
|
# Generate a 128-bit hash value.
|
49
55
|
#
|
56
|
+
# @example
|
57
|
+
# require 'mmh3'
|
58
|
+
#
|
59
|
+
# puts Mmh3.hash128('Hello, world') # => 87198040132278428547135563345531192982
|
60
|
+
#
|
50
61
|
# @param key [String] Key for hash value.
|
51
62
|
# @param seed [Integer] Seed for hash value.
|
52
63
|
# @param x64arch [Boolean] Flag indicating whether to generate hash value for x64 architecture.
|
53
64
|
#
|
54
65
|
# @return [Integer] Returns hash value.
|
55
|
-
def hash128(key, seed
|
66
|
+
def hash128(key, seed: 0, x64arch: true)
|
56
67
|
return hash128_x86(key, seed) if x64arch == false
|
57
68
|
|
58
69
|
hash128_x64(key, seed)
|
data/lib/mmh3/version.rb
CHANGED
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: 1.0.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-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A pure Ruby implementation of MurmurHash3
|
14
14
|
email:
|
@@ -25,8 +25,6 @@ files:
|
|
25
25
|
- LICENSE.txt
|
26
26
|
- README.md
|
27
27
|
- Rakefile
|
28
|
-
- bin/console
|
29
|
-
- bin/setup
|
30
28
|
- lib/mmh3.rb
|
31
29
|
- lib/mmh3/version.rb
|
32
30
|
- mmh3.gemspec
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "mmh3"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|