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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bfc1e9d10476bf6684d49b924c2df97da27a6dc4
4
- data.tar.gz: e1b73faf1ccb468e1b5df4c95dcbb30858438aa0
3
+ metadata.gz: fc4258b3c5efab8a5b29067b61e51c0c9660de33
4
+ data.tar.gz: 1065affd37a40bde5b1b188c64fd0b69a6aadd99
5
5
  SHA512:
6
- metadata.gz: 157d98da65f5be762d8a57d40fe58a977d219a971751e910efe0515559b7ffe57f4b0f8df48e1b5bbc8bb403a1d15ad573df2cc4e354ad63aaa8ebddcd11fc8a
7
- data.tar.gz: e8979751ca9a9e274e949e985a1b1faf1861adc6b3bfe321ae21a3ba88e18f924f878b9cd0ae77a0893bce6b612e07981d0973eb51b48ade1ad692875d7cb6cf
6
+ metadata.gz: f5fdd5429e26c7beeb8d37be5e614f2b553a6d21bcd7784f39e538be882c00748c90d47da312412b538ec43095d3f92e4b67da70ff54d20d16449141d080a4c8
7
+ data.tar.gz: 80d8f021ca4f675b336838893f9f5b5dcd2d29d74c536d83edc59908071a838399115f30c808f8784eae18220a55f5892be22d8371588c7cc22573df665753f1
@@ -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
- std::size_t hash_value(member const& member) {
36
- // TODO: something better?
37
- return reinterpret_cast<std::size_t>(&member);
38
- // return NUM2INT(rb_funcall(member.val, hashSym, 0));
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.3.7
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-01 00:00:00.000000000 Z
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.