rbfnv19 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+
2
+ v1.0. it works.
3
+
4
+ v0.9. experiment.
@@ -0,0 +1,6 @@
1
+ CHANGELOG
2
+ Manifest
3
+ Rakefile
4
+ ext/extconf.rb
5
+ ext/fnv.c
6
+ test/unit/fnv_test.rb
@@ -0,0 +1,12 @@
1
+ require 'echoe'
2
+
3
+ Echoe.new("rbfnv19") do |p|
4
+ p.author = "Susan Potter (1.9.x)"
5
+ p.email = "me@susanpotter.net"
6
+ p.url = "https://github.com/mbbx6spp/rbfnv"
7
+ p.project = "rbfnv19"
8
+ p.version = "0.1"
9
+ p.summary = "FNV hash implementation for Ruby using C implementation"
10
+ p.description = "Based heavily on the now broken rbfnv gem that does not build with Ruby 1.9."
11
+ p.rdoc_pattern = /README|TODO|LICENSE|CHANGELOG|BENCH|COMPAT|exceptions|behaviors|rails.rb/
12
+ end
@@ -0,0 +1,10 @@
1
+
2
+ require 'mkmf'
3
+
4
+ $CFLAGS << " -O3"
5
+ if ENV['DEBUG']
6
+ puts "setting debug flags"
7
+ $CFLAGS << " -ggdb -DHAVE_DEBUG"
8
+ end
9
+
10
+ create_makefile 'rbfnv'
@@ -0,0 +1,88 @@
1
+ #include <stdint.h>
2
+ #include "ruby.h"
3
+
4
+ #define PRIME32 16777619
5
+ #define PRIME64 1099511628211UL
6
+
7
+ /**
8
+ * FNV fast hashing algorithm in 32 bits.
9
+ * @see http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
10
+ */
11
+ static inline uint64_t fnv1_32(const char *data, uint64_t len) {
12
+ uint64_t rv = 0x811c9dc5U;
13
+ uint64_t i;
14
+ for (i = 0; i < len; i++) {
15
+ rv = (rv * PRIME32) ^ (unsigned char)(data[i]);
16
+ }
17
+ return rv;
18
+ }
19
+
20
+ /**
21
+ * FNV fast hashing algorithm in 32 bits, variant with operations reversed.
22
+ * @see http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
23
+ */
24
+ static inline uint64_t fnv1a_32(const char *data, uint64_t len) {
25
+ uint64_t rv = 0x811c9dc5U;
26
+ uint64_t i;
27
+ for (i = 0; i < len; i++) {
28
+ rv = (rv ^ (unsigned char)data[i]) * PRIME32;
29
+ }
30
+ return rv;
31
+ }
32
+
33
+ /**
34
+ * FNV fast hashing algorithm in 64 bits.
35
+ * @see http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
36
+ */
37
+ static inline uint64_t fnv1_64(const char *data, uint64_t len) {
38
+ uint64_t rv = 0xcbf29ce484222325UL;
39
+ uint64_t i;
40
+ for (i = 0; i < len; i++) {
41
+ rv = (rv * PRIME64) ^ (unsigned char)data[i];
42
+ }
43
+ return (uint64_t)rv;
44
+ }
45
+
46
+ /**
47
+ * FNV fast hashing algorithm in 64 bits, variant with operations reversed.
48
+ * @see http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash
49
+ */
50
+ static inline uint64_t fnv1a_64(const char *data, uint64_t len) {
51
+ uint64_t rv = 0xcbf29ce484222325UL;
52
+ uint64_t i;
53
+ for (i = 0; i < len; i++) {
54
+ rv = (rv ^ (unsigned char)data[i]) * PRIME64;
55
+ }
56
+ return (uint64_t)rv;
57
+ }
58
+
59
+
60
+ /* ----- ruby bindings ----- */
61
+
62
+ static VALUE rbfnv_fnv1_32(VALUE self, VALUE data) {
63
+ return UINT2NUM(fnv1_32(RSTRING_PTR(data), RSTRING_LEN(data)));
64
+ }
65
+
66
+ static VALUE rbfnv_fnv1a_32(VALUE self, VALUE data) {
67
+ return UINT2NUM(fnv1a_32(RSTRING_PTR(data), RSTRING_LEN(data)));
68
+ }
69
+
70
+ static VALUE rbfnv_fnv1_64(VALUE self, VALUE data) {
71
+ return UINT2NUM(fnv1_64(RSTRING_PTR(data), RSTRING_LEN(data)));
72
+ }
73
+
74
+ static VALUE rbfnv_fnv1a_64(VALUE self, VALUE data) {
75
+ return UINT2NUM(fnv1a_64(RSTRING_PTR(data), RSTRING_LEN(data)));
76
+ }
77
+
78
+
79
+ static VALUE rb_rbfnv;
80
+
81
+ void Init_rbfnv() {
82
+ /* nothing here yet */
83
+ rb_rbfnv = rb_define_module("Rbfnv");
84
+ rb_define_singleton_method(rb_rbfnv, "fnv1_32", rbfnv_fnv1_32, 1);
85
+ rb_define_singleton_method(rb_rbfnv, "fnv1a_32", rbfnv_fnv1a_32, 1);
86
+ rb_define_singleton_method(rb_rbfnv, "fnv1_64", rbfnv_fnv1_64, 1);
87
+ rb_define_singleton_method(rb_rbfnv, "fnv1a_64", rbfnv_fnv1a_64, 1);
88
+ }
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "rbfnv19"
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Susan Potter (1.9.x)"]
9
+ s.date = "2011-12-16"
10
+ s.description = "Based heavily on the now broken rbfnv gem that does not build with Ruby 1.9."
11
+ s.email = "me@susanpotter.net"
12
+ s.extensions = ["ext/extconf.rb"]
13
+ s.extra_rdoc_files = ["CHANGELOG"]
14
+ s.files = ["CHANGELOG", "Manifest", "Rakefile", "ext/extconf.rb", "ext/fnv.c", "test/unit/fnv_test.rb", "rbfnv19.gemspec"]
15
+ s.homepage = "https://github.com/mbbx6spp/rbfnv"
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rbfnv19"]
17
+ s.require_paths = ["lib", "ext"]
18
+ s.rubyforge_project = "rbfnv19"
19
+ s.rubygems_version = "1.8.10"
20
+ s.summary = "FNV hash implementation for Ruby using C implementation"
21
+ s.test_files = ["test/unit/fnv_test.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ s.specification_version = 3
25
+
26
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
+ else
28
+ end
29
+ else
30
+ end
31
+ end
@@ -0,0 +1,34 @@
1
+ require "test/unit"
2
+ require "rbfnv"
3
+
4
+ LONGKEY = "the easter island statue memorial tabernacle choir presents"
5
+
6
+ class FnvTest < Test::Unit::TestCase
7
+ def test_fnv1_32
8
+ assert_nothing_raised { Rbfnv }
9
+ assert_equal Rbfnv.fnv1_32(""), 2166136261
10
+ assert_equal Rbfnv.fnv1_32("cat"), 983016379
11
+ assert_equal Rbfnv.fnv1_32(LONGKEY), 2223726839
12
+ end
13
+
14
+ def test_fnv1a_32
15
+ assert_nothing_raised { Rbfnv }
16
+ assert_equal Rbfnv.fnv1a_32(""), 2166136261
17
+ assert_equal Rbfnv.fnv1a_32("cat"), 108289031
18
+ assert_equal Rbfnv.fnv1a_32(LONGKEY), 1968151335
19
+ end
20
+
21
+ def test_fnv1_64
22
+ assert_nothing_raised { Rbfnv }
23
+ assert_equal Rbfnv.fnv1_64(""), 2216829733
24
+ assert_equal Rbfnv.fnv1_64("cat"), 1806270427
25
+ assert_equal Rbfnv.fnv1_64(LONGKEY), 3588698999
26
+ end
27
+
28
+ def test_fnv1a_64
29
+ assert_nothing_raised { Rbfnv }
30
+ assert_equal Rbfnv.fnv1a_64(""), 2216829733
31
+ assert_equal Rbfnv.fnv1a_64("cat"), 216310567
32
+ assert_equal Rbfnv.fnv1a_64(LONGKEY), 2969891175
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbfnv19
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Susan Potter (1.9.x)
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-16 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: Based heavily on the now broken rbfnv gem that does not build with Ruby
15
+ 1.9.
16
+ email: me@susanpotter.net
17
+ executables: []
18
+ extensions:
19
+ - ext/extconf.rb
20
+ extra_rdoc_files:
21
+ - CHANGELOG
22
+ files:
23
+ - CHANGELOG
24
+ - Manifest
25
+ - Rakefile
26
+ - ext/extconf.rb
27
+ - ext/fnv.c
28
+ - test/unit/fnv_test.rb
29
+ - rbfnv19.gemspec
30
+ homepage: https://github.com/mbbx6spp/rbfnv
31
+ licenses: []
32
+ post_install_message:
33
+ rdoc_options:
34
+ - --line-numbers
35
+ - --inline-source
36
+ - --title
37
+ - Rbfnv19
38
+ require_paths:
39
+ - lib
40
+ - ext
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
53
+ requirements: []
54
+ rubyforge_project: rbfnv19
55
+ rubygems_version: 1.8.10
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: FNV hash implementation for Ruby using C implementation
59
+ test_files:
60
+ - test/unit/fnv_test.rb