memcache-client 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/continuum.rb +54 -23
- metadata +16 -7
- data/ext/memcache/binary_search.c +0 -54
- data/ext/memcache/extconf.rb +0 -5
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 1.6.3 (2009-02-14)
|
2
|
+
|
3
|
+
* Remove gem native extension in preference to RubyInline. This allows the gem to install
|
4
|
+
and work on JRuby and Ruby 1.8.5 when the native code fails to compile.
|
5
|
+
|
1
6
|
= 1.6.2 (2009-02-04)
|
2
7
|
|
3
8
|
* Validate that values are less than one megabyte in size.
|
data/lib/continuum.rb
CHANGED
@@ -1,31 +1,62 @@
|
|
1
1
|
module Continuum
|
2
2
|
POINTS_PER_SERVER = 160 # this is the default in libmemcached
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
4
|
+
class << self
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'inline'
|
8
|
+
inline do |builder|
|
9
|
+
builder.c <<-EOM
|
10
|
+
int binary_search(VALUE ary, unsigned int r) {
|
11
|
+
int upper = RARRAY_LEN(ary) - 1;
|
12
|
+
int lower = 0;
|
13
|
+
int idx = 0;
|
14
|
+
ID value = rb_intern("value");
|
15
|
+
|
16
|
+
while (lower <= upper) {
|
17
|
+
idx = (lower + upper) / 2;
|
18
|
+
|
19
|
+
VALUE continuumValue = rb_funcall(RARRAY_PTR(ary)[idx], value, 0);
|
20
|
+
unsigned int l = NUM2UINT(continuumValue);
|
21
|
+
if (l == r) {
|
22
|
+
return idx;
|
23
|
+
}
|
24
|
+
else if (l > r) {
|
25
|
+
upper = idx - 1;
|
26
|
+
}
|
27
|
+
else {
|
28
|
+
lower = idx + 1;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return upper;
|
32
|
+
}
|
33
|
+
EOM
|
34
|
+
end
|
35
|
+
rescue Exception => e
|
36
|
+
puts "Unable to generate native code, falling back to Ruby: #{e.message}"
|
37
|
+
|
38
|
+
# slow but pure ruby version
|
39
|
+
# Find the closest index in Continuum with value <= the given value
|
40
|
+
def binary_search(ary, value, &block)
|
41
|
+
upper = ary.size - 1
|
42
|
+
lower = 0
|
43
|
+
idx = 0
|
44
|
+
|
45
|
+
while(lower <= upper) do
|
46
|
+
idx = (lower + upper) / 2
|
47
|
+
comp = ary[idx].value <=> value
|
48
|
+
|
49
|
+
if comp == 0
|
50
|
+
return idx
|
51
|
+
elsif comp > 0
|
52
|
+
upper = idx - 1
|
53
|
+
else
|
54
|
+
lower = idx + 1
|
55
|
+
end
|
26
56
|
end
|
57
|
+
return upper
|
27
58
|
end
|
28
|
-
|
59
|
+
|
29
60
|
end
|
30
61
|
end
|
31
62
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memcache-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Hodel
|
@@ -11,16 +11,26 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2009-02-
|
14
|
+
date: 2009-02-14 00:00:00 -06:00
|
15
15
|
default_executable:
|
16
|
-
dependencies:
|
17
|
-
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name:
|
19
|
+
- RubyInline
|
20
|
+
type: :runtime
|
21
|
+
version_requirement:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: "0"
|
27
|
+
version:
|
18
28
|
description: A Ruby library for accessing memcached.
|
19
29
|
email: mperham@gmail.com
|
20
30
|
executables: []
|
21
31
|
|
22
|
-
extensions:
|
23
|
-
|
32
|
+
extensions: []
|
33
|
+
|
24
34
|
extra_rdoc_files: []
|
25
35
|
|
26
36
|
files:
|
@@ -31,7 +41,6 @@ files:
|
|
31
41
|
- lib/continuum.rb
|
32
42
|
- lib/memcache.rb
|
33
43
|
- lib/memcache_util.rb
|
34
|
-
- ext/memcache/binary_search.c
|
35
44
|
has_rdoc: false
|
36
45
|
homepage: http://github.com/mperham/memcache-client
|
37
46
|
post_install_message:
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#include "ruby.h"
|
2
|
-
#include "stdio.h"
|
3
|
-
|
4
|
-
/*
|
5
|
-
def binary_search(ary, value)
|
6
|
-
upper = ary.size - 1
|
7
|
-
lower = 0
|
8
|
-
idx = 0
|
9
|
-
|
10
|
-
while(lower <= upper) do
|
11
|
-
idx = (lower + upper) / 2
|
12
|
-
comp = ary[idx].value <=> value
|
13
|
-
|
14
|
-
if comp == 0
|
15
|
-
return idx
|
16
|
-
elsif comp > 0
|
17
|
-
upper = idx - 1
|
18
|
-
else
|
19
|
-
lower = idx + 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
return upper
|
23
|
-
end
|
24
|
-
*/
|
25
|
-
static VALUE binary_search(VALUE self, VALUE ary, VALUE number) {
|
26
|
-
int upper = RARRAY_LEN(ary) - 1;
|
27
|
-
int lower = 0;
|
28
|
-
int idx = 0;
|
29
|
-
unsigned int r = NUM2UINT(number);
|
30
|
-
ID value = rb_intern("value");
|
31
|
-
|
32
|
-
while (lower <= upper) {
|
33
|
-
idx = (lower + upper) / 2;
|
34
|
-
|
35
|
-
VALUE continuumValue = rb_funcall(RARRAY_PTR(ary)[idx], value, 0);
|
36
|
-
unsigned int l = NUM2UINT(continuumValue);
|
37
|
-
if (l == r) {
|
38
|
-
return INT2FIX(idx);
|
39
|
-
}
|
40
|
-
else if (l > r) {
|
41
|
-
upper = idx - 1;
|
42
|
-
}
|
43
|
-
else {
|
44
|
-
lower = idx + 1;
|
45
|
-
}
|
46
|
-
}
|
47
|
-
return INT2FIX(upper);
|
48
|
-
}
|
49
|
-
|
50
|
-
VALUE cContinuum;
|
51
|
-
void Init_binary_search() {
|
52
|
-
cContinuum = rb_define_module("Continuum");
|
53
|
-
rb_define_module_function(cContinuum, "binary_search", binary_search, 2);
|
54
|
-
}
|