fnv 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/fnv.gemspec +51 -0
  3. data/lib/fnv.rb +10 -10
  4. metadata +4 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -0,0 +1,51 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{fnv}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jake Douglas"]
12
+ s.date = %q{2011-07-16}
13
+ s.email = %q{jakecdouglas@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ "Gemfile",
20
+ "Gemfile.lock",
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "fnv.gemspec",
26
+ "lib/fnv.rb",
27
+ "test/fnv_test.rb",
28
+ "test_fnv.c"
29
+ ]
30
+ s.homepage = %q{https://github.com/jakedouglas/fnv}
31
+ s.licenses = ["MIT"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.6.2}
34
+ s.summary = %q{fnv1 and fnv1a hash functions in pure ruby}
35
+
36
+ if s.respond_to? :specification_version then
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
41
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
42
+ else
43
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
44
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
45
+ end
46
+ else
47
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
49
+ end
50
+ end
51
+
data/lib/fnv.rb CHANGED
@@ -3,29 +3,29 @@ class FNV
3
3
  INIT64 = 0xcbf29ce484222325
4
4
  PRIME32 = 0x01000193
5
5
  PRIME64 = 0x100000001b3
6
- MASK32 = 0xffffffff
7
- MASK64 = 0xffffffffffffffff
6
+ MOD32 = 2 ** 32
7
+ MOD64 = 2 ** 64
8
8
 
9
9
  def fnv1_32(data)
10
10
  hash = INIT32
11
11
 
12
12
  data.bytes.each do |byte|
13
- hash = hash * PRIME32
13
+ hash = (hash * PRIME32) % MOD32
14
14
  hash = hash ^ byte
15
15
  end
16
16
 
17
- hash & MASK32
17
+ hash
18
18
  end
19
19
 
20
20
  def fnv1_64(data)
21
21
  hash = INIT64
22
22
 
23
23
  data.bytes.each do |byte|
24
- hash = hash * PRIME64
24
+ hash = (hash * PRIME64) % MOD64
25
25
  hash = hash ^ byte
26
26
  end
27
27
 
28
- hash & MASK64
28
+ hash
29
29
  end
30
30
 
31
31
  def fnv1a_32(data)
@@ -33,10 +33,10 @@ class FNV
33
33
 
34
34
  data.bytes.each do |byte|
35
35
  hash = hash ^ byte
36
- hash = hash * PRIME32
36
+ hash = (hash * PRIME32) % MOD32
37
37
  end
38
38
 
39
- hash & MASK32
39
+ hash
40
40
  end
41
41
 
42
42
  def fnv1a_64(data)
@@ -44,9 +44,9 @@ class FNV
44
44
 
45
45
  data.bytes.each do |byte|
46
46
  hash = hash ^ byte
47
- hash = hash * PRIME64
47
+ hash = (hash * PRIME64) % MOD64
48
48
  end
49
49
 
50
- hash & MASK64
50
+ hash
51
51
  end
52
52
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fnv
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jake Douglas
@@ -66,6 +66,7 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - VERSION
69
+ - fnv.gemspec
69
70
  - lib/fnv.rb
70
71
  - test/fnv_test.rb
71
72
  - test_fnv.c