mmh3 1.1.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: f9232bb276c9e81d9283f72dd767cfac0a32a639f36051ba1719415ce941d32a
4
- data.tar.gz: 2a8bcb3958785b4f198b0aeb505dec3bf50d3ab827ec981613583eae6caaffce
3
+ metadata.gz: 70a69ac210acc55f49b85764ddacced777cd5b14c515c587b22e77a08479356e
4
+ data.tar.gz: 320c6db6188375dd16f065164691af0c254bcdc01968a5dd7318b087c6bdc896
5
5
  SHA512:
6
- metadata.gz: 1c99ca7f0f22ed5ee7ec6adef36bc19b9456afdc8c51ae74a970e62266e5336f2bc4617795d28210a03f1591b82980a8c9f188581c619f495765685c315ab920
7
- data.tar.gz: 67df0cd6af0f55a1a5d2bc257c136e4af4ca637783f1c68bde550319a52078ef67fb51c3f9ecc303988f9b0d0a72f2b9053e4d4c9f3dbb83d88d8ea6cc49f645
6
+ metadata.gz: b533e1bf9b5bb655eef411e0b4f5e6cf184dfab4c9053513771941aa851f2abc768c2d81c6c97ebd37d2af7232d8f091cb9511fb8e6f2b23759727e944872555
7
+ data.tar.gz: dbf836b9f3e3f7cef52aa4aa414f58f960592533f40d6bbf885250ee2ce36d12bd68dd43b2c3b0417d3fbc76c5222be94dd9367b26c419d0f768fb140cbbd2c5
@@ -6,16 +6,15 @@ jobs:
6
6
  build:
7
7
  runs-on: ubuntu-latest
8
8
  strategy:
9
+ fail-fast: false
9
10
  matrix:
10
- ruby: [ '2.6', '2.7', '3.0' ]
11
+ ruby: [ '2.7', '3.0', '3.1' ]
11
12
  steps:
12
- - uses: actions/checkout@v2
13
+ - uses: actions/checkout@v3
13
14
  - name: Set up Ruby ${{ matrix.ruby }}
14
- uses: actions/setup-ruby@v1
15
+ uses: ruby/setup-ruby@v1
15
16
  with:
16
17
  ruby-version: ${{ matrix.ruby }}
18
+ bundler-cache: true
17
19
  - name: Build and test with Rake
18
- run: |
19
- gem install bundler
20
- bundle install --jobs 4 --retry 3
21
- bundle exec rake
20
+ run: bundle exec rake
@@ -12,14 +12,12 @@ jobs:
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
14
  - name: Set up Ruby 2.7
15
- uses: actions/setup-ruby@v1
15
+ uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  ruby-version: '2.7'
18
+ bundler-cache: true
18
19
  - name: Build and test with Rake
19
- run: |
20
- gem install bundler
21
- bundle install --jobs 4 --retry 3
22
- bundle exec rake
20
+ run: bundle exec rake
23
21
  - name: Coveralls GitHub Action
24
22
  uses: coverallsapp/github-action@v1.1.2
25
23
  with:
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,6 @@
1
+ # 1.2.0
2
+ - Refactor codes and configs with RuboCop.
3
+
1
4
  # 1.1.0
2
5
  - Add type declaration file: sig/mmh3.rbs
3
6
 
data/Gemfile CHANGED
@@ -1,11 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in mmh3.gemspec
4
6
  gemspec
5
7
 
6
8
  gem 'rake', '~> 12.0'
9
+ gem 'rbs', '~> 1.2'
7
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'
8
15
  gem 'simplecov', '~> 0.21'
9
16
  gem 'simplecov-lcov', '~> 0.8'
10
- gem 'rbs', '~> 1.2'
11
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-2021 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/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/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 = '1.1.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.
@@ -29,16 +31,18 @@ module Mmh3
29
31
  k = block32(keyb, bstart, 0)
30
32
  h ^= scramble32(k)
31
33
  h = rotl32(h, 13)
32
- h = (h * 5 + 0xe6546b64) & 0xFFFFFFFF
34
+ h = ((h * 5) + 0xe6546b64) & 0xFFFFFFFF
33
35
  end
34
36
 
35
37
  tail_id = n_blocks * 4
36
38
  tail_sz = key_len & 3
37
39
 
38
40
  k = 0
41
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
39
42
  k ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
40
43
  k ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
41
44
  k ^= keyb[tail_id + 0] if tail_sz >= 1
45
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
42
46
 
43
47
  h ^= scramble32(k) if tail_sz.positive?
44
48
 
@@ -92,7 +96,7 @@ module Mmh3
92
96
 
93
97
  h1 = rotl64(h1, 27)
94
98
  h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
95
- h1 = (h1 * 5 + 0x52dce729) & 0xFFFFFFFFFFFFFFFF
99
+ h1 = ((h1 * 5) + 0x52dce729) & 0xFFFFFFFFFFFFFFFF
96
100
 
97
101
  k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
98
102
  k2 = rotl64(k2, 33)
@@ -101,13 +105,14 @@ module Mmh3
101
105
 
102
106
  h2 = rotl64(h2, 31)
103
107
  h2 = (h2 + h1) & 0xFFFFFFFFFFFFFFFF
104
- h2 = (h2 * 5 + 0x38495ab5) & 0xFFFFFFFFFFFFFFFF
108
+ h2 = ((h2 * 5) + 0x38495ab5) & 0xFFFFFFFFFFFFFFFF
105
109
  end
106
110
 
107
111
  tail_id = n_blocks * 16
108
112
  tail_sz = key_len & 15
109
113
 
110
114
  k2 = 0
115
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
111
116
  k2 ^= keyb[tail_id + 14] << 48 if tail_sz >= 15
112
117
  k2 ^= keyb[tail_id + 13] << 40 if tail_sz >= 14
113
118
  k2 ^= keyb[tail_id + 12] << 32 if tail_sz >= 13
@@ -115,6 +120,7 @@ module Mmh3
115
120
  k2 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
116
121
  k2 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
117
122
  k2 ^= keyb[tail_id + 8] if tail_sz >= 9
123
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
118
124
 
119
125
  if tail_sz > 8
120
126
  k2 = (k2 * c2) & 0xFFFFFFFFFFFFFFFF
@@ -124,6 +130,7 @@ module Mmh3
124
130
  end
125
131
 
126
132
  k1 = 0
133
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
127
134
  k1 ^= keyb[tail_id + 7] << 56 if tail_sz >= 8
128
135
  k1 ^= keyb[tail_id + 6] << 48 if tail_sz >= 7
129
136
  k1 ^= keyb[tail_id + 5] << 40 if tail_sz >= 6
@@ -132,6 +139,7 @@ module Mmh3
132
139
  k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
133
140
  k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
134
141
  k1 ^= keyb[tail_id] if tail_sz >= 1
142
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
135
143
 
136
144
  if tail_sz > 0
137
145
  k1 = (k1 * c1) & 0xFFFFFFFFFFFFFFFF
@@ -152,7 +160,7 @@ module Mmh3
152
160
  h1 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
153
161
  h2 = (h1 + h2) & 0xFFFFFFFFFFFFFFFF
154
162
 
155
- h2 << 64 | h1
163
+ (h2 << 64) | h1
156
164
  end
157
165
 
158
166
  def hash128_x86(key, seed = 0)
@@ -182,7 +190,7 @@ module Mmh3
182
190
 
183
191
  h1 = rotl32(h1, 19)
184
192
  h1 = (h1 + h2) & 0xFFFFFFFF
185
- h1 = (h1 * 5 + 0x561ccd1b) & 0xFFFFFFFF
193
+ h1 = ((h1 * 5) + 0x561ccd1b) & 0xFFFFFFFF
186
194
 
187
195
  k2 = (k2 * c2) & 0xFFFFFFFF
188
196
  k2 = rotl32(k2, 16)
@@ -191,7 +199,7 @@ module Mmh3
191
199
 
192
200
  h2 = rotl32(h2, 17)
193
201
  h2 = (h2 + h3) & 0xFFFFFFFF
194
- h2 = (h2 * 5 + 0x0bcaa747) & 0xFFFFFFFF
202
+ h2 = ((h2 * 5) + 0x0bcaa747) & 0xFFFFFFFF
195
203
 
196
204
  k3 = (k3 * c3) & 0xFFFFFFFF
197
205
  k3 = rotl32(k3, 17)
@@ -200,7 +208,7 @@ module Mmh3
200
208
 
201
209
  h3 = rotl32(h3, 15)
202
210
  h3 = (h3 + h4) & 0xFFFFFFFF
203
- h3 = (h3 * 5 + 0x96cd1c35) & 0xFFFFFFFF
211
+ h3 = ((h3 * 5) + 0x96cd1c35) & 0xFFFFFFFF
204
212
 
205
213
  k4 = (k4 * c4) & 0xFFFFFFFF
206
214
  k4 = rotl32(k4, 18)
@@ -209,16 +217,18 @@ module Mmh3
209
217
 
210
218
  h4 = rotl32(h4, 13)
211
219
  h4 = (h4 + h1) & 0xFFFFFFFF
212
- h4 = (h4 * 5 + 0x32ac3b17) & 0xFFFFFFFF
220
+ h4 = ((h4 * 5) + 0x32ac3b17) & 0xFFFFFFFF
213
221
  end
214
222
 
215
223
  tail_id = n_blocks * 16
216
224
  tail_sz = key_len & 15
217
225
 
218
226
  k4 = 0
227
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
219
228
  k4 ^= keyb[tail_id + 14] << 16 if tail_sz >= 15
220
229
  k4 ^= keyb[tail_id + 13] << 8 if tail_sz >= 14
221
230
  k4 ^= keyb[tail_id + 12] if tail_sz >= 13
231
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
222
232
 
223
233
  if tail_sz > 12
224
234
  k4 = (k4 * c4) & 0xFFFFFFFF
@@ -228,10 +238,12 @@ module Mmh3
228
238
  end
229
239
 
230
240
  k3 = 0
241
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
231
242
  k3 ^= keyb[tail_id + 11] << 24 if tail_sz >= 12
232
243
  k3 ^= keyb[tail_id + 10] << 16 if tail_sz >= 11
233
244
  k3 ^= keyb[tail_id + 9] << 8 if tail_sz >= 10
234
245
  k3 ^= keyb[tail_id + 8] if tail_sz >= 9
246
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
235
247
 
236
248
  if tail_sz > 8
237
249
  k3 = (k3 * c3) & 0xFFFFFFFF
@@ -241,10 +253,12 @@ module Mmh3
241
253
  end
242
254
 
243
255
  k2 = 0
256
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
244
257
  k2 ^= keyb[tail_id + 7] << 24 if tail_sz >= 8
245
258
  k2 ^= keyb[tail_id + 6] << 16 if tail_sz >= 7
246
259
  k2 ^= keyb[tail_id + 5] << 8 if tail_sz >= 6
247
260
  k2 ^= keyb[tail_id + 4] if tail_sz >= 5
261
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
248
262
 
249
263
  if tail_sz > 4
250
264
  k2 = (k2 * c2) & 0xFFFFFFFF
@@ -254,10 +268,12 @@ module Mmh3
254
268
  end
255
269
 
256
270
  k1 = 0
271
+ # rubocop:disable Layout/ExtraSpacing, Layout/SpaceAroundOperators
257
272
  k1 ^= keyb[tail_id + 3] << 24 if tail_sz >= 4
258
273
  k1 ^= keyb[tail_id + 2] << 16 if tail_sz >= 3
259
274
  k1 ^= keyb[tail_id + 1] << 8 if tail_sz >= 2
260
275
  k1 ^= keyb[tail_id] if tail_sz >= 1
276
+ # rubocop:enable Layout/ExtraSpacing, Layout/SpaceAroundOperators
261
277
 
262
278
  if tail_sz > 0
263
279
  k1 = (k1 * c1) & 0xFFFFFFFF
@@ -290,33 +306,37 @@ module Mmh3
290
306
  h3 = (h1 + h3) & 0xFFFFFFFF
291
307
  h4 = (h1 + h4) & 0xFFFFFFFF
292
308
 
293
- h4 << 96 | h3 << 64 | h2 << 32 | h1
309
+ (h4 << 96) | (h3 << 64) | (h2 << 32) | h1
294
310
  end
295
311
 
296
312
  def block32(kb, bstart, offset)
297
- kb[bstart + offset + 3] << 24 |
298
- kb[bstart + offset + 2] << 16 |
299
- kb[bstart + offset + 1] << 8 |
300
- 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
301
319
  end
302
320
 
303
321
  def block64(kb, bstart, offset)
304
- kb[2 * bstart + (7 + offset)] << 56 |
305
- kb[2 * bstart + (6 + offset)] << 48 |
306
- kb[2 * bstart + (5 + offset)] << 40 |
307
- kb[2 * bstart + (4 + offset)] << 32 |
308
- kb[2 * bstart + (3 + offset)] << 24 |
309
- kb[2 * bstart + (2 + offset)] << 16 |
310
- kb[2 * bstart + (1 + offset)] << 8 |
311
- 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
312
332
  end
313
333
 
314
334
  def rotl32(x, r)
315
- (x << r | x >> (32 - r)) & 0xFFFFFFFF
335
+ ((x << r) | (x >> (32 - r))) & 0xFFFFFFFF
316
336
  end
317
337
 
318
338
  def rotl64(x, r)
319
- (x << r | x >> (64 - r)) & 0xFFFFFFFFFFFFFFFF
339
+ ((x << r) | (x >> (64 - r))) & 0xFFFFFFFFFFFFFFFF
320
340
  end
321
341
 
322
342
  def scramble32(k)
@@ -343,3 +363,5 @@ module Mmh3
343
363
 
344
364
  private_class_method :hash128_x64, :hash128_x86, :block32, :block64, :rotl32, :rotl64, :scramble32, :fmix32, :fmix64
345
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|
@@ -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
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: 1.1.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: 2021-05-29 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:
@@ -22,6 +22,7 @@ files:
22
22
  - ".github/workflows/coverage.yml"
23
23
  - ".gitignore"
24
24
  - ".rspec"
25
+ - ".rubocop.yml"
25
26
  - CHANGELOG.md
26
27
  - Gemfile
27
28
  - LICENSE.txt
@@ -40,7 +41,8 @@ metadata:
40
41
  source_code_uri: https://github.com/yoshoku/mmh3
41
42
  changelog_uri: https://github.com/yoshoku/mmh3/blob/main/CHANGELOG.md
42
43
  documentation_uri: https://rubydoc.info/gems/mmh3
43
- post_install_message:
44
+ rubygems_mfa_required: 'true'
45
+ post_install_message:
44
46
  rdoc_options: []
45
47
  require_paths:
46
48
  - lib
@@ -55,8 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
57
  - !ruby/object:Gem::Version
56
58
  version: '0'
57
59
  requirements: []
58
- rubygems_version: 3.1.6
59
- signing_key:
60
+ rubygems_version: 3.2.33
61
+ signing_key:
60
62
  specification_version: 4
61
63
  summary: A pure Ruby implementation of MurmurHash3
62
64
  test_files: []