mmh3 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b3781157663073fc2ddf9f5af0f58f28e4ef31af58cbc5ac081327b9aba327e
4
- data.tar.gz: bb4cdba03cab5d309509947f917f884392a23d386a1f072a7322d2ee250dc91f
3
+ metadata.gz: 9b1702ed3a4591c78df8c10a33e20c5d1a64c8a10603119f7ce445e00d1f9fa7
4
+ data.tar.gz: 4007d57ada806c9856470c365837cda90329eae0876f2583ccef5451763aa0ad
5
5
  SHA512:
6
- metadata.gz: c7fa5acfc24334d26726ac8c32f3ebbeb710012056d71ab35fa73a72ef9067e1bdc76c02e1ec7afb8f3d2f7d522fc0289231fe88cc7f622bd12149aad6ce7a42
7
- data.tar.gz: c2be744d61934671e2c0ad18b842f178daab06f411f3164d77989fa9b9f347db707aff66dc186ff4bd93374b125d8968979429dc91ac7f5c39e704e14222cd96
6
+ metadata.gz: d48d67b0d0b56410512a1c55eaeab3af85068ca269b869dd6bf53f91cbc51ca003ec83daf7822567bcb62dd8de2c717a5cb16f797c79f89a3e8bc15949e7c1f2
7
+ data.tar.gz: 90ac92b83d9ed6c04da3832c226988792b9362a164c7baa7695cb2201dbd8ac5cb4e8f275300b0403711fd15075d128103da589053c5335326787c6903993662
@@ -1,3 +1,8 @@
1
+ # 1.0.0
2
+ - Change to use keyword argument for seed and x64arch arguments.
3
+ - Refactor hash32 method.
4
+ - Update API documentation.
5
+
1
6
  # 0.3.0
2
7
  - Add option to hash128 method for generating a 128-bit hash value in x86 architecture.
3
8
 
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
- puts Mmh3.hash32('Hello, world', 10)
30
-
31
- # => -172601702
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
@@ -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 = 0)
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[bstart + 3] << 24 | keyb[bstart + 2] << 16 | keyb[bstart + 1] << 8 | keyb[bstart + 0]
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] << 8 if tail_sz >= 2
36
- k ^= keyb[tail_id + 0] if tail_sz >= 1
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 = 0, x64arch = true)
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)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Mmh3
4
4
  # Version number of Mmh3 you are using.
5
- VERSION = '0.3.0'
5
+ VERSION = '1.0.0'
6
6
  end
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.3.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-04-25 00:00:00.000000000 Z
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
@@ -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__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here