sfh 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +20 -0
- data/bin/sfhsum +17 -0
- data/ext/extconf.rb +6 -0
- data/ext/sfh.c +78 -0
- data/ext/sfh.i +3 -0
- data/ext/sfh_wrap.c +1981 -0
- data/ext/test_sfh_swig.rb +5 -0
- data/gemspec.rb +32 -0
- data/sfh.rb +66 -0
- data/test_sfh.rb +15 -0
- metadata +58 -0
data/gemspec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
SPEC = Gem::Specification.new do |spec|
|
5
|
+
spec.name = "sfh"
|
6
|
+
spec.version = "1.0.0"
|
7
|
+
spec.summary = "A gem for SuperFastHash (http://www.azillionmonkeys.com/qed/hash.html)"
|
8
|
+
spec.author = "Jonathan Wilkins"
|
9
|
+
spec.email = "jwilkins[at]nospam[dot]bitland[dot]net"
|
10
|
+
spec.has_rdoc = true
|
11
|
+
spec.extra_rdoc_files = ["README"]
|
12
|
+
spec.require_path = "."
|
13
|
+
spec.autorequire = "sfh.rb"
|
14
|
+
|
15
|
+
unfiltered_files = FileList['*', 'examples/*', 'bin/*', 'ext/*']
|
16
|
+
spec.files = unfiltered_files.delete_if do |filename|
|
17
|
+
filename.include?(".gem") || filename.include?("Makefile") ||
|
18
|
+
filename.include?(".so") || filename.include?(".o")
|
19
|
+
end
|
20
|
+
spec.executables = ['sfhsum']
|
21
|
+
|
22
|
+
# optional native component
|
23
|
+
if cc_command
|
24
|
+
spec.extensions << 'ext/extconf.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
puts "Building gem w/ "
|
28
|
+
spec.files.each do |f|
|
29
|
+
puts "- #{f}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/sfh.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'inline'
|
3
|
+
|
4
|
+
class Sfh
|
5
|
+
inline(:C) do |builder|
|
6
|
+
builder.include '<stdio.h>'
|
7
|
+
builder.include '<sys/types.h>'
|
8
|
+
builder.include '<stdint.h>'
|
9
|
+
|
10
|
+
builder.c '
|
11
|
+
unsigned int hash(const char * data, int len)
|
12
|
+
{
|
13
|
+
unsigned int hash = len, tmp;
|
14
|
+
int rem;
|
15
|
+
|
16
|
+
if (len <= 0 || data == NULL) return 0;
|
17
|
+
|
18
|
+
rem = len & 3;
|
19
|
+
len >>= 2;
|
20
|
+
|
21
|
+
/* Main loop */
|
22
|
+
for (;len > 0; len--) {
|
23
|
+
hash += (*((const uint16_t *) (data)));
|
24
|
+
tmp = ((*((const uint16_t *) (data+2))) << 11) ^ hash;
|
25
|
+
hash = (hash << 16) ^ tmp;
|
26
|
+
data += 2*sizeof (unsigned short);
|
27
|
+
hash += hash >> 11;
|
28
|
+
}
|
29
|
+
|
30
|
+
/* Handle end cases */
|
31
|
+
switch (rem) {
|
32
|
+
case 3: hash += (*((const uint16_t *) (data)));
|
33
|
+
hash ^= hash << 16;
|
34
|
+
hash ^= data[sizeof (unsigned short)] << 18;
|
35
|
+
hash += hash >> 11;
|
36
|
+
break;
|
37
|
+
case 2: hash += (*((const uint16_t *) (data)));
|
38
|
+
hash ^= hash << 11;
|
39
|
+
hash += hash >> 17;
|
40
|
+
break;
|
41
|
+
case 1: hash += *data;
|
42
|
+
hash ^= hash << 10;
|
43
|
+
hash += hash >> 1;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* Force "avalanching" of final 127 bits */
|
47
|
+
hash ^= hash << 3;
|
48
|
+
hash += hash >> 5;
|
49
|
+
hash ^= hash << 4;
|
50
|
+
hash += hash >> 17;
|
51
|
+
hash ^= hash << 25;
|
52
|
+
hash += hash >> 6;
|
53
|
+
|
54
|
+
return hash;
|
55
|
+
}
|
56
|
+
'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if $0 == __FILE__
|
61
|
+
h = Sfh.new()
|
62
|
+
puts "hashing 'asdf' a million times"
|
63
|
+
1000000.times {
|
64
|
+
h.hash('asdf', 4)
|
65
|
+
}
|
66
|
+
end
|
data/test_sfh.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'sfh'
|
2
|
+
|
3
|
+
str = 'asdf'
|
4
|
+
times = 1000000
|
5
|
+
|
6
|
+
h = Sfh.new
|
7
|
+
puts "hashing #{str} #{times} times"
|
8
|
+
times.times { h.hash(str, str.length) }
|
9
|
+
puts "done"
|
10
|
+
|
11
|
+
times = 1000
|
12
|
+
puts "hashing #{str}*1000000 #{times} times"
|
13
|
+
str = str*1000000
|
14
|
+
times.times { h.hash(str, str.length) }
|
15
|
+
puts "done"
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: sfh
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2008-02-17 00:00:00 -08:00
|
8
|
+
summary: A gem for SuperFastHash (http://www.azillionmonkeys.com/qed/hash.html)
|
9
|
+
require_paths:
|
10
|
+
- .
|
11
|
+
email: jwilkins[at]nospam[dot]bitland[dot]net
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: sfh.rb
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Jonathan Wilkins
|
31
|
+
files:
|
32
|
+
- sfh.rb
|
33
|
+
- README
|
34
|
+
- test_sfh.rb
|
35
|
+
- examples
|
36
|
+
- ext
|
37
|
+
- bin
|
38
|
+
- gemspec.rb
|
39
|
+
- bin/sfhsum
|
40
|
+
- ext/sfh.c
|
41
|
+
- ext/test_sfh_swig.rb
|
42
|
+
- ext/sfh_wrap.c
|
43
|
+
- ext/sfh.i
|
44
|
+
- ext/extconf.rb
|
45
|
+
test_files: []
|
46
|
+
|
47
|
+
rdoc_options: []
|
48
|
+
|
49
|
+
extra_rdoc_files:
|
50
|
+
- README
|
51
|
+
executables:
|
52
|
+
- sfhsum
|
53
|
+
extensions:
|
54
|
+
- ext/extconf.rb
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
dependencies: []
|
58
|
+
|