tair 0.1.0 → 0.1.1.pre
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.
- checksums.yaml +4 -4
- data/lib/tair/protocol/murmurhash.rb +42 -1
- data/lib/tair/version.rb +2 -2
- data/tair.gemspec +0 -1
- metadata +6 -23
- data/ext/tair/extconf.rb +0 -3
- data/ext/tair/tair_murmurhash.cpp +0 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3439ef24484e932537cc2403abd84819519f4db
|
4
|
+
data.tar.gz: 6aa58d81edc3c133ff3fe67895db30defa11af2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 072924488e5b1d03c90ebe3b3ad64e6927ab5afa4d2c10fb5a9116453a8257d3304292db08c4e5eb7c8ecb8689610c245e84608a9947ad20e019eab7357d439a
|
7
|
+
data.tar.gz: 4a2ed0fd8939f9281ba20083cf95b0fbdc4d1f7df2a846a026c38da47fb0bd886172f81813f7f250de60ed8aeb54159563e741e78b2c6760a2282bf9ed35247c
|
@@ -3,8 +3,49 @@ require 'tair_murmurhash'
|
|
3
3
|
module Tair
|
4
4
|
module Protocol
|
5
5
|
module Murmurhash
|
6
|
+
|
7
|
+
MURMURHASH_M = 0x5bd1e995
|
8
|
+
MAX_OF_32B = (1 << 32) - 1
|
9
|
+
|
6
10
|
def self.digest(key, seed=97)
|
7
|
-
|
11
|
+
key = key.each_codepoint.to_a
|
12
|
+
len = key.size
|
13
|
+
h = seed ^ len
|
14
|
+
index = 0
|
15
|
+
|
16
|
+
while len >= 4
|
17
|
+
k = (key[index] & 0xff) |
|
18
|
+
((key[index + 1] << 8) & 0xff00) |
|
19
|
+
((key[index + 2] << 16) & 0xff0000) |
|
20
|
+
(key[index + 3] << 24)
|
21
|
+
|
22
|
+
|
23
|
+
k = (k * MURMURHASH_M) & MAX_OF_32B
|
24
|
+
k ^= (k >> 24)
|
25
|
+
k = (k * MURMURHASH_M) & MAX_OF_32B
|
26
|
+
h = (h * MURMURHASH_M) & MAX_OF_32B
|
27
|
+
h ^= k
|
28
|
+
index += 4
|
29
|
+
len -= 4
|
30
|
+
end
|
31
|
+
|
32
|
+
if len == 3
|
33
|
+
h ^= (key[index + 2] << 16)
|
34
|
+
end
|
35
|
+
|
36
|
+
if len == 3 or len == 2
|
37
|
+
h ^= (key[index + 1] << 8)
|
38
|
+
end
|
39
|
+
|
40
|
+
if len == 3 or len == 2 or len == 1
|
41
|
+
h ^= key[index]
|
42
|
+
h = (h* MURMURHASH_M) & MAX_OF_32B
|
43
|
+
end
|
44
|
+
|
45
|
+
h ^= (h >> 13)
|
46
|
+
h = (h * MURMURHASH_M) & MAX_OF_32B
|
47
|
+
h ^= (h >> 15)
|
48
|
+
h
|
8
49
|
end
|
9
50
|
end
|
10
51
|
end
|
data/lib/tair/version.rb
CHANGED
data/tair.gemspec
CHANGED
@@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.extensions = spec.files.grep(%r{extconf})
|
24
24
|
|
25
25
|
spec.add_dependency "bindata", "~> 2.1.0"
|
26
|
-
spec.add_dependency "rice", "~> 1.6.2"
|
27
26
|
spec.add_dependency "colored", "~> 1.2.0"
|
28
27
|
|
29
28
|
spec.add_development_dependency "bundler", "~> 1.7"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tair
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "如彼"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 2.1.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rice
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.6.2
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.6.2
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: colored
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,8 +112,7 @@ description: Tair client for ruby.
|
|
126
112
|
email:
|
127
113
|
- hua.qiuh@alibaba-inc.com
|
128
114
|
executables: []
|
129
|
-
extensions:
|
130
|
-
- ext/tair/extconf.rb
|
115
|
+
extensions: []
|
131
116
|
extra_rdoc_files: []
|
132
117
|
files:
|
133
118
|
- ".gitignore"
|
@@ -135,8 +120,6 @@ files:
|
|
135
120
|
- Gemfile
|
136
121
|
- LICENSE.txt
|
137
122
|
- Rakefile
|
138
|
-
- ext/tair/extconf.rb
|
139
|
-
- ext/tair/tair_murmurhash.cpp
|
140
123
|
- lib/tair.rb
|
141
124
|
- lib/tair/client.rb
|
142
125
|
- lib/tair/cluster.rb
|
@@ -177,12 +160,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
160
|
version: '0'
|
178
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
162
|
requirements:
|
180
|
-
- - "
|
163
|
+
- - ">"
|
181
164
|
- !ruby/object:Gem::Version
|
182
|
-
version:
|
165
|
+
version: 1.3.1
|
183
166
|
requirements: []
|
184
167
|
rubyforge_project:
|
185
|
-
rubygems_version: 2.4.
|
168
|
+
rubygems_version: 2.4.5
|
186
169
|
signing_key:
|
187
170
|
specification_version: 4
|
188
171
|
summary: tair client for ruby.
|
data/ext/tair/extconf.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#include "rice/Module.hpp"
|
2
|
-
#include "rice/Class.hpp"
|
3
|
-
#include "rice/String.hpp"
|
4
|
-
|
5
|
-
using namespace Rice;
|
6
|
-
using namespace std;
|
7
|
-
|
8
|
-
#define MURMURHASH_M 0x5bd1e995
|
9
|
-
|
10
|
-
uint64_t digest(string str, uint32_t seed)
|
11
|
-
{
|
12
|
-
const char *key = str.c_str();
|
13
|
-
int len = str.length();
|
14
|
-
uint32_t h = seed ^ len;
|
15
|
-
int index = 0;
|
16
|
-
|
17
|
-
while (len >= 4) {
|
18
|
-
uint32_t k = (key[index] & 0xff) | ((key[index + 1] << 8) & 0xff00)
|
19
|
-
| ((key[index + 2] << 16) & 0xff0000)
|
20
|
-
| (key[index + 3] << 24);
|
21
|
-
|
22
|
-
k *= MURMURHASH_M;
|
23
|
-
k ^= (k >> 24);
|
24
|
-
k *= MURMURHASH_M;
|
25
|
-
h *= MURMURHASH_M;
|
26
|
-
h ^= k;
|
27
|
-
index += 4;
|
28
|
-
len -= 4;
|
29
|
-
}
|
30
|
-
|
31
|
-
switch (len) {
|
32
|
-
case 3:
|
33
|
-
h ^= (key[index + 2] << 16);
|
34
|
-
|
35
|
-
case 2:
|
36
|
-
h ^= (key[index + 1] << 8);
|
37
|
-
|
38
|
-
case 1:
|
39
|
-
h ^= key[index];
|
40
|
-
h *= MURMURHASH_M;
|
41
|
-
}
|
42
|
-
|
43
|
-
h ^= (h >> 13);
|
44
|
-
h *= MURMURHASH_M;
|
45
|
-
h ^= (h >> 15);
|
46
|
-
return h;
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
Object tmh_initialize(Object self, String str, uint32_t seed)
|
51
|
-
{
|
52
|
-
self.iv_set("@string", str);
|
53
|
-
self.iv_set("@seed", seed);
|
54
|
-
}
|
55
|
-
|
56
|
-
Object tmh_digest(Object self)
|
57
|
-
{
|
58
|
-
string str = self.iv_get("@string").to_s().str();
|
59
|
-
uint32_t seed = from_ruby<uint32_t>(self.iv_get("@seed"));
|
60
|
-
uint32_t hash = digest(str, seed);
|
61
|
-
return to_ruby<uint32_t>(hash);
|
62
|
-
}
|
63
|
-
|
64
|
-
extern "C"
|
65
|
-
void Init_tair_murmurhash()
|
66
|
-
{
|
67
|
-
Module rb_mTair = define_module("Tair");
|
68
|
-
Class rb_cTairMurmurhash =
|
69
|
-
define_class_under(rb_mTair, "TairMurmurhash")
|
70
|
-
.define_method( "initialize", &tmh_initialize )
|
71
|
-
.define_method( "digest", &tmh_digest );
|
72
|
-
}
|