rb_lovely 0.3.7 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rb_lovely/ruby_util.hpp +6 -0
- data/ext/rb_lovely/sorted_hash.cpp +22 -12
- data/ext/rb_lovely/sorted_set.cpp +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4258b3c5efab8a5b29067b61e51c0c9660de33
|
4
|
+
data.tar.gz: 1065affd37a40bde5b1b188c64fd0b69a6aadd99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5fdd5429e26c7beeb8d37be5e614f2b553a6d21bcd7784f39e538be882c00748c90d47da312412b538ec43095d3f92e4b67da70ff54d20d16449141d080a4c8
|
7
|
+
data.tar.gz: 80d8f021ca4f675b336838893f9f5b5dcd2d29d74c536d83edc59908071a838399115f30c808f8784eae18220a55f5892be22d8371588c7cc22573df665753f1
|
data/ext/rb_lovely/ruby_util.hpp
CHANGED
@@ -29,6 +29,12 @@ VALUE rubyAlloc(VALUE klass) {
|
|
29
29
|
return Data_Wrap_Struct(klass, 0, rubyDelete<T>, new T);
|
30
30
|
}
|
31
31
|
|
32
|
+
typedef void (*MarkFunction)(void *);
|
33
|
+
template <class T, MarkFunction M>
|
34
|
+
VALUE rubyAlloc(VALUE klass) {
|
35
|
+
return Data_Wrap_Struct(klass, M, rubyDelete<T>, new T);
|
36
|
+
}
|
37
|
+
|
32
38
|
static void initRubyUtil() {
|
33
39
|
rbMod = rb_define_module("RbLovely");
|
34
40
|
cmpMethSym = rb_intern("<=>");
|
@@ -18,11 +18,6 @@ struct member {
|
|
18
18
|
return NUM2INT(cmpResult) < 0;
|
19
19
|
}
|
20
20
|
|
21
|
-
bool operator==(member const& rhs) const {
|
22
|
-
auto equalityVal = rb_funcall(key, hashEqualitySym, 1, rhs.key);
|
23
|
-
return RTEST(equalityVal);
|
24
|
-
}
|
25
|
-
|
26
21
|
// also cache as two element array?
|
27
22
|
member(VALUE _compareProc, VALUE _key, VALUE _val)
|
28
23
|
: compareProc(_compareProc), key(_key), val(_val) {}
|
@@ -32,11 +27,18 @@ struct member {
|
|
32
27
|
VALUE val;
|
33
28
|
};
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
30
|
+
struct CompareVALUEs {
|
31
|
+
bool operator()(VALUE const& lhs, VALUE const& rhs) const {
|
32
|
+
auto equalityVal = rb_funcall(lhs, hashEqualitySym, 1, rhs);
|
33
|
+
return RTEST(equalityVal);
|
34
|
+
}
|
35
|
+
};
|
36
|
+
|
37
|
+
struct HashVALUE {
|
38
|
+
std::size_t operator()(VALUE const& value) const {
|
39
|
+
return NUM2LL(rb_funcall(value, hashSym, 0));
|
40
|
+
}
|
41
|
+
};
|
40
42
|
|
41
43
|
namespace mi = boost::multi_index;
|
42
44
|
|
@@ -44,7 +46,7 @@ struct Hash {
|
|
44
46
|
boost::multi_index_container<
|
45
47
|
member,
|
46
48
|
mi::indexed_by<
|
47
|
-
mi::hashed_unique< mi::member<member, VALUE, &member::key
|
49
|
+
mi::hashed_unique< mi::member<member, VALUE, &member::key>, HashVALUE, CompareVALUEs>,
|
48
50
|
mi::ordered_non_unique< mi::identity<member> >
|
49
51
|
>
|
50
52
|
> container;
|
@@ -224,6 +226,14 @@ VALUE hashHas(VALUE self, VALUE key) {
|
|
224
226
|
return it == hash->container.end() ? Qfalse : Qtrue;
|
225
227
|
}
|
226
228
|
|
229
|
+
void markHash(void *voidSet) {
|
230
|
+
Hash *hash = static_cast<Hash *>(voidSet);
|
231
|
+
for (auto const& entry : hash->container) {
|
232
|
+
rb_gc_mark(entry.key);
|
233
|
+
rb_gc_mark(entry.val);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
227
237
|
} }
|
228
238
|
|
229
239
|
extern "C" {
|
@@ -232,7 +242,7 @@ extern "C" {
|
|
232
242
|
|
233
243
|
void Init_rb_lovely_hybrid_set() {
|
234
244
|
auto rbHash = rb_define_class_under(rbMod, "SortedHash", rb_cObject);
|
235
|
-
rb_define_alloc_func(rbHash, rubyAlloc<Hash>);
|
245
|
+
rb_define_alloc_func(rbHash, rubyAlloc<Hash, markHash>);
|
236
246
|
rb_include_module(rbHash, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
237
247
|
|
238
248
|
rb_define_method(rbHash, "initialize", RUBY_METHOD_FUNC(hashInitialize), -1);
|
@@ -194,6 +194,12 @@ VALUE setHas(VALUE self, VALUE val) {
|
|
194
194
|
return it == set->end() ? Qfalse : Qtrue;
|
195
195
|
}
|
196
196
|
|
197
|
+
void markSet(void *voidSet) {
|
198
|
+
Set *set = static_cast<Set *>(voidSet);
|
199
|
+
for (auto& value : *set)
|
200
|
+
rb_gc_mark(value);
|
201
|
+
}
|
202
|
+
|
197
203
|
} } // end namespace
|
198
204
|
|
199
205
|
extern "C" {
|
@@ -202,7 +208,7 @@ extern "C" {
|
|
202
208
|
|
203
209
|
void Init_rb_lovely_sorted_set() {
|
204
210
|
auto rbSet = rb_define_class_under(rbMod, "SortedSet", rb_cObject);
|
205
|
-
rb_define_alloc_func(rbSet, rubyAlloc<Set>);
|
211
|
+
rb_define_alloc_func(rbSet, rubyAlloc<Set, &markSet>);
|
206
212
|
rb_include_module(rbSet, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
207
213
|
|
208
214
|
rb_define_method(rbSet, "initialize", RUBY_METHOD_FUNC(setInitialize), -1);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_lovely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A fast sorted set built using std::set and a fast sorted hash built using
|
14
14
|
boost::multi_index_container.
|