mmh3 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0a69bb53a4e9f7a3a63711f27669f2172ee3e61000961b453bd428fb0dd5147f
4
+ data.tar.gz: 5ec35b7d7b436d01c798cf5478e652066477dbf28f1f5be2e6947ac8535d695c
5
+ SHA512:
6
+ metadata.gz: 69bf8ef42fe0e46d7954df35d3fe3f43693fe0f7bfe1ab38ea16f81be69c7a08ebe183fb6d51a7c6b133afeb0b757ea44f5d36bcfb36bd95a6e55492e56cb452
7
+ data.tar.gz: d19e0b3fe2f766569a166234d16f2940fa3e15ff28d2609c34cf18acf29387a1d58afa20376ead005e828f70c551fd96e9aee75d65286ecaa4bb7b3bfbcf125a
@@ -0,0 +1,20 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ 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
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in mmh3.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 yoshoku
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # Mmh3
2
+
3
+ ![Ruby](https://github.com/yoshoku/mmh3/workflows/Ruby/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/mmh3.svg)](https://badge.fury.io/rb/mmh3)
5
+
6
+ A pure Ruby implementation of [MurmurHash3](https://en.wikipedia.org/wiki/MurmurHash).
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'mmh3'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install mmh3
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ require 'mmh3'
28
+
29
+ puts Mmh3.hash32('Hello, world', 10)
30
+
31
+ # => -172601702
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/mmh3.
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
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__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mmh3/version'
4
+
5
+ # This module consists module functions that implement MurmurHash3.
6
+ # MurmurHash3 was written by Austin Appleby, and is placed in the public domain.
7
+ # The author hereby disclaims copyright to this source code.
8
+ module Mmh3
9
+ module_function
10
+
11
+ # Generate a 32-bit hash value.
12
+ #
13
+ # @param key [String] Key for hash value.
14
+ # @param seed [Integer] Seed for hash value.
15
+ #
16
+ # @return [Integer] Returns hash value.
17
+ def hash32(key, seed = 0)
18
+ keyb = key.to_s.bytes
19
+ key_len = keyb.size
20
+ n_blocks = key_len / 4
21
+
22
+ h = seed
23
+ (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]
25
+ h ^= scramble32(k)
26
+ h = rotl32(h, 13)
27
+ h = (h * 5 + 0xe6546b64) & 0xFFFFFFFF
28
+ end
29
+
30
+ tail_id = n_blocks * 4
31
+ tail_sz = key_len & 3
32
+
33
+ k = 0
34
+ 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
37
+ h ^= scramble32(k) if tail_sz.positive?
38
+
39
+ h = fmix32(h ^ key_len)
40
+
41
+ if (h & 0x80000000).zero?
42
+ h
43
+ else
44
+ -((h ^ 0xFFFFFFFF) + 1)
45
+ end
46
+ end
47
+
48
+ def rotl32(x, r)
49
+ (x << r | x >> (32 - r)) & 0xFFFFFFFF
50
+ end
51
+
52
+ def scramble32(k)
53
+ k = (k * 0xcc9e2d51) & 0xFFFFFFFF
54
+ k = rotl32(k, 15)
55
+ (k * 0x1b873593) & 0xFFFFFFFF
56
+ end
57
+
58
+ def fmix32(h)
59
+ h ^= h >> 16
60
+ h = (h * 0x85ebca6b) & 0xFFFFFFFF
61
+ h ^= h >> 13
62
+ h = (h * 0xc2b2ae35) & 0xFFFFFFFF
63
+ h ^ (h >> 16)
64
+ end
65
+
66
+ private_class_method :rotl32, :scramble32, :fmix32
67
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mmh3
4
+ # Version number of Mmh3 you are using.
5
+ VERSION = '0.1.0'
6
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'lib/mmh3/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'mmh3'
5
+ spec.version = Mmh3::VERSION
6
+ spec.authors = ['yoshoku']
7
+ spec.email = ['yoshoku@outlook.com']
8
+
9
+ spec.summary = 'A pure Ruby implementation of MurmurHash3'
10
+ spec.description = 'A pure Ruby implementation of MurmurHash3'
11
+ spec.homepage = 'https://github.com/yoshoku/mmh3'
12
+ spec.license = 'MIT'
13
+
14
+ spec.metadata['homepage_uri'] = spec.homepage
15
+ spec.metadata['source_code_uri'] = 'https://github.com/yoshoku/mmh3'
16
+ spec.metadata['changelog_uri'] = 'https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md'
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmh3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yoshoku
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A pure Ruby implementation of MurmurHash3
14
+ email:
15
+ - yoshoku@outlook.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/build.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - lib/mmh3.rb
30
+ - lib/mmh3/version.rb
31
+ - mmh3.gemspec
32
+ homepage: https://github.com/yoshoku/mmh3
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/yoshoku/mmh3
37
+ source_code_uri: https://github.com/yoshoku/mmh3
38
+ changelog_uri: https://github.com/yoshoku/mmh3/blob/master/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.1.2
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: A pure Ruby implementation of MurmurHash3
58
+ test_files: []