cityhash 0.1.1 → 0.2.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.
- data/README.rdoc +10 -3
- data/cityhash.gemspec +1 -1
- data/lib/cityhash.rb +51 -8
- data/lib/cityhash/ext/libcity.so +0 -0
- data/lib/cityhash/ext/src/Makefile +1 -1
- data/lib/cityhash/version.rb +2 -2
- data/test/test_cityhash.rb +9 -8
- metadata +2 -2
data/README.rdoc
CHANGED
|
@@ -10,9 +10,9 @@ Ruby wrapper for google's cityhash.
|
|
|
10
10
|
|
|
11
11
|
require 'cityhash'
|
|
12
12
|
|
|
13
|
-
CityHash.
|
|
14
|
-
CityHash.
|
|
15
|
-
CityHash.
|
|
13
|
+
CityHash.hash64("test") # => 17703940110308125106
|
|
14
|
+
CityHash.hash64("test", 12345) # => 14900027982776226655
|
|
15
|
+
CityHash.hash64("test", 12345, 54321) # => 11136353178704814373
|
|
16
16
|
|
|
17
17
|
== Contributing to cityhash
|
|
18
18
|
|
|
@@ -24,6 +24,13 @@ Ruby wrapper for google's cityhash.
|
|
|
24
24
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
25
25
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
|
26
26
|
|
|
27
|
+
Authors
|
|
28
|
+
=======
|
|
29
|
+
### [Contributors](http://github.com/nashby/cityhash/contributors)
|
|
30
|
+
- [Johannes Holzfuß](http://github.com/DataWraith)
|
|
31
|
+
|
|
32
|
+
[Vasiliy Ermolovich](http://github.com/nashby/)<br/>
|
|
33
|
+
|
|
27
34
|
== Copyright
|
|
28
35
|
|
|
29
36
|
Copyright (c) 2011 nashby. See LICENSE.txt for
|
data/cityhash.gemspec
CHANGED
data/lib/cityhash.rb
CHANGED
|
@@ -1,12 +1,55 @@
|
|
|
1
1
|
require 'ffi'
|
|
2
2
|
|
|
3
3
|
module CityHash
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
module Internal
|
|
5
|
+
extend FFI::Library
|
|
6
|
+
|
|
7
|
+
ffi_lib File.dirname(__FILE__)+"/cityhash/ext/libcity.so"
|
|
8
|
+
attach_function :city_hash64, :CityHash64, [:string, :size_t], :uint64
|
|
9
|
+
attach_function :city_hash64_with_seed, :CityHash64WithSeed, [:string, :size_t, :uint64], :uint64
|
|
10
|
+
attach_function :city_hash64_with_seeds, :CityHash64WithSeeds, [:string, :size_t, :uint64, :uint64], :uint64
|
|
11
|
+
attach_function :city_hash128, :CityHash128, [:string, :size_t], :ulong
|
|
12
|
+
attach_function :city_hash128_with_seed, :CityHash128WithSeed, [:string, :size_t, :ulong], :ulong
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.hash64(input, seed1 = nil, seed2 = nil)
|
|
16
|
+
input_str = input.to_s
|
|
17
|
+
|
|
18
|
+
# Ruby 1.8 compatibility
|
|
19
|
+
len = 0
|
|
20
|
+
if input_str.respond_to?(:bytesize)
|
|
21
|
+
len = input_str.bytesize
|
|
22
|
+
else
|
|
23
|
+
len = input_str.size
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if seed1.nil?
|
|
27
|
+
return CityHash::Internal.city_hash64(input, len)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
if seed2.nil?
|
|
31
|
+
return CityHash::Internal.city_hash64_with_seed(input, len, seed1.to_i)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
return CityHash::Internal.city_hash64_with_seeds(input, len, seed1.to_i, seed2.to_i)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.hash128(input, seed = nil)
|
|
38
|
+
input_str = input.to_s
|
|
39
|
+
|
|
40
|
+
# Ruby 1.8 compatibility
|
|
41
|
+
len = 0
|
|
42
|
+
if input_str.respond_to?(:bytesize)
|
|
43
|
+
len = input_str.bytesize
|
|
44
|
+
else
|
|
45
|
+
len = input_str.size
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if seed1.nil?
|
|
49
|
+
return CityHash::Internal.city_hash128(input, len)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
return CityHash::Internal.city_hash128_with_seed(input, len, seed.to_i)
|
|
53
|
+
end
|
|
54
|
+
|
|
12
55
|
end
|
data/lib/cityhash/ext/libcity.so
CHANGED
|
Binary file
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
all:
|
|
2
|
-
g++ -shared city.cc -o ../libcity.so
|
|
2
|
+
g++ -shared -fPIC city.cc -o ../libcity.so
|
data/lib/cityhash/version.rb
CHANGED
data/test/test_cityhash.rb
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
require 'helper'
|
|
2
2
|
|
|
3
3
|
class TestCityhash < Test::Unit::TestCase
|
|
4
|
+
|
|
4
5
|
should "return 64bit hash" do
|
|
5
|
-
assert_equal 17703940110308125106, CityHash.
|
|
6
|
+
assert_equal 17703940110308125106, CityHash.hash64("test")
|
|
6
7
|
end
|
|
7
|
-
|
|
8
|
+
|
|
8
9
|
should "return 64bit hash with a seed" do
|
|
9
|
-
assert_equal 14900027982776226655, CityHash.
|
|
10
|
-
end
|
|
11
|
-
|
|
10
|
+
assert_equal 14900027982776226655, CityHash.hash64("test", 12345)
|
|
11
|
+
end
|
|
12
|
+
|
|
12
13
|
should "return 64bit hash with seeds" do
|
|
13
|
-
assert_equal 11136353178704814373, CityHash.
|
|
14
|
-
end
|
|
15
|
-
|
|
14
|
+
assert_equal 11136353178704814373, CityHash.hash64("test", 12345, 54321)
|
|
15
|
+
end
|
|
16
|
+
|
|
16
17
|
end
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: cityhash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.
|
|
5
|
+
version: 0.2.0
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- nashby
|
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
118
118
|
requirements:
|
|
119
119
|
- - ">="
|
|
120
120
|
- !ruby/object:Gem::Version
|
|
121
|
-
hash:
|
|
121
|
+
hash: 738874061
|
|
122
122
|
segments:
|
|
123
123
|
- 0
|
|
124
124
|
version: "0"
|