java_hash_code 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15d22b49f05037f69c3238c00f4418561385e443
4
+ data.tar.gz: d287907abd0d79a81d4e0da057d212ae83d3ec26
5
+ SHA512:
6
+ metadata.gz: a1928b9716c0d76e3793e2a8f639366533c267bdc807d81b9fe9b053eab41c1b8252e384363face07b77d412d4ba4e8e8d45fbca87874549b317f443a78e1376
7
+ data.tar.gz: dac4dbfe7abc39734b7c0a2ea7e1b6bbe52c8aa2897fa067e9b77c3c28d5953ea2e9a4251c6f21d2f7825ac602fb4fd180bd403f517e376705651e139619b411
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea/
11
+
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Artem Baikuzin
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,36 @@
1
+ # JavaHashCode
2
+
3
+ Computes hash for given string with Java [hashCode algorithm](https://en.wikipedia.org/wiki/Java_hashCode())
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'java_hash_code'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install java_hash_code
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ require 'java_hash_code'
25
+
26
+ JavaHashCode.compute('1234 ABC abc') # returns 892228006
27
+ ```
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ybinzu/java_hash_code.
32
+
33
+
34
+ ## License
35
+
36
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'java_hash_code/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'java_hash_code'
8
+ spec.version = JavaHashCode::VERSION
9
+ spec.authors = ['Artem Baikuzin']
10
+ spec.email = ['artembaykuzin@gmail.com']
11
+
12
+ spec.summary = %q{Java hash code algorithm for string}
13
+ spec.description = %q{Computes java hashCode algorithm for given string}
14
+ spec.homepage = 'https://github.com/ybinzu/java_hash_code'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.13'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'minitest', '~> 5.0'
27
+ end
@@ -0,0 +1,24 @@
1
+ require 'java_hash_code/version'
2
+
3
+ module JavaHashCode
4
+ ##
5
+ # Computes hash for given string with Java hashCode algorithm
6
+ #
7
+ # ==== Example
8
+ # JavaHashCode.compute('1234') # 1509442
9
+ # JavaHashCode.compute('ABC abc') # -489353340
10
+ # JavaHashCode.compute('АБВ') # 1032753
11
+ #
12
+ def self.compute(string_value)
13
+ return 0 if string_value.nil? || string_value.empty?
14
+ hash = 0
15
+
16
+ power = string_value.size - 1
17
+ string_value.each_char do |char|
18
+ hash += char.ord * (31 ** power)
19
+ power -= 1
20
+ end
21
+
22
+ [hash].pack('L').unpack('l')[0]
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module JavaHashCode
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: java_hash_code
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Artem Baikuzin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Computes java hashCode algorithm for given string
56
+ email:
57
+ - artembaykuzin@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - java_hash_code.gemspec
68
+ - lib/java_hash_code.rb
69
+ - lib/java_hash_code/version.rb
70
+ homepage: https://github.com/ybinzu/java_hash_code
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.6.10
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Java hash code algorithm for string
94
+ test_files: []