cityhash 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -10,9 +10,9 @@ Ruby wrapper for google's cityhash.
10
10
 
11
11
  require 'cityhash'
12
12
 
13
- CityHash.city_hash64("test", 4) # => 17703940110308125106
14
- CityHash.city_hash64_with_seed("test", 4, 12345) # => 14900027982776226655
15
- CityHash.city_hash64_with_seeds("test", 4, 12345, 54321) # => 11136353178704814373
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cityhash}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["nashby"]
data/lib/cityhash.rb CHANGED
@@ -1,12 +1,55 @@
1
1
  require 'ffi'
2
2
 
3
3
  module CityHash
4
- extend FFI::Library
5
-
6
- ffi_lib File.dirname(__FILE__)+"/cityhash/ext/libcity.so"
7
- attach_function :city_hash64, :CityHash64, [:string, :size_t], :uint64
8
- attach_function :city_hash64_with_seed, :CityHash64WithSeed, [:string, :size_t, :uint64], :uint64
9
- attach_function :city_hash64_with_seeds, :CityHash64WithSeeds, [:string, :size_t, :uint64, :uint64], :uint64
10
- attach_function :city_hash128, :CityHash128, [:string, :size_t], :ulong
11
- attach_function :city_hash128_with_seed, :CityHash128WithSeed, [:string, :size_t, :ulong], :ulong
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
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
@@ -2,8 +2,8 @@ module CityHash
2
2
 
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 1
6
- PATCH = 1
5
+ MINOR = 2
6
+ PATCH = 0
7
7
  BUILD = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -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.city_hash64("test", 4)
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.city_hash64_with_seed("test", 4, 12345)
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.city_hash64_with_seeds("test", 4, 12345, 54321)
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.1.1
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: 223389711
121
+ hash: 738874061
122
122
  segments:
123
123
  - 0
124
124
  version: "0"