cityhash 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -4
- data/ext/cityhash/city.cc +32 -4
- data/ext/cityhash/cityhash.cc +6 -1
- data/ext/cityhash/extconf.rb +3 -2
- data/lib/cityhash.rb +16 -12
- data/lib/cityhash/version.rb +1 -1
- data/test/cityhash_test.rb +14 -0
- metadata +9 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 964373c4e613cd8d4c996f8499e24bb50a919b00
|
4
|
+
data.tar.gz: 743d17ddff4ba29d11209c89af5bfdfc11ba7e8e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ae99d60b87a15463974003da1ff1f625edb70ba39f40627dd2c6326cad9749a9f5366ea6fbdb79540a5c34557e87dcbf8f0d02b351cd91d92b8f23cb41abe4f5
|
7
|
+
data.tar.gz: ea0f0ae415a26d2ea7828c8347bb7d430bd5ed34dd1584ca27a329577f5ed13511e8aab9238cb6953d99664cb2a5919c4c98f1993ed256c2df5ac5462b51727c
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## 0.9.0 (October 11, 2017) ##
|
2
|
+
|
3
|
+
### enhancements
|
4
|
+
* update cityhash lib version
|
5
|
+
* ditch old rubies. support only Ruby 2.0+
|
6
|
+
* let the environment dictate the arch
|
7
|
+
* do not define CRC methods if it's not supported by system
|
8
|
+
|
1
9
|
## 0.8.1 (May 18, 2013) ##
|
2
10
|
|
3
11
|
### bugfixes
|
data/README.md
CHANGED
@@ -6,10 +6,6 @@ Ruby wrapper for google's cityhash.
|
|
6
6
|
|
7
7
|
gem install cityhash
|
8
8
|
|
9
|
-
Since OSX uses `llvm-gcc-4.2` that doesn't support `-march=native` flag you have to compile `cityhash` lib with `clang++` compiler:
|
10
|
-
|
11
|
-
CXX=/usr/bin/clang++ gem install cityhash
|
12
|
-
|
13
9
|
### Usage
|
14
10
|
|
15
11
|
```ruby
|
@@ -30,6 +26,12 @@ CityHash.hash128crc(text, seed1) # => 101668641288246442316643001405184598611
|
|
30
26
|
CityHash.hash256crc(text) # => 11964743055457135893972873789222488394617411264226841264756
|
31
27
|
```
|
32
28
|
|
29
|
+
### Important note
|
30
|
+
|
31
|
+
CityHash does not maintain backward compatibility with previous versions. You should not use CityHash for persitent storage, or else never upgrade it.
|
32
|
+
|
33
|
+
If you need backward compatibility please consider other hash functions like [xxHash](https://github.com/nashby/xxhash) or [MurmurHash](https://github.com/ksss/digest-murmurhash)
|
34
|
+
|
33
35
|
### Contributing to cityhash
|
34
36
|
|
35
37
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
data/ext/cityhash/city.cc
CHANGED
@@ -59,6 +59,33 @@ static uint32 UNALIGNED_LOAD32(const char *p) {
|
|
59
59
|
#define bswap_32(x) OSSwapInt32(x)
|
60
60
|
#define bswap_64(x) OSSwapInt64(x)
|
61
61
|
|
62
|
+
#elif defined(__sun) || defined(sun)
|
63
|
+
|
64
|
+
#include <sys/byteorder.h>
|
65
|
+
#define bswap_32(x) BSWAP_32(x)
|
66
|
+
#define bswap_64(x) BSWAP_64(x)
|
67
|
+
|
68
|
+
#elif defined(__FreeBSD__)
|
69
|
+
|
70
|
+
#include <sys/endian.h>
|
71
|
+
#define bswap_32(x) bswap32(x)
|
72
|
+
#define bswap_64(x) bswap64(x)
|
73
|
+
|
74
|
+
#elif defined(__OpenBSD__)
|
75
|
+
|
76
|
+
#include <sys/types.h>
|
77
|
+
#define bswap_32(x) swap32(x)
|
78
|
+
#define bswap_64(x) swap64(x)
|
79
|
+
|
80
|
+
#elif defined(__NetBSD__)
|
81
|
+
|
82
|
+
#include <sys/types.h>
|
83
|
+
#include <machine/bswap.h>
|
84
|
+
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
|
85
|
+
#define bswap_32(x) bswap32(x)
|
86
|
+
#define bswap_64(x) bswap64(x)
|
87
|
+
#endif
|
88
|
+
|
62
89
|
#else
|
63
90
|
|
64
91
|
#include <byteswap.h>
|
@@ -95,8 +122,8 @@ static const uint64 k1 = 0xb492b66fbe98f273ULL;
|
|
95
122
|
static const uint64 k2 = 0x9ae16a3b2f90404fULL;
|
96
123
|
|
97
124
|
// Magic numbers for 32-bit hashing. Copied from Murmur3.
|
98
|
-
static const
|
99
|
-
static const
|
125
|
+
static const uint32 c1 = 0xcc9e2d51;
|
126
|
+
static const uint32 c2 = 0x1b873593;
|
100
127
|
|
101
128
|
// A 32-bit to 32-bit integer hash copied from Murmur3.
|
102
129
|
static uint32 fmix(uint32 h)
|
@@ -142,8 +169,9 @@ static uint32 Hash32Len13to24(const char *s, size_t len) {
|
|
142
169
|
static uint32 Hash32Len0to4(const char *s, size_t len) {
|
143
170
|
uint32 b = 0;
|
144
171
|
uint32 c = 9;
|
145
|
-
for (
|
146
|
-
|
172
|
+
for (size_t i = 0; i < len; i++) {
|
173
|
+
signed char v = s[i];
|
174
|
+
b = b * c1 + v;
|
147
175
|
c ^= b;
|
148
176
|
}
|
149
177
|
return fmix(Mur(b, Mur(len, c)));
|
data/ext/cityhash/cityhash.cc
CHANGED
@@ -16,27 +16,32 @@ extern "C" VALUE cityhash_hash32(VALUE mod, VALUE input)
|
|
16
16
|
|
17
17
|
extern "C" VALUE cityhash_hash64(VALUE mod, VALUE input)
|
18
18
|
{
|
19
|
+
Check_Type(input, T_STRING);
|
19
20
|
return ULL2NUM(CityHash64(StringValuePtr(input), RSTRING_LEN(input)));
|
20
21
|
}
|
21
22
|
|
22
23
|
extern "C" VALUE cityhash_hash64_with_seed(VALUE mod, VALUE input, VALUE seed)
|
23
24
|
{
|
25
|
+
Check_Type(input, T_STRING);
|
24
26
|
return ULL2NUM(CityHash64WithSeed(StringValuePtr(input), RSTRING_LEN(input), NUM2ULL(seed)));
|
25
27
|
}
|
26
28
|
|
27
29
|
extern "C" VALUE cityhash_hash64_with_seeds(VALUE mod, VALUE input, VALUE seed1, VALUE seed2)
|
28
30
|
{
|
31
|
+
Check_Type(input, T_STRING);
|
29
32
|
return ULL2NUM(CityHash64WithSeeds(StringValuePtr(input), RSTRING_LEN(input), NUM2ULL(seed1), NUM2ULL(seed2)));
|
30
33
|
}
|
31
34
|
|
32
35
|
extern "C" VALUE cityhash_hash128(VALUE mod, VALUE input)
|
33
36
|
{
|
37
|
+
Check_Type(input, T_STRING);
|
34
38
|
uint128 hash = CityHash128(StringValuePtr(input), RSTRING_LEN(input));
|
35
39
|
return rb_str_new((char *)&hash, sizeof(hash));
|
36
40
|
}
|
37
41
|
|
38
42
|
extern "C" VALUE cityhash_hash128_with_seed(VALUE mod, VALUE input, VALUE seed_string)
|
39
43
|
{
|
44
|
+
Check_Type(input, T_STRING);
|
40
45
|
uint128 seed = *(uint128 *)StringValuePtr(seed_string);
|
41
46
|
uint128 hash = CityHash128WithSeed(StringValuePtr(input), RSTRING_LEN(input), seed);
|
42
47
|
return rb_str_new((char *)&hash, sizeof(hash));
|
@@ -58,7 +63,7 @@ extern "C" VALUE cityhash_hashcrc128_with_seed(VALUE mod, VALUE input, VALUE see
|
|
58
63
|
|
59
64
|
extern "C" VALUE cityhash_hashcrc256(VALUE mod, VALUE input)
|
60
65
|
{
|
61
|
-
uint64 hash[
|
66
|
+
uint64 hash[4] = {};
|
62
67
|
CityHashCrc256(StringValuePtr(input), RSTRING_LEN(input), hash);
|
63
68
|
return rb_str_new((char *)&hash, sizeof(hash));
|
64
69
|
}
|
data/ext/cityhash/extconf.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
|
-
|
3
|
+
cxx = ENV['CXX'] || with_config('CXX')
|
4
|
+
RbConfig::MAKEFILE_CONFIG['CXX'] = cxx if cxx
|
4
5
|
|
5
|
-
%w{g O3 Wall
|
6
|
+
%w{g O3 Wall}.each do |flag|
|
6
7
|
flag = "-#{flag}"
|
7
8
|
$CPPFLAGS += " #{flag}" unless $CPPFLAGS.split.include? flag
|
8
9
|
end
|
data/lib/cityhash.rb
CHANGED
@@ -31,23 +31,27 @@ module CityHash
|
|
31
31
|
unpacked_digest(digest)
|
32
32
|
end
|
33
33
|
|
34
|
-
|
35
|
-
input =
|
34
|
+
if Internal.respond_to?(:hash128crc)
|
35
|
+
def self.hash128crc(input, seed=nil)
|
36
|
+
input = input.to_s
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
digest = if seed
|
39
|
+
Internal.hash128crc_with_seed(input, packed_seed(seed))
|
40
|
+
else
|
41
|
+
Internal.hash128crc(input)
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
+
unpacked_digest(digest)
|
45
|
+
end
|
44
46
|
end
|
45
47
|
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
if Internal.respond_to?(:hash256crc)
|
49
|
+
def self.hash256crc(input)
|
50
|
+
input = input.to_s
|
51
|
+
digest = Internal.hash256crc(input)
|
49
52
|
|
50
|
-
|
53
|
+
[0..7, 8..15, 16..23].map { |r| digest[r].unpack('Q').first.to_s }.join.to_i
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
57
|
private
|
data/lib/cityhash/version.rb
CHANGED
data/test/cityhash_test.rb
CHANGED
@@ -27,19 +27,33 @@ describe CityHash do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns 128bit crc hash' do
|
30
|
+
skip unless CityHash.respond_to?(:hash128crc)
|
31
|
+
|
30
32
|
assert_equal 124124989950401219618153994964897029896, CityHash.hash128crc("test")
|
31
33
|
end
|
32
34
|
|
33
35
|
it 'returns 128bit crc hash with seed' do
|
36
|
+
skip unless CityHash.respond_to?(:hash128crc)
|
37
|
+
|
34
38
|
seed = (123 << 64) | 123
|
35
39
|
assert_equal 1834994000056895780313918994795281207519, CityHash.hash128crc("test", seed)
|
36
40
|
end
|
37
41
|
|
38
42
|
it 'returns 256bit crc hash' do
|
43
|
+
skip unless CityHash.respond_to?(:hash256crc)
|
44
|
+
|
39
45
|
assert_equal 11964743055457135893972873789222488394617411264226841264756, CityHash.hash256crc("test")
|
40
46
|
end
|
41
47
|
|
42
48
|
it 'converts input data to string' do
|
43
49
|
assert_equal CityHash.hash128('1337'), CityHash.hash128(1337)
|
44
50
|
end
|
51
|
+
|
52
|
+
it 'does not core when you pass it nil' do
|
53
|
+
assert_raises TypeError do
|
54
|
+
CityHash::Internal.hash64(nil)
|
55
|
+
end
|
56
|
+
|
57
|
+
CityHash.hash64(nil)
|
58
|
+
end
|
45
59
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cityhash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Vasiliy Ermolovich
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: ruby bindings for google's cityhash
|
15
14
|
email:
|
@@ -19,8 +18,8 @@ extensions:
|
|
19
18
|
- ext/cityhash/extconf.rb
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .travis.yml
|
21
|
+
- ".gitignore"
|
22
|
+
- ".travis.yml"
|
24
23
|
- CHANGELOG.md
|
25
24
|
- Gemfile
|
26
25
|
- LICENSE.txt
|
@@ -38,33 +37,26 @@ files:
|
|
38
37
|
- test/test_helper.rb
|
39
38
|
homepage: http://github.com/nashby/cityhash
|
40
39
|
licenses: []
|
40
|
+
metadata: {}
|
41
41
|
post_install_message:
|
42
42
|
rdoc_options: []
|
43
43
|
require_paths:
|
44
44
|
- lib
|
45
45
|
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
-
none: false
|
47
46
|
requirements:
|
48
|
-
- -
|
47
|
+
- - ">="
|
49
48
|
- !ruby/object:Gem::Version
|
50
49
|
version: '0'
|
51
|
-
segments:
|
52
|
-
- 0
|
53
|
-
hash: 3315565900202712629
|
54
50
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
-
none: false
|
56
51
|
requirements:
|
57
|
-
- -
|
52
|
+
- - ">="
|
58
53
|
- !ruby/object:Gem::Version
|
59
54
|
version: '0'
|
60
|
-
segments:
|
61
|
-
- 0
|
62
|
-
hash: 3315565900202712629
|
63
55
|
requirements: []
|
64
56
|
rubyforge_project: cityhash
|
65
|
-
rubygems_version:
|
57
|
+
rubygems_version: 2.5.2.1
|
66
58
|
signing_key:
|
67
|
-
specification_version:
|
59
|
+
specification_version: 4
|
68
60
|
summary: ruby bindings for google's cityhash
|
69
61
|
test_files:
|
70
62
|
- test/cityhash_test.rb
|