mmh3 0.3.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b3781157663073fc2ddf9f5af0f58f28e4ef31af58cbc5ac081327b9aba327e
4
- data.tar.gz: bb4cdba03cab5d309509947f917f884392a23d386a1f072a7322d2ee250dc91f
3
+ metadata.gz: 70a69ac210acc55f49b85764ddacced777cd5b14c515c587b22e77a08479356e
4
+ data.tar.gz: 320c6db6188375dd16f065164691af0c254bcdc01968a5dd7318b087c6bdc896
5
5
  SHA512:
6
- metadata.gz: c7fa5acfc24334d26726ac8c32f3ebbeb710012056d71ab35fa73a72ef9067e1bdc76c02e1ec7afb8f3d2f7d522fc0289231fe88cc7f622bd12149aad6ce7a42
7
- data.tar.gz: c2be744d61934671e2c0ad18b842f178daab06f411f3164d77989fa9b9f347db707aff66dc186ff4bd93374b125d8968979429dc91ac7f5c39e704e14222cd96
6
+ metadata.gz: b533e1bf9b5bb655eef411e0b4f5e6cf184dfab4c9053513771941aa851f2abc768c2d81c6c97ebd37d2af7232d8f091cb9511fb8e6f2b23759727e944872555
7
+ data.tar.gz: dbf836b9f3e3f7cef52aa4aa414f58f960592533f40d6bbf885250ee2ce36d12bd68dd43b2c3b0417d3fbc76c5222be94dd9367b26c419d0f768fb140cbbd2c5
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: github-ci
@@ -1,20 +1,20 @@
1
- name: Ruby
1
+ name: build
2
2
 
3
- on: [push]
3
+ on: [push, pull_request]
4
4
 
5
5
  jobs:
6
6
  build:
7
-
8
7
  runs-on: ubuntu-latest
9
-
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby: [ '2.7', '3.0', '3.1' ]
10
12
  steps:
11
- - uses: actions/checkout@v2
12
- - name: Set up Ruby 2.6
13
- uses: actions/setup-ruby@v1
14
- with:
15
- ruby-version: 2.6.x
16
- - name: Build and test with Rake
17
- run: |
18
- gem install bundler
19
- bundle install --jobs 4 --retry 3
20
- bundle exec rake
13
+ - uses: actions/checkout@v3
14
+ - name: Set up Ruby ${{ matrix.ruby }}
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
19
+ - name: Build and test with Rake
20
+ run: bundle exec rake
@@ -0,0 +1,24 @@
1
+ name: coverage
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ coverage:
11
+ runs-on: ubuntu-20.04
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 2.7
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '2.7'
18
+ bundler-cache: true
19
+ - name: Build and test with Rake
20
+ run: bundle exec rake
21
+ - name: Coveralls GitHub Action
22
+ uses: coverallsapp/github-action@v1.1.2
23
+ with:
24
+ github-token: ${{ secrets.GITHUB_TOKEN }}
data/.rubocop.yml ADDED
@@ -0,0 +1,50 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rake
4
+ - rubocop-rspec
5
+
6
+ AllCops:
7
+ NewCops: enable
8
+ DisplayCopNames: true
9
+ DisplayStyleGuide: true
10
+ Exclude:
11
+ - 'tmp/**/*'
12
+ - 'vendor/**/*'
13
+ - 'Steepfile'
14
+
15
+ Gemspec/RequiredRubyVersion:
16
+ Enabled: false
17
+
18
+ Layout/LineLength:
19
+ IgnoredPatterns: ['(\A|\s)#']
20
+
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'spec/**/*'
24
+
25
+ Metrics/ParameterLists:
26
+ Max: 8
27
+
28
+ Naming/AccessorMethodName:
29
+ Enabled: false
30
+
31
+ Naming/MethodParameterName:
32
+ Enabled: false
33
+
34
+ RSpec/ExampleLength:
35
+ Max: 16
36
+
37
+ RSpec/MultipleMemoizedHelpers:
38
+ Max: 8
39
+
40
+ RSpec/NamedSubject:
41
+ Enabled: false
42
+
43
+ RSpec/NestedGroups:
44
+ Max: 4
45
+
46
+ Style/NumericLiterals:
47
+ Enabled: false
48
+
49
+ Style/NumericPredicate:
50
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ # 1.2.0
2
+ - Refactor codes and configs with RuboCop.
3
+
4
+ # 1.1.0
5
+ - Add type declaration file: sig/mmh3.rbs
6
+
7
+ # 1.0.0
8
+ - Change to use keyword argument for seed and x64arch arguments.
9
+ - Refactor hash32 method.
10
+ - Update API documentation.
11
+
1
12
  # 0.3.0
2
13
  - Add option to hash128 method for generating a 128-bit hash value in x86 architecture.
3
14
 
data/Gemfile CHANGED
@@ -1,7 +1,17 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mmh3.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rbs', '~> 1.2'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop', '~> 1.24'
12
+ gem 'rubocop-performance', '~> 1.14'
13
+ gem 'rubocop-rake', '~> 0.6.0'
14
+ gem 'rubocop-rspec', '~> 2.11'
15
+ gem 'simplecov', '~> 0.21'
16
+ gem 'simplecov-lcov', '~> 0.8'
17
+ gem 'steep', '~> 0.44'
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 yoshoku
3
+ Copyright (c) 2020-2022 yoshoku
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Mmh3
2
2
 
3
- ![Ruby](https://github.com/yoshoku/mmh3/workflows/Ruby/badge.svg)
3
+ [![Build Status](https://github.com/yoshoku/mmh3/workflows/build/badge.svg)](https://github.com/yoshoku/mmh3/actions?query=workflow%3Abuild)
4
+ [![Coverage Status](https://coveralls.io/repos/github/yoshoku/mmh3/badge.svg?branch=main)](https://coveralls.io/github/yoshoku/mmh3?branch=main)
4
5
  [![Gem Version](https://badge.fury.io/rb/mmh3.svg)](https://badge.fury.io/rb/mmh3)
6
+ [![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://rubydoc.info/gems/mmh3)
5
7
 
6
8
  A pure Ruby implementation of [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash).
7
9
 
@@ -24,11 +26,17 @@ Or install it yourself as:
24
26
  ## Usage
25
27
 
26
28
  ```ruby
27
- require 'mmh3'
28
-
29
- puts Mmh3.hash32('Hello, world', 10)
30
-
31
- # => -172601702
29
+ irb(main):001:0> require 'mmh3'
30
+ => true
31
+ irb(main):002:0> Mmh3.hash32('Hello, world', seed: 3)
32
+ => 1659891412
33
+ irb(main):003:0> Mmh3.hash128('Hello, world', seed: 8)
34
+ => 87198040132278428547135563345531192982
35
+ irb(main):004:0> Mmh3.hash32('Hello, world')
36
+ => 1785891924
37
+ irb(main):005:0> Mmh3.hash32('Hello, world', seed: 0)
38
+ => 1785891924
39
+ irb(main):006:0>
32
40
  ```
33
41
 
34
42
  ## Contributing
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[rubocop spec]
data/Steepfile ADDED
@@ -0,0 +1,20 @@
1
+ target :lib do
2
+ signature "sig"
3
+ #
4
+ check "lib" # Directory name
5
+ # check "Gemfile" # File name
6
+ # check "app/models/**/*.rb" # Glob
7
+ # # ignore "lib/templates/*.rb"
8
+ #
9
+ # # library "pathname", "set" # Standard libraries
10
+ # # library "strong_json" # Gems
11
+ end
12
+
13
+ # target :spec do
14
+ # signature "sig", "sig-private"
15
+ #
16
+ # check "spec"
17
+ #
18
+ # # library "pathname", "set" # Standard libraries
19
+ # # library "rspec"
20
+ # end
data/lib/mmh3/version.rb CHANGED
@@ -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.2.0'
6
6
  end
data/lib/mmh3.rb CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'mmh3/version'
4
4
 
5
+ # rubocop:disable Metrics/AbcSize, Metrics/BlockLength, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ModuleLength, Metrics/PerceivedComplexity
6
+
5
7
  # This module consists module functions that implement MurmurHash3.
6
8
  # MurmurHash3 was written by Austin Appleby, and is placed in the public domain.
7
9
  # The author hereby disclaims copyright to this source code.
@@ -10,30 +12,38 @@ module Mmh3
10
12
 
11
13
  # Generate a 32-bit hash value.
12
14
  #
15
+ # @example
16
+ # require 'mmh3'
17
+ #
18
+ # puts Mmh3.hash32('Hello, world') # => 1785891924
19
+ #
13
20
  # @param key [String] Key for hash value.
14
21
  # @param seed [Integer] Seed for hash value.
15
22
  #
16
23
  # @return [Integer] Returns hash value.
17
- def hash32(key, seed = 0)
24
+ def hash32(key, seed: 0)
18
25
  keyb = key.to_s.bytes
19
26
  key_len = keyb.size
20
27
  n_blocks = key_len / 4
21
28
 
22
29
  h = seed
23
30
  (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]
31
+ k = block32(keyb, bstart, 0)
25
32
  h ^= scramble32(k)
26
33
  h = rotl32(h, 13)
27
- h = (h * 5 + 0xe6546b64) & 0xFFFFFFFF
34
+ h = ((h * 5) + 0xe6546b64) & 0xFFFFFFFF
28
35
  end
29
36
 
30
37
  tail_id = n_blocks * 4
31
38
  tail_sz = key_len & 3
32
39
 
33
40
  k = 0
41
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
34
42
  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
43
+ k ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
44
+ k ^= keyb[tail_id + 0] if tail_sz >= 1
45
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
46
+
37
47
  h ^= scramble32(k) if tail_sz.positive?
38
48
 
39
49
  h = fmix32(h ^ key_len)
@@ -47,12 +57,17 @@ module Mmh3
47
57
 
48
58
  # Generate a 128-bit hash value.
49
59
  #
60
+ # @example
61
+ # require 'mmh3'
62
+ #
63
+ # puts Mmh3.hash128('Hello, world') # => 87198040132278428547135563345531192982
64
+ #
50
65
  # @param key [String] Key for hash value.
51
66
  # @param seed [Integer] Seed for hash value.
52
67
  # @param x64arch [Boolean] Flag indicating whether to generate hash value for x64 architecture.
53
68
  #
54
69
  # @return [Integer] Returns hash value.
55
- def hash128(key, seed = 0, x64arch = true)
70
+ def hash128(key, seed: 0, x64arch: true)
56
71
  return hash128_x86(key, seed) if x64arch == false
57
72
 
58
73
  hash128_x64(key, seed)
@@ -81,7 +96,7 @@ module Mmh3
81
96
 
82
97
  h1 = rotl64(h1, 27)
83
98
  h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
84
- h1 = (h1 * 5 + 0x52dce729) & 0xFFFFFFFFFFFFFFFF
99
+ h1 = ((h1 * 5) + 0x52dce729) & 0xFFFFFFFFFFFFFFFF
85
100
 
86
101
  k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
87
102
  k2 = rotl64(k2, 33)
@@ -90,13 +105,14 @@ module Mmh3
90
105
 
91
106
  h2 = rotl64(h2, 31)
92
107
  h2 = (h2 + h1) & 0xFFFFFFFFFFFFFFFF
93
- h2 = (h2 * 5 + 0x38495ab5) & 0xFFFFFFFFFFFFFFFF
108
+ h2 = ((h2 * 5) + 0x38495ab5) & 0xFFFFFFFFFFFFFFFF
94
109
  end
95
110
 
96
111
  tail_id = n_blocks * 16
97
112
  tail_sz = key_len & 15
98
113
 
99
114
  k2 = 0
115
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
100
116
  k2 ^= keyb[tail_id + 14] << 48 if tail_sz >= 15
101
117
  k2 ^= keyb[tail_id + 13] << 40 if tail_sz >= 14
102
118
  k2 ^= keyb[tail_id + 12] << 32 if tail_sz >= 13
@@ -104,6 +120,7 @@ module Mmh3
104
120
  k2 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
105
121
  k2 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
106
122
  k2 ^= keyb[tail_id + 8] if tail_sz >= 9
123
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
107
124
 
108
125
  if tail_sz > 8
109
126
  k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
@@ -113,6 +130,7 @@ module Mmh3
113
130
  end
114
131
 
115
132
  k1 = 0
133
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
116
134
  k1 ^= keyb[tail_id + 7] << 56 if tail_sz >= 8
117
135
  k1 ^= keyb[tail_id + 6] << 48 if tail_sz >= 7
118
136
  k1 ^= keyb[tail_id + 5] << 40 if tail_sz >= 6
@@ -121,6 +139,7 @@ module Mmh3
121
139
  k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
122
140
  k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
123
141
  k1 ^= keyb[tail_id] if tail_sz >= 1
142
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
124
143
 
125
144
  if tail_sz > 0
126
145
  k1 = (k1 * c1) & 0xFFFFFFFFFFFFFFFF
@@ -141,7 +160,7 @@ module Mmh3
141
160
  h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
142
161
  h2 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
143
162
 
144
- h2 << 64 | h1
163
+ (h2 << 64) | h1
145
164
  end
146
165
 
147
166
  def hash128_x86(key, seed = 0)
@@ -171,7 +190,7 @@ module Mmh3
171
190
 
172
191
  h1 = rotl32(h1, 19)
173
192
  h1 = (h1 + h2) & 0xFFFFFFFF
174
- h1 = (h1 * 5 + 0x561ccd1b) & 0xFFFFFFFF
193
+ h1 = ((h1 * 5) + 0x561ccd1b) & 0xFFFFFFFF
175
194
 
176
195
  k2 = (k2 * c2) & 0xFFFFFFFF
177
196
  k2 = rotl32(k2, 16)
@@ -180,7 +199,7 @@ module Mmh3
180
199
 
181
200
  h2 = rotl32(h2, 17)
182
201
  h2 = (h2 + h3) & 0xFFFFFFFF
183
- h2 = (h2 * 5 + 0x0bcaa747) & 0xFFFFFFFF
202
+ h2 = ((h2 * 5) + 0x0bcaa747) & 0xFFFFFFFF
184
203
 
185
204
  k3 = (k3 * c3) & 0xFFFFFFFF
186
205
  k3 = rotl32(k3, 17)
@@ -189,7 +208,7 @@ module Mmh3
189
208
 
190
209
  h3 = rotl32(h3, 15)
191
210
  h3 = (h3 + h4) & 0xFFFFFFFF
192
- h3 = (h3 * 5 + 0x96cd1c35) & 0xFFFFFFFF
211
+ h3 = ((h3 * 5) + 0x96cd1c35) & 0xFFFFFFFF
193
212
 
194
213
  k4 = (k4 * c4) & 0xFFFFFFFF
195
214
  k4 = rotl32(k4, 18)
@@ -198,16 +217,18 @@ module Mmh3
198
217
 
199
218
  h4 = rotl32(h4, 13)
200
219
  h4 = (h4 + h1) & 0xFFFFFFFF
201
- h4 = (h4 * 5 + 0x32ac3b17) & 0xFFFFFFFF
220
+ h4 = ((h4 * 5) + 0x32ac3b17) & 0xFFFFFFFF
202
221
  end
203
222
 
204
223
  tail_id = n_blocks * 16
205
224
  tail_sz = key_len & 15
206
225
 
207
226
  k4 = 0
227
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
208
228
  k4 ^= keyb[tail_id + 14] << 16 if tail_sz >= 15
209
229
  k4 ^= keyb[tail_id + 13] << 8 if tail_sz >= 14
210
230
  k4 ^= keyb[tail_id + 12] if tail_sz >= 13
231
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
211
232
 
212
233
  if tail_sz > 12
213
234
  k4 = (k4 * c4) & 0xFFFFFFFF
@@ -217,10 +238,12 @@ module Mmh3
217
238
  end
218
239
 
219
240
  k3 = 0
241
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
220
242
  k3 ^= keyb[tail_id + 11] << 24 if tail_sz >= 12
221
243
  k3 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
222
244
  k3 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
223
245
  k3 ^= keyb[tail_id + 8] if tail_sz >= 9
246
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
224
247
 
225
248
  if tail_sz > 8
226
249
  k3 = (k3 * c3) & 0xFFFFFFFF
@@ -230,10 +253,12 @@ module Mmh3
230
253
  end
231
254
 
232
255
  k2 = 0
256
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
233
257
  k2 ^= keyb[tail_id + 7] << 24 if tail_sz >= 8
234
258
  k2 ^= keyb[tail_id + 6] << 16 if tail_sz >= 7
235
259
  k2 ^= keyb[tail_id + 5] << 8 if tail_sz >= 6
236
260
  k2 ^= keyb[tail_id + 4] if tail_sz >= 5
261
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
237
262
 
238
263
  if tail_sz > 4
239
264
  k2 = (k2 * c2) & 0xFFFFFFFF
@@ -243,10 +268,12 @@ module Mmh3
243
268
  end
244
269
 
245
270
  k1 = 0
271
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
246
272
  k1 ^= keyb[tail_id + 3] << 24 if tail_sz >= 4
247
273
  k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
248
274
  k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
249
275
  k1 ^= keyb[tail_id] if tail_sz >= 1
276
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
250
277
 
251
278
  if tail_sz > 0
252
279
  k1 = (k1 * c1) & 0xFFFFFFFF
@@ -279,33 +306,37 @@ module Mmh3
279
306
  h3 = (h1 + h3) & 0xFFFFFFFF
280
307
  h4 = (h1 + h4) & 0xFFFFFFFF
281
308
 
282
- h4 << 96 | h3 << 64 | h2 << 32 | h1
309
+ (h4 << 96) | (h3 << 64) | (h2 << 32) | h1
283
310
  end
284
311
 
285
312
  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]
313
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators, Layout/MultilineOperationIndentation
314
+ (kb[bstart + offset + 3] << 24) |
315
+ (kb[bstart + offset + 2] << 16) |
316
+ (kb[bstart + offset + 1] << 8) |
317
+ kb[bstart + offset]
318
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators, Layout/MultilineOperationIndentation
290
319
  end
291
320
 
292
321
  def block64(kb, bstart, offset)
293
- kb[2 * bstart + (7 + offset)] << 56 |
294
- kb[2 * bstart + (6 + offset)] << 48 |
295
- kb[2 * bstart + (5 + offset)] << 40 |
296
- kb[2 * bstart + (4 + offset)] << 32 |
297
- kb[2 * bstart + (3 + offset)] << 24 |
298
- kb[2 * bstart + (2 + offset)] << 16 |
299
- kb[2 * bstart + (1 + offset)] << 8 |
300
- kb[2 * bstart + offset]
322
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators, Layout/MultilineOperationIndentation
323
+ (kb[(2 * bstart) + (7 + offset)] << 56) |
324
+ (kb[(2 * bstart) + (6 + offset)] << 48) |
325
+ (kb[(2 * bstart) + (5 + offset)] << 40) |
326
+ (kb[(2 * bstart) + (4 + offset)] << 32) |
327
+ (kb[(2 * bstart) + (3 + offset)] << 24) |
328
+ (kb[(2 * bstart) + (2 + offset)] << 16) |
329
+ (kb[(2 * bstart) + (1 + offset)] << 8) |
330
+ kb[(2 * bstart) + offset]
331
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators, Layout/MultilineOperationIndentation
301
332
  end
302
333
 
303
334
  def rotl32(x, r)
304
- (x << r | x >> (32 - r)) & 0xFFFFFFFF
335
+ ((x << r) | (x >> (32 - r))) & 0xFFFFFFFF
305
336
  end
306
337
 
307
338
  def rotl64(x, r)
308
- (x << r | x >> (64 - r)) & 0xFFFFFFFFFFFFFFFF
339
+ ((x << r) | (x >> (64 - r))) & 0xFFFFFFFFFFFFFFFF
309
340
  end
310
341
 
311
342
  def scramble32(k)
@@ -332,3 +363,5 @@ module Mmh3
332
363
 
333
364
  private_class_method :hash128_x64, :hash128_x86, :block32, :block64, :rotl32, :rotl64, :scramble32, :fmix32, :fmix64
334
365
  end
366
+
367
+ # rubocop:enable Metrics/AbcSize, Metrics/BlockLength, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ModuleLength, Metrics/PerceivedComplexity
data/mmh3.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'lib/mmh3/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
@@ -13,7 +15,7 @@ Gem::Specification.new do |spec|
13
15
 
14
16
  spec.metadata['homepage_uri'] = spec.homepage
15
17
  spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/mmh3'
16
- spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md'
18
+ spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/mmh3/blob/main/CHANGELOG.md'
17
19
  spec.metadata['documentation_uri'] = 'https://rubydoc.info/gems/mmh3'
18
20
 
19
21
  # Specify which files should be added to the gem when it is released.
@@ -24,4 +26,5 @@ Gem::Specification.new do |spec|
24
26
  spec.bindir = 'exe'
25
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
28
  spec.require_paths = ['lib']
29
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
30
  end
data/sig/mmh3.rbs ADDED
@@ -0,0 +1,18 @@
1
+ module Mmh3
2
+ VERSION: String
3
+
4
+ def self?.hash32: (String key, ?seed: Integer seed) -> Integer
5
+ def self?.hash128: (String key, ?seed: Integer seed, ?x64arch: bool x64arch) -> Integer
6
+
7
+ private
8
+
9
+ def self?.hash128_x64: (String key, ?Integer seed) -> Integer
10
+ def self?.hash128_x86: (String key, ?Integer seed) -> Integer
11
+ def self?.block32: (Array[Integer] kb, Integer bstart, Integer offset) -> Integer
12
+ def self?.block64: (Array[Integer] kb, Integer bstart, Integer offset) -> Integer
13
+ def self?.rotl32: (Integer x, Integer r) -> Integer
14
+ def self?.rotl64: (Integer x, Integer r) -> Integer
15
+ def self?.scramble32: (Integer k) -> Integer
16
+ def self?.fmix32: (Integer h) -> Integer
17
+ def self?.fmix64: (Integer h) -> Integer
18
+ 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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshoku
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-25 00:00:00.000000000 Z
11
+ date: 2022-06-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A pure Ruby implementation of MurmurHash3
14
14
  email:
@@ -17,28 +17,32 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".coveralls.yml"
20
21
  - ".github/workflows/build.yml"
22
+ - ".github/workflows/coverage.yml"
21
23
  - ".gitignore"
22
24
  - ".rspec"
25
+ - ".rubocop.yml"
23
26
  - CHANGELOG.md
24
27
  - Gemfile
25
28
  - LICENSE.txt
26
29
  - README.md
27
30
  - Rakefile
28
- - bin/console
29
- - bin/setup
31
+ - Steepfile
30
32
  - lib/mmh3.rb
31
33
  - lib/mmh3/version.rb
32
34
  - mmh3.gemspec
35
+ - sig/mmh3.rbs
33
36
  homepage: https://github.com/yoshoku/mmh3
34
37
  licenses:
35
38
  - MIT
36
39
  metadata:
37
40
  homepage_uri: https://github.com/yoshoku/mmh3
38
41
  source_code_uri: https://github.com/yoshoku/mmh3
39
- changelog_uri: https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md
42
+ changelog_uri: https://github.com/yoshoku/mmh3/blob/main/CHANGELOG.md
40
43
  documentation_uri: https://rubydoc.info/gems/mmh3
41
- post_install_message:
44
+ rubygems_mfa_required: 'true'
45
+ post_install_message:
42
46
  rdoc_options: []
43
47
  require_paths:
44
48
  - lib
@@ -53,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
57
  - !ruby/object:Gem::Version
54
58
  version: '0'
55
59
  requirements: []
56
- rubygems_version: 3.1.2
57
- signing_key:
60
+ rubygems_version: 3.2.33
61
+ signing_key:
58
62
  specification_version: 4
59
63
  summary: A pure Ruby implementation of MurmurHash3
60
64
  test_files: []
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__)
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