cityhash 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -13,6 +13,8 @@ Ruby wrapper for google's cityhash.
13
13
  CityHash.hash64("test") # => 17703940110308125106
14
14
  CityHash.hash64("test", 12345) # => 14900027982776226655
15
15
  CityHash.hash64("test", 12345, 54321) # => 11136353178704814373
16
+ CityHash.hash128("test") # => 130554790001792308794529643941127319555
17
+ CityHash.hash128("test", [123,123]) # => 183946415266487905135364192266033899899
16
18
 
17
19
  ### Contributing to cityhash
18
20
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cityhash}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.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"]
12
- s.date = %q{2011-04-22}
12
+ s.date = %q{2011-04-23}
13
13
  s.description = %q{ffi wrapper for google's cityhash}
14
14
  s.email = %q{younash@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
29
29
  "lib/cityhash/ext/src/Makefile",
30
30
  "lib/cityhash/ext/src/city.cc",
31
31
  "lib/cityhash/ext/src/city.h",
32
+ "lib/cityhash/ext/src/city_ruby_bridge.cpp",
33
+ "lib/cityhash/ext/src/city_ruby_bridge.h",
32
34
  "lib/cityhash/version.rb",
33
35
  "test/helper.rb",
34
36
  "test/test_cityhash.rb"
@@ -8,8 +8,8 @@ module CityHash
8
8
  attach_function :city_hash64, :CityHash64, [:string, :size_t], :uint64
9
9
  attach_function :city_hash64_with_seed, :CityHash64WithSeed, [:string, :size_t, :uint64], :uint64
10
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
11
+ attach_function :city_hash128, :CityHash128String, [:string, :size_t], :string
12
+ attach_function :city_hash128_with_seed, :CityHash128WithSeedString, [:string, :size_t, :uint64, :uint64], :string
13
13
  end
14
14
 
15
15
  def self.hash64(input, seed1 = nil, seed2 = nil)
@@ -34,7 +34,7 @@ module CityHash
34
34
  return CityHash::Internal.city_hash64_with_seeds(input_str, len, seed1.to_i, seed2.to_i)
35
35
  end
36
36
 
37
- def self.hash128(input, seed = nil)
37
+ def self.hash128(input, seed = [])
38
38
  input_str = input.to_s
39
39
 
40
40
  # Ruby 1.8 compatibility
@@ -45,11 +45,11 @@ module CityHash
45
45
  len = input_str.size
46
46
  end
47
47
 
48
- if seed.nil?
49
- return CityHash::Internal.city_hash128(input_str, len)
48
+ if seed.empty?
49
+ return CityHash::Internal.city_hash128(input_str, len).to_i
50
50
  end
51
51
 
52
- return CityHash::Internal.city_hash128_with_seed(input_str, len, seed.to_i)
52
+ return CityHash::Internal.city_hash128_with_seed(input_str, len, seed[0].to_i, seed[1].to_i).to_i
53
53
  end
54
54
 
55
55
  end
Binary file
@@ -1,2 +1,2 @@
1
1
  all:
2
- g++ -shared -fPIC city.cc -o ../libcity.so
2
+ g++ -shared -fPIC city.cc city_ruby_bridge.cpp -o ../libcity.so
@@ -0,0 +1,19 @@
1
+ #include "city_ruby_bridge.h"
2
+ #include <sstream>
3
+
4
+ const char* CityHash128String(const char *s, size_t len)
5
+ {
6
+ std::ostringstream str;
7
+ str << Uint128Low64(CityHash128(s, len)) << Uint128High64(CityHash128(s, len));
8
+
9
+ return str.str().c_str();
10
+ }
11
+
12
+ const char* CityHash128WithSeedString(const char *s, size_t len, uint64 seed1, uint64 seed2)
13
+ {
14
+ uint128 seed(seed1, seed2);
15
+ std::ostringstream str;
16
+ str << Uint128Low64(CityHash128WithSeed(s, len, seed)) << Uint128High64(CityHash128WithSeed(s, len, seed));
17
+
18
+ return str.str().c_str();
19
+ }
@@ -0,0 +1,8 @@
1
+ #include "city.h"
2
+
3
+ typedef uint64_t uint64;
4
+ typedef std::pair<uint64, uint64> uint128;
5
+
6
+ extern "C" const char* CityHash128String(const char *s, size_t len);
7
+
8
+ extern "C" const char* CityHash128WithSeedString(const char *s, size_t len, uint64 seed1, uint64 seed2);
@@ -2,8 +2,8 @@ module CityHash
2
2
 
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 2
6
- PATCH = 1
5
+ MINOR = 3
6
+ PATCH = 0
7
7
  BUILD = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -14,4 +14,12 @@ class TestCityhash < Test::Unit::TestCase
14
14
  assert_equal 11136353178704814373, CityHash.hash64("test", 12345, 54321)
15
15
  end
16
16
 
17
+ should "return 128bit hash" do
18
+ assert_equal 130554790001792308794529643941127319555, CityHash.hash128("test")
19
+ end
20
+
21
+ should "return 128bit hash with seed" do
22
+ assert_equal 183946415266487905135364192266033899899, CityHash.hash128("test", [123,123])
23
+ end
24
+
17
25
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cityhash
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - nashby
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-22 00:00:00 +03:00
13
+ date: 2011-04-23 00:00:00 +03:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -101,6 +101,8 @@ files:
101
101
  - lib/cityhash/ext/src/Makefile
102
102
  - lib/cityhash/ext/src/city.cc
103
103
  - lib/cityhash/ext/src/city.h
104
+ - lib/cityhash/ext/src/city_ruby_bridge.cpp
105
+ - lib/cityhash/ext/src/city_ruby_bridge.h
104
106
  - lib/cityhash/version.rb
105
107
  - test/helper.rb
106
108
  - test/test_cityhash.rb
@@ -118,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
120
  requirements:
119
121
  - - ">="
120
122
  - !ruby/object:Gem::Version
121
- hash: -574838995
123
+ hash: -308570463
122
124
  segments:
123
125
  - 0
124
126
  version: "0"