cityhash 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,4 +3,4 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
- - ruby-head
6
+ - 2.0.0
@@ -1,3 +1,8 @@
1
+ ## 0.8.0 (May 5, 2013) ##
2
+
3
+ ### enhancements
4
+ * add crc methods
5
+
1
6
  ## 0.7.0 (October 25, 2012) ##
2
7
 
3
8
  ### enhancements
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ gemspec
4
4
 
5
5
  gem 'rake'
6
6
  gem 'rake-compiler'
7
- gem 'minitest', '~> 2.11.0'
7
+ gem 'minitest', '~> 4.7.3'
data/README.md CHANGED
@@ -21,6 +21,9 @@ CityHash.hash64(text, seed1) # => 9154302171269876511
21
21
  CityHash.hash64(text, seed1, seed2) # => 4854399283587686019
22
22
  CityHash.hash128(text) # => 124124989950401219618153994964897029896
23
23
  CityHash.hash128(text, seed1) # => 101668641288246442316643001405184598611
24
+ CityHash.hash128crc(text) # => 124124989950401219618153994964897029896
25
+ CityHash.hash128crc(text, seed1) # => 101668641288246442316643001405184598611
26
+ CityHash.hash256crc(text) # => 11964743055457135893972873789222488394617411264226841264756
24
27
  ```
25
28
 
26
29
  ### Contributing to cityhash
@@ -0,0 +1,43 @@
1
+ // Copyright (c) 2011 Google, Inc.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ // of this software and associated documentation files (the "Software"), to deal
5
+ // in the Software without restriction, including without limitation the rights
6
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ // copies of the Software, and to permit persons to whom the Software is
8
+ // furnished to do so, subject to the following conditions:
9
+ //
10
+ // The above copyright notice and this permission notice shall be included in
11
+ // all copies or substantial portions of the Software.
12
+ //
13
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ // THE SOFTWARE.
20
+ //
21
+ // CityHash, by Geoff Pike and Jyrki Alakuijala
22
+ //
23
+ // This file declares the subset of the CityHash functions that require
24
+ // _mm_crc32_u64(). See the CityHash README for details.
25
+ //
26
+ // Functions in the CityHash family are not suitable for cryptography.
27
+
28
+ #ifndef CITY_HASH_CRC_H_
29
+ #define CITY_HASH_CRC_H_
30
+
31
+ #include <city.h>
32
+
33
+ // Hash function for a byte array.
34
+ uint128 CityHashCrc128(const char *s, size_t len);
35
+
36
+ // Hash function for a byte array. For convenience, a 128-bit seed is also
37
+ // hashed into the result.
38
+ uint128 CityHashCrc128WithSeed(const char *s, size_t len, uint128 seed);
39
+
40
+ // Hash function for a byte array. Sets result[0] ... result[3].
41
+ void CityHashCrc256(const char *s, size_t len, uint64 *result);
42
+
43
+ #endif // CITY_HASH_CRC_H_
@@ -1,6 +1,10 @@
1
1
  #include <ruby.h>
2
2
  #include "city.h"
3
3
 
4
+ #ifdef __SSE4_2__
5
+ #include "citycrc.h"
6
+ #endif
7
+
4
8
  // Use this typedef to make the compiler happy when
5
9
  // calling rb_define_method()
6
10
  typedef VALUE (ruby_method)(...);
@@ -38,6 +42,28 @@ extern "C" VALUE cityhash_hash128_with_seed(VALUE mod, VALUE input, VALUE seed_s
38
42
  return rb_str_new((char *)&hash, sizeof(hash));
39
43
  }
40
44
 
45
+ #ifdef __SSE4_2__
46
+ extern "C" VALUE cityhash_hashcrc128(VALUE mod, VALUE input)
47
+ {
48
+ uint128 hash = CityHashCrc128(StringValuePtr(input), RSTRING_LEN(input));
49
+ return rb_str_new((char *)&hash, sizeof(hash));
50
+ }
51
+
52
+ extern "C" VALUE cityhash_hashcrc128_with_seed(VALUE mod, VALUE input, VALUE seed_string)
53
+ {
54
+ uint128 seed = *(uint128 *)StringValuePtr(seed_string);
55
+ uint128 hash = CityHashCrc128WithSeed(StringValuePtr(input), RSTRING_LEN(input), seed);
56
+ return rb_str_new((char *)&hash, sizeof(hash));
57
+ }
58
+
59
+ extern "C" VALUE cityhash_hashcrc256(VALUE mod, VALUE input)
60
+ {
61
+ uint64 hash[3] = {};
62
+ CityHashCrc256(StringValuePtr(input), RSTRING_LEN(input), hash);
63
+ return rb_str_new((char *)&hash, sizeof(hash));
64
+ }
65
+ #endif
66
+
41
67
  extern "C" void Init_cityhash()
42
68
  {
43
69
  VALUE mCityHash = rb_define_module("CityHash");
@@ -51,4 +77,11 @@ extern "C" void Init_cityhash()
51
77
 
52
78
  rb_define_singleton_method(mInternal, "hash128", (ruby_method*) &cityhash_hash128, 1);
53
79
  rb_define_singleton_method(mInternal, "hash128_with_seed", (ruby_method*) &cityhash_hash128_with_seed, 2);
80
+
81
+ #ifdef __SSE4_2__
82
+ rb_define_singleton_method(mInternal, "hash128crc", (ruby_method*) &cityhash_hashcrc128, 1);
83
+ rb_define_singleton_method(mInternal, "hash128crc_with_seed", (ruby_method*) &cityhash_hashcrc128_with_seed, 2);
84
+
85
+ rb_define_singleton_method(mInternal, "hash256crc", (ruby_method*) &cityhash_hashcrc256, 1);
86
+ #endif
54
87
  }
@@ -1,6 +1,6 @@
1
1
  require 'mkmf'
2
2
 
3
- %w{g O3 Wall}.each do |flag|
3
+ %w{g O3 Wall msse4.2}.each do |flag|
4
4
  flag = "-#{flag}"
5
5
  $CPPFLAGS += " #{flag}" unless $CPPFLAGS.split.include? flag
6
6
  end
@@ -16,12 +16,38 @@ module CityHash
16
16
  end
17
17
 
18
18
  def self.hash128(input, seed=nil)
19
- if seed
20
- seed = [seed & LOW64_MASK, seed & HIGH64_MASK >> 64].pack('QQ')
21
- digest = Internal.hash128_with_seed(input, seed)
19
+ digest = if seed
20
+ Internal.hash128_with_seed(input, packed_seed(seed))
22
21
  else
23
- digest = Internal.hash128(input)
22
+ Internal.hash128(input)
24
23
  end
24
+
25
+ unpacked_digest(digest)
26
+ end
27
+
28
+ def self.hash128crc(input, seed=nil)
29
+ digest = if seed
30
+ Internal.hash128crc_with_seed(input, packed_seed(seed))
31
+ else
32
+ Internal.hash128crc(input)
33
+ end
34
+
35
+ unpacked_digest(digest)
36
+ end
37
+
38
+ def self.hash256crc(input)
39
+ digest = Internal.hash256crc(input)
40
+
41
+ [0..7, 8..15, 16..23].map { |r| digest[r].unpack('Q').first.to_s }.join.to_i
42
+ end
43
+
44
+ private
45
+
46
+ def self.packed_seed(seed)
47
+ [seed & LOW64_MASK, seed & HIGH64_MASK >> 64].pack('QQ')
48
+ end
49
+
50
+ def self.unpacked_digest(digest)
25
51
  [0..7, 8..15].map { |r| digest[r].unpack('Q').first.to_s }.join.to_i
26
52
  end
27
53
  end
@@ -1,3 +1,3 @@
1
1
  module CityHash
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -25,4 +25,17 @@ describe CityHash do
25
25
  seed = (123 << 64) | 123
26
26
  assert_equal 1834994000056895780313918994795281207519, CityHash.hash128("test", seed)
27
27
  end
28
+
29
+ it "returns 128bit crc hash" do
30
+ assert_equal 124124989950401219618153994964897029896, CityHash.hash128crc("test")
31
+ end
32
+
33
+ it "returns 128bit crc hash with seed" do
34
+ seed = (123 << 64) | 123
35
+ assert_equal 1834994000056895780313918994795281207519, CityHash.hash128crc("test", seed)
36
+ end
37
+
38
+ it "returns 256bit crc hash" do
39
+ assert_equal 11964743055457135893972873789222488394617411264226841264756, CityHash.hash256crc("test")
40
+ end
28
41
  end
metadata CHANGED
@@ -1,24 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cityhash
3
- version: !ruby/object:Gem::Version
4
- version: 0.7.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Vasiliy Ermolovich
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-10-25 00:00:00.000000000 Z
17
+
18
+ date: 2013-05-05 00:00:00 Z
13
19
  dependencies: []
20
+
14
21
  description: ruby bindings for google's cityhash
15
- email:
22
+ email:
16
23
  - younash@gmail.com
17
24
  executables: []
18
- extensions:
25
+
26
+ extensions:
19
27
  - ext/cityhash/extconf.rb
20
28
  extra_rdoc_files: []
21
- files:
29
+
30
+ files:
22
31
  - .gitignore
23
32
  - .travis.yml
24
33
  - CHANGELOG.md
@@ -29,6 +38,7 @@ files:
29
38
  - cityhash.gemspec
30
39
  - ext/cityhash/city.cc
31
40
  - ext/cityhash/city.h
41
+ - ext/cityhash/citycrc.h
32
42
  - ext/cityhash/cityhash.cc
33
43
  - ext/cityhash/extconf.rb
34
44
  - lib/cityhash.rb
@@ -37,34 +47,37 @@ files:
37
47
  - test/test_helper.rb
38
48
  homepage: http://github.com/nashby/cityhash
39
49
  licenses: []
50
+
40
51
  post_install_message:
41
52
  rdoc_options: []
42
- require_paths:
53
+
54
+ require_paths:
43
55
  - lib
44
- required_ruby_version: !ruby/object:Gem::Requirement
56
+ required_ruby_version: !ruby/object:Gem::Requirement
45
57
  none: false
46
- requirements:
47
- - - ! '>='
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- segments:
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
51
63
  - 0
52
- hash: 4171946996269433700
53
- required_rubygems_version: !ruby/object:Gem::Requirement
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
66
  none: false
55
- requirements:
56
- - - ! '>='
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- segments:
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
60
72
  - 0
61
- hash: 4171946996269433700
73
+ version: "0"
62
74
  requirements: []
75
+
63
76
  rubyforge_project: cityhash
64
77
  rubygems_version: 1.8.24
65
78
  signing_key:
66
79
  specification_version: 3
67
80
  summary: ruby bindings for google's cityhash
68
- test_files:
81
+ test_files:
69
82
  - test/cityhash_test.rb
70
83
  - test/test_helper.rb