YkESet 0.99.0

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/CODE_OF_CONDUCT.md +74 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE +21 -0
  5. data/README.md +68 -0
  6. data/Rakefile +13 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/docs/Yk/EMMap/Iterator.html +626 -0
  10. data/docs/Yk/EMMap.html +1504 -0
  11. data/docs/Yk/EMSet/Iterator.html +626 -0
  12. data/docs/Yk/EMSet.html +1472 -0
  13. data/docs/Yk/EMap/Iterator.html +626 -0
  14. data/docs/Yk/EMap.html +1730 -0
  15. data/docs/Yk/ESet/Iterator.html +626 -0
  16. data/docs/Yk/ESet.html +1472 -0
  17. data/docs/Yk.html +126 -0
  18. data/docs/_index.html +170 -0
  19. data/docs/class_list.html +51 -0
  20. data/docs/css/common.css +1 -0
  21. data/docs/css/full_list.css +58 -0
  22. data/docs/css/style.css +496 -0
  23. data/docs/file_list.html +51 -0
  24. data/docs/frames.html +17 -0
  25. data/docs/index.html +170 -0
  26. data/docs/js/app.js +314 -0
  27. data/docs/js/full_list.js +216 -0
  28. data/docs/js/jquery.js +4 -0
  29. data/docs/method_list.html +571 -0
  30. data/docs/top-level-namespace.html +110 -0
  31. data/eset.gemspec +29 -0
  32. data/ext/Yk/.ruby-version +1 -0
  33. data/ext/Yk/.yardoc/checksums +1 -0
  34. data/ext/Yk/.yardoc/complete +0 -0
  35. data/ext/Yk/.yardoc/object_types +0 -0
  36. data/ext/Yk/.yardoc/objects/root.dat +0 -0
  37. data/ext/Yk/.yardoc/proxy_types +0 -0
  38. data/ext/Yk/Makefile +267 -0
  39. data/ext/Yk/depend +2 -0
  40. data/ext/Yk/extconf.rb +7 -0
  41. data/ext/Yk/for_yard.rb +192 -0
  42. data/ext/Yk/for_yard_product.rb +397 -0
  43. data/ext/Yk/map_tz +78 -0
  44. data/ext/Yk/set_tz +77 -0
  45. data/ext/Yk/stl_map_tz.h +1026 -0
  46. data/ext/Yk/stl_multimap_tz.h +927 -0
  47. data/ext/Yk/stl_multiset_tz.h +805 -0
  48. data/ext/Yk/stl_set_tz.h +815 -0
  49. data/ext/Yk/stl_set_tz_ruby.cpp +575 -0
  50. data/ext/Yk/stl_tree_tz.h +1865 -0
  51. data/ext/Yk/test_set.rb +115 -0
  52. data/ext/Yk/tree_tz.cc +489 -0
  53. data/ext/Yk/tz_stl_auto.cpp +84 -0
  54. data/lib/eset/version.rb +3 -0
  55. data/lib/eset.rb +7 -0
  56. metadata +101 -0
@@ -0,0 +1,575 @@
1
+ /*
2
+ * Copyright (c) 2020
3
+ *
4
+ * Yougaein@github (Kokeji Yougain)
5
+ */
6
+
7
+ #include "set_tz"
8
+ #include "map_tz"
9
+ #include <algorithm>
10
+ #include <ruby.h>
11
+ #include <new>
12
+
13
+
14
+ using namespace std;
15
+ using namespace tz;
16
+
17
+
18
+ static ID ID_CALL;
19
+ static ID ID_LESS;
20
+ static ID ID_EQ;
21
+ static VALUE rb_mYk;
22
+
23
+ #include <iostream>
24
+
25
+ struct ValueCompareBy{
26
+ VALUE block;
27
+ ValueCompareBy(VALUE b) : block(b){ }
28
+ bool operator()(VALUE a, VALUE b){
29
+ if(block != Qnil){
30
+ VALUE ac = rb_funcall(block, ID_CALL, 1, a);
31
+ VALUE bc = rb_funcall(block, ID_CALL, 1, b);
32
+ VALUE res = rb_funcall(ac, ID_LESS, 1, bc);
33
+ return res != Qfalse && res != Qnil;
34
+ }else{
35
+ return a < b;
36
+ }
37
+ }
38
+ };
39
+
40
+
41
+ typedef multiset<VALUE, ValueCompareBy> EMTSet;
42
+ typedef set<VALUE, ValueCompareBy> ESet;
43
+ typedef multimap<VALUE, VALUE, ValueCompareBy> EMTMap;
44
+ typedef map<VALUE, VALUE, ValueCompareBy> EMap;
45
+
46
+
47
+ template <typename EMSet>
48
+ struct ESetWrap{
49
+ typedef EMSet Target;
50
+ static VALUE cESet;
51
+ static VALUE cESetIt;
52
+
53
+ typedef typename EMSet::iterator iterator;
54
+
55
+ inline static iterator getIterator(pair<iterator, bool> r){
56
+ return r.first;
57
+ }
58
+
59
+
60
+ inline static iterator getIterator(iterator r){
61
+ return r;
62
+ }
63
+
64
+
65
+ static void eMSet_free(EMSet* p){
66
+ p->~EMSet();
67
+ ruby_xfree(p);
68
+ }
69
+
70
+
71
+ static void eMSet_rb_gc_mark(std::pair<VALUE, VALUE> arg){
72
+ rb_gc_mark(arg.first);
73
+ rb_gc_mark(arg.second);
74
+ }
75
+
76
+ static void eMSet_rb_gc_mark(VALUE arg){
77
+ rb_gc_mark(arg);
78
+ }
79
+
80
+ static void eMSet_mark(EMSet* p){
81
+ for(iterator it = p->begin() ; it != p->end() ; ++it)
82
+ eMSet_rb_gc_mark(*it);
83
+ rb_gc_mark(p->_M_t._M_impl._M_key_compare.block);
84
+ }
85
+
86
+ static void eMSetIt_free(iterator* p){
87
+ p->iterator::~iterator();
88
+ ruby_xfree(p);
89
+ }
90
+
91
+
92
+ static void eMSetIt_mark(iterator* p){
93
+ if((*p)._M_node){
94
+ EMSet* q = ((EMSet*)p->_M_node->_TZ_tree);
95
+ if(q && q->end() != *p){
96
+ eMSet_rb_gc_mark(**p);
97
+ }
98
+ VALUE m = q->_M_t.memo;
99
+ if(m){
100
+ rb_gc_mark(m); //why?
101
+ }
102
+ }
103
+ }
104
+
105
+ // EMSet.new do |a, b|
106
+ // a < b
107
+ // end
108
+
109
+ static EMSet* eMSet(VALUE self){
110
+ EMSet* p;
111
+ Data_Get_Struct(self, EMSet, p);
112
+ return p;
113
+ }
114
+
115
+
116
+ static iterator* eMSetIt(VALUE self){
117
+ iterator* p;
118
+ Data_Get_Struct(self, iterator, p);
119
+ return p;
120
+ }
121
+
122
+
123
+ static VALUE eMSet_alloc(VALUE klass){
124
+ void* p = ruby_xmalloc(sizeof(EMSet));
125
+ new(p) EMSet(ValueCompareBy(Qnil));
126
+ return Data_Wrap_Struct(klass, eMSet_mark, eMSet_free, p);
127
+ }
128
+
129
+
130
+ static VALUE eMSetIt_alloc(VALUE klass){
131
+ void* p = ruby_xmalloc(sizeof(iterator));
132
+ new(p) iterator();
133
+ return Data_Wrap_Struct(klass, eMSetIt_mark, eMSetIt_free, p);
134
+ }
135
+
136
+
137
+ static VALUE eMSet_init(int argc, VALUE *argv, VALUE self) {
138
+ EMSet* p = eMSet(self);
139
+ VALUE block;
140
+ rb_scan_args(argc, argv, "0&", &block);
141
+ p->~EMSet();
142
+ new(p) EMSet(ValueCompareBy(block));
143
+ p->_M_t.memo = self;
144
+ return Qnil;
145
+ }
146
+
147
+
148
+ static VALUE eMSetIt_init(VALUE self) {
149
+ iterator* p = eMSetIt(self);
150
+ p->~iterator();
151
+ new(p) iterator();
152
+ return Qnil;
153
+ }
154
+
155
+
156
+ static VALUE eMSetIt_eq(VALUE self, VALUE arg) {
157
+ iterator* a = eMSetIt(self);
158
+ if(!rb_obj_is_instance_of(arg, cESetIt)){
159
+ rb_raise(rb_eArgError, "Right operand is not compatible type");
160
+ return Qnil;
161
+ }
162
+ iterator* b = eMSetIt(arg);
163
+ return *a == *b ? Qtrue : Qfalse;
164
+ }
165
+
166
+
167
+ static VALUE eMSetIt_neq(VALUE self, VALUE arg) {
168
+ iterator* a = eMSetIt(self);
169
+ if(!rb_obj_is_instance_of(arg, cESetIt)){
170
+ rb_raise(rb_eArgError, "Right operand is not compatible type");
171
+ return Qnil;
172
+ }
173
+ iterator* b = eMSetIt(arg);
174
+ return *a != *b ? Qtrue : Qfalse;
175
+ }
176
+
177
+
178
+ static VALUE eMSet_upper_bound(VALUE self, VALUE arg) {
179
+ EMSet* p = eMSet(self);
180
+ VALUE itv = eMSetIt_alloc(cESetIt);
181
+ iterator* it = eMSetIt(itv);
182
+ new(it) iterator();
183
+ *it = p->upper_bound(arg);
184
+ return itv;
185
+ }
186
+
187
+
188
+ static VALUE eMSet_lower_bound(VALUE self, VALUE arg) {
189
+ EMSet* p = eMSet(self);
190
+ VALUE itv = eMSetIt_alloc(cESetIt);
191
+ iterator* it = eMSetIt(itv);
192
+ new(it) iterator();
193
+ *it = p->lower_bound(arg);
194
+ return itv;
195
+ }
196
+
197
+
198
+ static VALUE eMSet_begin(VALUE self) {
199
+ EMSet* p = eMSet(self);
200
+ VALUE itv = eMSetIt_alloc(cESetIt);
201
+ iterator* it = eMSetIt(itv);
202
+ new(it) iterator();
203
+ *it = p->begin();
204
+ return itv;
205
+ }
206
+
207
+
208
+ static VALUE eMSet_size(VALUE self) {
209
+ EMSet* p = eMSet(self);
210
+ return INT2FIX(p->size());
211
+ }
212
+
213
+
214
+ static VALUE eMSet_end(VALUE self) {
215
+ EMSet* p = eMSet(self);
216
+ VALUE itv = eMSetIt_alloc(cESetIt);
217
+ iterator* it = eMSetIt(itv);
218
+ new(it) iterator();
219
+ *it = p->end();
220
+ return itv;
221
+ }
222
+
223
+ inline static VALUE toValue(iterator dummy, VALUE itv){
224
+ return itv;
225
+ }
226
+
227
+
228
+ inline static VALUE toValue(pair<iterator, bool> r, VALUE itv){
229
+ VALUE elts[2] = {itv, r.second ? Qtrue : Qfalse};
230
+ return rb_ary_new_from_values(2, (const VALUE*)&elts);
231
+ }
232
+
233
+ inline static VALUE toValue(pair<VALUE, VALUE> r){
234
+ VALUE elts[2] = {r.first, r.second};
235
+ return rb_ary_new_from_values(2, (const VALUE*)&elts);
236
+ }
237
+
238
+ inline static VALUE toValue(VALUE r){
239
+ return r;
240
+ }
241
+
242
+
243
+ inline static VALUE getFirst(pair<VALUE, VALUE> r){
244
+ return r.first;
245
+ }
246
+
247
+ inline static VALUE getFirst(VALUE r){
248
+ return r;
249
+ }
250
+
251
+
252
+ template <class T>
253
+ inline static VALUE insertRet(T r){
254
+ VALUE itv = eMSetIt_alloc(cESetIt);
255
+ iterator* it = eMSetIt(itv);
256
+ new(it) iterator(getIterator(r));
257
+ return toValue(r, itv);
258
+ }
259
+
260
+
261
+ static VALUE eMSetIt_inc(VALUE self) {
262
+ iterator* it = eMSetIt(self);
263
+ if(*it == ((EMSet*)it->_M_node->_TZ_tree)->end()){
264
+ rb_raise(rb_eRangeError, "advancing over the end");
265
+ return Qnil;
266
+ }
267
+ ++*it;
268
+ return self;
269
+ }
270
+
271
+
272
+ static VALUE eMSetIt_dec(VALUE self) {
273
+ iterator* it = eMSetIt(self);
274
+ if(*it == ((EMSet*)it->_M_node->_TZ_tree)->begin()){
275
+ rb_raise(rb_eRangeError, "rewinding over the begining");
276
+ return Qnil;
277
+ }
278
+ --*it;
279
+ return self;
280
+ }
281
+
282
+
283
+ static VALUE eMSet_find(int argc, VALUE *argv, VALUE self){
284
+ VALUE b, e, v;
285
+
286
+ rb_scan_args(argc, argv, "21", &b, &e, &v);
287
+ if(!rb_obj_is_instance_of(b, cESetIt)){
288
+ rb_raise(rb_eArgError, "First argument is not compatible type");
289
+ return Qnil;
290
+ }
291
+ if(!rb_obj_is_instance_of(e, cESetIt)){
292
+ rb_raise(rb_eArgError, "Second argument is not compatible type");
293
+ return Qnil;
294
+ }
295
+ iterator* bg = eMSetIt(b), * ed = eMSetIt(e);
296
+ if((EMSet*)bg->_M_node->_TZ_tree != (EMSet*)ed->_M_node->_TZ_tree){
297
+ rb_raise(rb_eArgError, "First and last iterators are not from the same container");
298
+ return Qnil;
299
+ }
300
+ if(v != Qnil){
301
+ if(!rb_block_given_p()){
302
+ for(iterator it = *bg ; it != *ed ; ++it){
303
+ if(it == ((EMSet*)bg->_M_node->_TZ_tree)->end()){
304
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
305
+ return Qnil;
306
+ }
307
+ VALUE res = rb_funcall(getFirst(*it), ID_EQ, 1, v);
308
+ if(res != Qnil && res != Qfalse)
309
+ return toValue(*it);
310
+ }
311
+ }else{
312
+ for(iterator it = *bg ; it != *ed ; ++it){
313
+ if(it == ((EMSet*)bg->_M_node->_TZ_tree)->end()){
314
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
315
+ return Qnil;
316
+ }
317
+ VALUE res = rb_funcall(getFirst(*it), ID_EQ, 1, v);
318
+ if(res != Qnil && res != Qfalse){
319
+ res = rb_yield(getFirst(*it));
320
+ if(res != Qnil && res != Qfalse)
321
+ return toValue(*it);
322
+ }
323
+ }
324
+ }
325
+ }else if(rb_block_given_p()){
326
+ for(iterator it = *bg ; it != *ed ; ++it){
327
+ if(it == ((EMSet*)bg->_M_node->_TZ_tree)->end()){
328
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
329
+ return Qnil;
330
+ }
331
+ VALUE res = rb_yield(getFirst(*it));
332
+ if(res != Qnil && res != Qfalse)
333
+ return toValue(*it);
334
+ }
335
+ }else{
336
+ rb_raise(rb_eArgError, "Both argument and block are missing");
337
+ return Qnil;
338
+ }
339
+ return e;
340
+ }
341
+
342
+
343
+ static VALUE eMSet_for_each(VALUE self, VALUE b, VALUE e) {
344
+ VALUE tov;
345
+ if(!rb_block_given_p()){
346
+ rb_raise(rb_eArgError, "Block missing");
347
+ return Qnil;
348
+ }
349
+ if(!rb_obj_is_instance_of(b, cESetIt)){
350
+ rb_raise(rb_eArgError, "First argument is not compatible type");
351
+ return Qnil;
352
+ }
353
+ if(!rb_obj_is_instance_of(e, cESetIt)){
354
+ rb_raise(rb_eArgError, "Second argument is not compatible type");
355
+ return Qnil;
356
+ }
357
+ iterator* bg = eMSetIt(b), * ed = eMSetIt(e);
358
+ if((EMSet*)bg->_M_node->_TZ_tree != (EMSet*)ed->_M_node->_TZ_tree){
359
+ rb_raise(rb_eArgError, "First and second iterators are not from the same container");
360
+ return Qnil;
361
+ }
362
+ VALUE res = Qnil;
363
+ for(iterator it = *bg ; it != *ed ; ++it){
364
+ if(it == ((EMSet*)bg->_M_node->_TZ_tree)->end()){
365
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
366
+ return Qnil;
367
+ }
368
+ tov = toValue(*it);
369
+ res = rb_yield(toValue(*it));
370
+ }
371
+ return res;
372
+ }
373
+
374
+
375
+ static VALUE eMSet_erase(VALUE self, VALUE b, VALUE e) {
376
+ EMSet* p = eMSet(self);
377
+ if(!rb_obj_is_instance_of(b, cESetIt)){
378
+ rb_raise(rb_eArgError, "First argument is not compatible type");
379
+ return Qnil;
380
+ }
381
+ if(!rb_obj_is_instance_of(e, cESetIt)){
382
+ rb_raise(rb_eArgError, "Second argument is not compatible type");
383
+ return Qnil;
384
+ }
385
+ iterator* bg = eMSetIt(b), * ed = eMSetIt(e);
386
+ if((EMSet*)bg->_M_node->_TZ_tree != p || (EMSet*)ed->_M_node->_TZ_tree != p){
387
+ rb_raise(rb_eArgError, "First and/or second iterators are not from the method reciever's container");
388
+ return Qnil;
389
+ }
390
+ for(iterator it = *bg ; it != *ed ; ++it){
391
+ if(it == ((EMSet*)bg->_M_node->_TZ_tree)->end()){
392
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
393
+ return Qnil;
394
+ }
395
+ p->erase(it);
396
+ }
397
+ return Qnil;
398
+ }
399
+
400
+ static VALUE eMSet_clear(VALUE self) {
401
+ EMSet* p = eMSet(self);
402
+ p->clear();
403
+ return Qnil;
404
+ }
405
+
406
+ static void Init_eset(const char* cName){
407
+
408
+ cESet = rb_define_class_under(rb_mYk, cName, rb_cObject);
409
+ cESetIt = rb_define_class_under(cESet, "Iterator", rb_cObject);
410
+
411
+ rb_define_alloc_func(cESet, ESetWrap<EMSet>::eMSet_alloc);
412
+ rb_define_alloc_func(cESetIt, ESetWrap<EMSet>::eMSetIt_alloc);
413
+ rb_define_method(cESet, "initialize", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_init), -1);
414
+ rb_define_method(cESet, "size", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_size), 0);
415
+ rb_define_method(cESet, "clear", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_clear), 0);
416
+
417
+ rb_define_method(cESet, "begin", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_begin), 0);
418
+ rb_define_method(cESet, "end", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_end), 0);
419
+ rb_define_method(cESet, "upper_bound", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_upper_bound), 1);
420
+ rb_define_method(cESet, "lower_bound", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_lower_bound), 1);
421
+
422
+ rb_define_method(cESetIt, "inc", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSetIt_inc), 0);
423
+ rb_define_method(cESetIt, "dec", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSetIt_dec), 0);
424
+ rb_define_method(cESetIt, "==", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSetIt_eq), 1);
425
+ rb_define_method(cESetIt, "!=", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSetIt_neq), 1);
426
+
427
+ rb_define_singleton_method(cESet, "find", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_find), -1);
428
+ rb_define_method(cESet, "erase", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_erase), 2);
429
+ rb_define_singleton_method(cESet, "for_each", RUBY_METHOD_FUNC(ESetWrap<EMSet>::eMSet_for_each), 2);
430
+ }
431
+
432
+ };
433
+
434
+
435
+ template <typename EMSet>
436
+ VALUE ESetWrap<EMSet>::cESet = Qnil;
437
+ template <typename EMSet>
438
+ VALUE ESetWrap<EMSet>::cESetIt = Qnil;
439
+
440
+ template <typename E>
441
+ struct ESetWrapMap_ : ESetWrap<E>{
442
+ static VALUE eMSet_insert(int argc, VALUE *argv, VALUE self){
443
+ E* p = ESetWrap<E>::eMSet(self);
444
+ VALUE a1, a2, a3;
445
+ rb_scan_args(argc, argv, "21", &a1, &a2, &a3);
446
+ if(argc == 2){
447
+ decltype(p->insert(std::make_pair(a1, a2))) ret;
448
+ ret = p->insert(std::make_pair(a1, a2));
449
+ return ESetWrap<E>::insertRet(ret);
450
+ }else{
451
+ if(!rb_obj_is_instance_of(a1, ESetWrap<E>::cESetIt)){
452
+ rb_raise(rb_eArgError, "First argument is not a compatible iterator");
453
+ return Qnil;
454
+ }
455
+ typename E::iterator* iit = ESetWrap<E>::eMSetIt(a1);
456
+ if((E*)(*iit)._M_node->_TZ_tree != p){
457
+ rb_raise(rb_eArgError, "Referece iterator is not from the method reciever's container");
458
+ return Qnil;
459
+ }
460
+ decltype(p->insert(*iit, std::make_pair(a2, a3))) ret;
461
+ ret = p->insert(*iit, std::make_pair(a2, a3));
462
+ return ESetWrap<E>::insertRet(ret);
463
+ }
464
+ }
465
+ static VALUE eMSetIt_item(VALUE self) {
466
+ typename E::iterator* it = ESetWrap<E>::eMSetIt(self);
467
+ if(*it == ((E*)it->_M_node->_TZ_tree)->end()){
468
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
469
+ return Qnil;
470
+ }else{
471
+ VALUE v[2] = {(*it)->first, (*it)->second};
472
+ return rb_ary_new_from_values(2, (VALUE*)&v);
473
+ }
474
+ }
475
+ static void Init_eset(const char* n){
476
+ ESetWrap<E>::Init_eset(n);
477
+ rb_define_method(ESetWrap<E>::cESet, "insert", RUBY_METHOD_FUNC(eMSet_insert), -1);
478
+ rb_define_method(ESetWrap<E>::cESetIt, "item", RUBY_METHOD_FUNC(eMSetIt_item), 0);
479
+ };
480
+ };
481
+
482
+ template <typename EMSet>
483
+ struct ESetWrapMap : ESetWrapMap_<EMSet>{
484
+ };
485
+
486
+ template <>
487
+ struct ESetWrapMap<EMap> : ESetWrapMap_<EMap>{
488
+ static VALUE eMSet_insert_or_assign(int argc, VALUE *argv, VALUE self){
489
+ EMap* p = ESetWrap<EMap>::eMSet(self);
490
+ VALUE a1, a2, a3;
491
+ rb_scan_args(argc, argv, "21", &a1, &a2, &a3);
492
+ if(argc == 2){
493
+ std::pair<EMap::iterator, bool> ret;
494
+ ret = p->insert(std::make_pair(a1, a2));
495
+ if(!ret.second)
496
+ ret.first->second = a2;
497
+ return ESetWrap<EMap>::insertRet(ret);
498
+ }else{
499
+ if(!rb_obj_is_instance_of(a1, cESetIt)){
500
+ rb_raise(rb_eArgError, "First argument is not an iterator");
501
+ return Qnil;
502
+ }
503
+ iterator* iit = eMSetIt(a1);
504
+ if((EMap*)(*iit)._M_node->_TZ_tree != p){
505
+ rb_raise(rb_eArgError, "Referece iterator is not from the method reciever's container");
506
+ return Qnil;
507
+ }
508
+ EMap::iterator ret;
509
+ ret = p->insert(*iit, std::make_pair(a2, a3));
510
+ if((*ret).second != a3)
511
+ (*ret).second = a3;
512
+ return ESetWrap<EMap>::insertRet(ret);
513
+ }
514
+ }
515
+ static void Init_eset(const char* n){
516
+ ESetWrapMap_<EMap>::Init_eset(n);
517
+ rb_define_method(ESetWrap<EMap>::cESet, "insert_or_assign", RUBY_METHOD_FUNC(eMSet_insert_or_assign), -1);
518
+ }
519
+ };
520
+
521
+
522
+ template <typename EMSet>
523
+ struct ESetWrapSet : ESetWrap<EMSet>{
524
+ static VALUE eMSet_insert(int argc, VALUE *argv, VALUE self){
525
+ EMSet* p = ESetWrap<EMSet>::eMSet(self);
526
+ VALUE a1, a2;
527
+ rb_scan_args(argc, argv, "11", &a1, &a2);
528
+ if(argc == 1){
529
+ decltype(p->insert(a1)) ret;
530
+ ret = p->insert(a1);
531
+ return ESetWrap<EMSet>::insertRet(ret);
532
+ }else{
533
+ if(!rb_obj_is_instance_of(a1, ESetWrap<EMSet>::cESetIt)){
534
+ rb_raise(rb_eArgError, "First argument is not an iterator");
535
+ return Qnil;
536
+ }
537
+ typename EMSet::iterator* iit = ESetWrap<EMSet>::eMSetIt(a1);
538
+ if((EMSet*)(*iit)._M_node->_TZ_tree != p){
539
+ rb_raise(rb_eArgError, "Referece iterator is not from the method reciever's container");
540
+ return Qnil;
541
+ }
542
+ decltype(p->insert(*iit, a2)) ret;
543
+ ret = p->insert(*iit, a2);
544
+ return ESetWrap<EMSet>::insertRet(ret);
545
+ }
546
+ }
547
+ static VALUE eMSetIt_item(VALUE self) {
548
+ typename EMSet::iterator* it = ESetWrap<EMSet>::eMSetIt(self);
549
+ if(*it == ((EMSet*)it->_M_node->_TZ_tree)->end()){
550
+ rb_raise(rb_eRangeError, "Dereferencing the end iterator");
551
+ return Qnil;
552
+ }else{
553
+ return **it;
554
+ }
555
+ }
556
+ static void Init_eset(const char* n){
557
+ ESetWrap<EMSet>::Init_eset(n);
558
+ rb_define_method(ESetWrap<EMSet>::cESet, "insert", RUBY_METHOD_FUNC(eMSet_insert), -1);
559
+ rb_define_method(ESetWrap<EMSet>::cESetIt, "item", RUBY_METHOD_FUNC(eMSetIt_item), 0);
560
+ };
561
+ };
562
+
563
+
564
+ extern "C" void Init_ESet(void){
565
+ rb_mYk = rb_define_module("Yk");
566
+ ID_CALL = rb_intern("call");
567
+ ID_LESS = rb_intern("<");
568
+ ID_EQ = rb_intern("==");
569
+ ESetWrapSet<EMTSet>::Init_eset("EMSet");
570
+ ESetWrapSet<ESet>::Init_eset("ESet");
571
+ ESetWrapMap<EMTMap>::Init_eset("EMMap");
572
+ ESetWrapMap<EMap>::Init_eset("EMap");
573
+ }
574
+
575
+