sparsehash 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/etc/anyset.rb +1 -1
- data/ext/sparsehash.cpp +15 -40
- metadata +2 -2
data/etc/anyset.rb
CHANGED
data/ext/sparsehash.cpp
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
#include <map>
|
7
7
|
#include <set>
|
8
8
|
|
9
|
+
#include <cstring>
|
10
|
+
|
9
11
|
#ifdef __GNUC__
|
10
12
|
#include <ext/hash_map>
|
11
13
|
#include <ext/hash_set>
|
@@ -20,25 +22,27 @@ namespace {
|
|
20
22
|
|
21
23
|
struct sparsehash_equal_key {
|
22
24
|
bool operator() (const VALUE &x, const VALUE &y) const {
|
23
|
-
|
25
|
+
if (TYPE(x) == T_STRING && TYPE(y) == T_STRING) {
|
26
|
+
const char *x_ptr = RSTRING_PTR(x);
|
27
|
+
const char *y_ptr = RSTRING_PTR(y);
|
28
|
+
long x_len = RSTRING_LEN(x);
|
29
|
+
long y_len = RSTRING_LEN(y);
|
30
|
+
return (x_len == y_len) && (x_len == 0 || (strncmp(x_ptr, y_ptr, x_len) == 0));
|
31
|
+
} else {
|
32
|
+
return (x == y);
|
33
|
+
}
|
24
34
|
}
|
25
35
|
};
|
26
36
|
|
27
37
|
struct sparsehash_hash {
|
28
38
|
size_t operator() (const VALUE &x) const {
|
29
|
-
|
30
|
-
return NUM2INT(hash);
|
39
|
+
return (TYPE(x) == T_STRING) ? rb_str_hash(x) : x;
|
31
40
|
}
|
32
41
|
};
|
33
42
|
|
34
43
|
struct stl_key_compare {
|
35
44
|
bool operator() (const VALUE &x, const VALUE &y) const {
|
36
|
-
|
37
|
-
VALUE hash_y = rb_funcall(y, rb_intern("hash"), 0);
|
38
|
-
int i_hash_x = NUM2INT(hash_x);
|
39
|
-
int i_hash_y = NUM2INT(hash_y);
|
40
|
-
|
41
|
-
return (i_hash_x < i_hash_y);
|
45
|
+
return (rb_str_hash(x) < rb_str_hash(y));
|
42
46
|
}
|
43
47
|
};
|
44
48
|
|
@@ -82,37 +86,8 @@ void sparsehash_initialize<DHSet>(DHSet *x) {
|
|
82
86
|
|
83
87
|
template <class T>
|
84
88
|
void sparsehash_validate_key(VALUE &x) {
|
85
|
-
|
86
|
-
|
87
|
-
template <>
|
88
|
-
void sparsehash_validate_key<SHMap>(VALUE &x) {
|
89
|
-
if (NIL_P(x)) {
|
90
|
-
rb_raise(rb_eArgError, "Invalid key: nil");
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
template <>
|
95
|
-
void sparsehash_validate_key<SHSet>(VALUE &x) {
|
96
|
-
if (NIL_P(x)) {
|
97
|
-
rb_raise(rb_eArgError, "Invalid key: nil");
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
template <>
|
102
|
-
void sparsehash_validate_key<DHMap>(VALUE &x) {
|
103
|
-
if (!x) {
|
104
|
-
rb_raise(rb_eArgError, "Invalid key: false");
|
105
|
-
} else if(NIL_P(x)) {
|
106
|
-
rb_raise(rb_eArgError, "Invalid key: nil");
|
107
|
-
}
|
108
|
-
}
|
109
|
-
|
110
|
-
template <>
|
111
|
-
void sparsehash_validate_key<DHSet>(VALUE &x) {
|
112
|
-
if (!x) {
|
113
|
-
rb_raise(rb_eArgError, "Invalid key: false");
|
114
|
-
} else if(NIL_P(x)) {
|
115
|
-
rb_raise(rb_eArgError, "Invalid key: nil");
|
89
|
+
if (TYPE(x) != T_STRING) {
|
90
|
+
rb_raise(rb_eArgError, "Invalid key (String only)");
|
116
91
|
}
|
117
92
|
}
|
118
93
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sparsehash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-21 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|