rbtree 0.4.2 → 0.4.3
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.
- checksums.yaml +5 -5
- data/README +2 -15
- data/extconf.rb +1 -0
- data/rbtree.c +62 -60
- data/test.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 46dbcc33616abd5c8b981b8b6e7da4c5cb6c72335dcdf3bc58b853fc64183808
|
4
|
+
data.tar.gz: 901e36a110e792a3b62bf6daf0969edae792a061620d7e1a3ee97c8773a2aaf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c0698f5c54abd965e390104d2b3bc08959b04ac903f25dd02b6d9019b02945b6ba53f425e182bdf3291e3793b23b1ca86b7fde9216cd86492b14bd1fb85fa9c
|
7
|
+
data.tar.gz: 0c7e76b305604f3bea800d642287b82316331d909d68811285c8d05348712f886904603f3cf43e954920c3e2ae5d3dbdac1c9342c6759e3f0c70bbf78d08e4d3
|
data/README
CHANGED
@@ -57,21 +57,8 @@ Run the following command.
|
|
57
57
|
$ sudo gem install rbtree
|
58
58
|
|
59
59
|
== Changes
|
60
|
-
=== 0.4.
|
61
|
-
*
|
62
|
-
|
63
|
-
=== 0.4.1
|
64
|
-
* Fixed a crash that could be triggered when GC happened.
|
65
|
-
|
66
|
-
=== 0.4.0
|
67
|
-
|
68
|
-
* Fixed build failure with Ruby 2.0.0.
|
69
|
-
* \#bound now returns an enumerator if no block is given.
|
70
|
-
* \#select now returns a new MultiRBTree / RBTree.
|
71
|
-
* Fixed a bug where \#reject could return nil.
|
72
|
-
* \#to_s is now equivalent to \#inspect.
|
73
|
-
* \#each now passes a two elements array as an argument to the given block.
|
74
|
-
* Added new methods: \#default_proc=, \#flatten, \#keep_if, \#key, \#select! and \#to_h.
|
60
|
+
=== 0.4.3
|
61
|
+
* Quick bug fixes for Ruby 3.
|
75
62
|
|
76
63
|
== License
|
77
64
|
|
data/extconf.rb
CHANGED
@@ -10,6 +10,7 @@ have_func('rb_exec_recursive_paired', 'ruby.h')
|
|
10
10
|
have_func('rb_proc_lambda_p', 'ruby.h')
|
11
11
|
have_func('rb_ary_resize', 'ruby.h')
|
12
12
|
have_func('rb_obj_hide', 'ruby.h')
|
13
|
+
have_func('rb_safe_level', 'ruby.h')
|
13
14
|
if Hash.method_defined?(:flatten)
|
14
15
|
$defs << '-DHAVE_HASH_FLATTEN'
|
15
16
|
end
|
data/rbtree.c
CHANGED
@@ -176,8 +176,10 @@ rbtree_modify(VALUE self)
|
|
176
176
|
if (ITER_LEV(self) > 0)
|
177
177
|
rb_raise(rb_eTypeError, "can't modify rbtree during iteration");
|
178
178
|
rb_check_frozen(self);
|
179
|
+
#ifdef HAVE_RB_SAFE_LEVEL
|
179
180
|
if (!OBJ_TAINTED(self) && rb_safe_level() >= 4)
|
180
181
|
rb_raise(rb_eSecurityError, "Insecure: can't modify rbtree");
|
182
|
+
#endif
|
181
183
|
}
|
182
184
|
|
183
185
|
static VALUE
|
@@ -187,14 +189,14 @@ rbtree_alloc(VALUE klass)
|
|
187
189
|
VALUE rbtree = Data_Wrap_Struct(klass, rbtree_mark, rbtree_free, NULL);
|
188
190
|
RBTREE(rbtree) = ALLOC(rbtree_t);
|
189
191
|
MEMZERO(RBTREE(rbtree), rbtree_t, 1);
|
190
|
-
|
192
|
+
|
191
193
|
dict = ALLOC(dict_t);
|
192
194
|
dict_init(dict, rbtree_cmp);
|
193
195
|
dict_set_allocator(dict, rbtree_alloc_node, rbtree_free_node,
|
194
196
|
RBTREE(rbtree));
|
195
197
|
if (!RTEST(rb_class_inherited_p(klass, RBTree)))
|
196
198
|
dict_allow_dupes(dict);
|
197
|
-
|
199
|
+
|
198
200
|
DICT(rbtree) = dict;
|
199
201
|
IFNONE(rbtree) = Qnil;
|
200
202
|
CMP_PROC(rbtree) = Qnil;
|
@@ -224,29 +226,29 @@ rbtree_s_create(int argc, VALUE* argv, VALUE klass)
|
|
224
226
|
{
|
225
227
|
long i;
|
226
228
|
VALUE rbtree;
|
227
|
-
|
229
|
+
|
228
230
|
if (argc == 1) {
|
229
231
|
VALUE temp;
|
230
|
-
|
232
|
+
|
231
233
|
if (rb_obj_is_kind_of(argv[0], klass)) {
|
232
234
|
rbtree = rbtree_alloc(klass);
|
233
235
|
rbtree_update(rbtree, argv[0]);
|
234
236
|
return rbtree;
|
235
237
|
}
|
236
|
-
|
238
|
+
|
237
239
|
if (RTEST(rb_class_inherited_p(klass, RBTree)) &&
|
238
240
|
(rb_obj_is_kind_of(argv[0], MultiRBTree) && !rb_obj_is_kind_of(argv[0], RBTree))) {
|
239
|
-
|
241
|
+
|
240
242
|
rb_raise(rb_eTypeError, "wrong argument type MultiRBTree (expected RBTree)");
|
241
243
|
}
|
242
|
-
|
244
|
+
|
243
245
|
temp = rb_check_convert_type(argv[0], T_HASH, "Hash", "to_hash");
|
244
246
|
if (!NIL_P(temp)) {
|
245
247
|
rbtree = rbtree_alloc(klass);
|
246
248
|
rb_hash_foreach(temp, hash_to_rbtree_i, rbtree);
|
247
249
|
return rbtree;
|
248
250
|
}
|
249
|
-
|
251
|
+
|
250
252
|
temp = rb_check_array_type(argv[0]);
|
251
253
|
if (!NIL_P(temp)) {
|
252
254
|
rbtree = rbtree_alloc(klass);
|
@@ -272,7 +274,7 @@ rbtree_s_create(int argc, VALUE* argv, VALUE klass)
|
|
272
274
|
return rbtree;
|
273
275
|
}
|
274
276
|
}
|
275
|
-
|
277
|
+
|
276
278
|
if (argc % 2 != 0)
|
277
279
|
rb_raise(rb_eArgError, "odd number of arguments for %s", rb_class2name(klass));
|
278
280
|
|
@@ -325,7 +327,7 @@ insert_node_body(rbtree_insert_arg_t* arg)
|
|
325
327
|
{
|
326
328
|
dict_t* dict = arg->dict;
|
327
329
|
dnode_t* node = arg->node;
|
328
|
-
|
330
|
+
|
329
331
|
if (dict_insert(dict, node, dnode_getkey(node))) {
|
330
332
|
if (TYPE(GET_KEY(node)) == T_STRING) {
|
331
333
|
arg->result = KeyAllocationFailed;
|
@@ -343,7 +345,7 @@ insert_node_ensure(rbtree_insert_arg_t* arg)
|
|
343
345
|
{
|
344
346
|
dict_t* dict = arg->dict;
|
345
347
|
dnode_t* node = arg->node;
|
346
|
-
|
348
|
+
|
347
349
|
switch (arg->result) {
|
348
350
|
case InsertionSucceeded:
|
349
351
|
break;
|
@@ -366,7 +368,7 @@ rbtree_insert(VALUE self, VALUE key, VALUE value)
|
|
366
368
|
|
367
369
|
dnode_init(node, TO_VAL(value));
|
368
370
|
node->dict_key = TO_KEY(key);
|
369
|
-
|
371
|
+
|
370
372
|
arg.dict = dict;
|
371
373
|
arg.node = node;
|
372
374
|
arg.result = NoNodeInserted;
|
@@ -501,14 +503,14 @@ VALUE
|
|
501
503
|
rbtree_set_default_proc(VALUE self, VALUE proc)
|
502
504
|
{
|
503
505
|
VALUE temp;
|
504
|
-
|
506
|
+
|
505
507
|
rbtree_modify(self);
|
506
508
|
if (NIL_P(proc)) {
|
507
509
|
IFNONE(self) = Qnil;
|
508
510
|
FL_UNSET(self, RBTREE_PROC_DEFAULT);
|
509
511
|
return Qnil;
|
510
512
|
}
|
511
|
-
|
513
|
+
|
512
514
|
temp = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
|
513
515
|
if (NIL_P(temp)) {
|
514
516
|
rb_raise(rb_eTypeError,
|
@@ -528,16 +530,16 @@ rbtree_recursive_equal(VALUE self, VALUE other, int recursive)
|
|
528
530
|
dict_t* dict2 = DICT(other);
|
529
531
|
dnode_t* node1;
|
530
532
|
dnode_t* node2;
|
531
|
-
|
533
|
+
|
532
534
|
if (recursive)
|
533
535
|
return Qtrue;
|
534
536
|
for (node1 = dict_first(dict1), node2 = dict_first(dict2);
|
535
537
|
node1 != NULL && node2 != NULL;
|
536
538
|
node1 = dict_next(dict1, node1), node2 = dict_next(dict2, node2)) {
|
537
|
-
|
539
|
+
|
538
540
|
if (!rb_equal(GET_KEY(node1), GET_KEY(node2)) ||
|
539
541
|
!rb_equal(GET_VAL(node1), GET_VAL(node2))) {
|
540
|
-
|
542
|
+
|
541
543
|
return Qfalse;
|
542
544
|
}
|
543
545
|
}
|
@@ -557,7 +559,7 @@ rbtree_equal(VALUE self, VALUE other)
|
|
557
559
|
if (dict_count(DICT(self)) != dict_count(DICT(other)) ||
|
558
560
|
DICT(self)->dict_compare != DICT(other)->dict_compare ||
|
559
561
|
CMP_PROC(self) != CMP_PROC(other)) {
|
560
|
-
|
562
|
+
|
561
563
|
return Qfalse;
|
562
564
|
}
|
563
565
|
#if defined(HAVE_RB_EXEC_RECURSIVE_PAIRED)
|
@@ -599,7 +601,7 @@ rbtree_each_body(rbtree_each_arg_t* arg)
|
|
599
601
|
dnode_t* node;
|
600
602
|
dnode_t* first_node;
|
601
603
|
dnode_t* (*next_func)(dict_t*, dnode_t*);
|
602
|
-
|
604
|
+
|
603
605
|
if (arg->reverse) {
|
604
606
|
first_node = dict_last(dict);
|
605
607
|
next_func = dict_prev;
|
@@ -607,12 +609,12 @@ rbtree_each_body(rbtree_each_arg_t* arg)
|
|
607
609
|
first_node = dict_first(dict);
|
608
610
|
next_func = dict_next;
|
609
611
|
}
|
610
|
-
|
612
|
+
|
611
613
|
ITER_LEV(self)++;
|
612
614
|
for (node = first_node;
|
613
615
|
node != NULL;
|
614
616
|
node = next_func(dict, node)) {
|
615
|
-
|
617
|
+
|
616
618
|
if (arg->func(node, arg->arg) == EACH_STOP)
|
617
619
|
break;
|
618
620
|
}
|
@@ -776,7 +778,7 @@ VALUE
|
|
776
778
|
rbtree_initialize_copy(VALUE self, VALUE other)
|
777
779
|
{
|
778
780
|
rbtree_modify(self);
|
779
|
-
|
781
|
+
|
780
782
|
if (self == other)
|
781
783
|
return self;
|
782
784
|
if (!rb_obj_is_kind_of(other, CLASS_OF(self))) {
|
@@ -784,9 +786,9 @@ rbtree_initialize_copy(VALUE self, VALUE other)
|
|
784
786
|
rb_obj_classname(other),
|
785
787
|
rb_obj_classname(self));
|
786
788
|
}
|
787
|
-
|
789
|
+
|
788
790
|
copy_dict(other, self, DICT(other)->dict_compare, CMP_PROC(other));
|
789
|
-
|
791
|
+
|
790
792
|
IFNONE(self) = IFNONE(other);
|
791
793
|
if (FL_TEST(other, RBTREE_PROC_DEFAULT))
|
792
794
|
FL_SET(self, RBTREE_PROC_DEFAULT);
|
@@ -803,7 +805,7 @@ rbtree_values_at(int argc, VALUE* argv, VALUE self)
|
|
803
805
|
{
|
804
806
|
long i;
|
805
807
|
VALUE ary = rb_ary_new2(argc);
|
806
|
-
|
808
|
+
|
807
809
|
for (i = 0; i < argc; i++)
|
808
810
|
rb_ary_push(ary, rbtree_aref(self, argv[i]));
|
809
811
|
return ary;
|
@@ -937,7 +939,7 @@ static VALUE
|
|
937
939
|
rbtree_remove_if(VALUE self, const int if_true)
|
938
940
|
{
|
939
941
|
rbtree_remove_if_arg_t arg;
|
940
|
-
|
942
|
+
|
941
943
|
RETURN_SIZED_ENUMERATOR(self, 0, NULL, rbtree_size);
|
942
944
|
rbtree_modify(self);
|
943
945
|
arg.self = self;
|
@@ -974,7 +976,7 @@ VALUE
|
|
974
976
|
rbtree_reject_bang(VALUE self)
|
975
977
|
{
|
976
978
|
dictcount_t count;
|
977
|
-
|
979
|
+
|
978
980
|
RETURN_SIZED_ENUMERATOR(self, 0, NULL, rbtree_size);
|
979
981
|
count = dict_count(DICT(self));
|
980
982
|
rbtree_delete_if(self);
|
@@ -990,14 +992,14 @@ VALUE
|
|
990
992
|
rbtree_select_bang(VALUE self)
|
991
993
|
{
|
992
994
|
dictcount_t count;
|
993
|
-
|
995
|
+
|
994
996
|
RETURN_SIZED_ENUMERATOR(self, 0, NULL, rbtree_size);
|
995
997
|
count = dict_count(DICT(self));
|
996
998
|
rbtree_keep_if(self);
|
997
999
|
if (count == dict_count(DICT(self)))
|
998
1000
|
return Qnil;
|
999
1001
|
return self;
|
1000
|
-
|
1002
|
+
|
1001
1003
|
}
|
1002
1004
|
|
1003
1005
|
/*********************************************************************/
|
@@ -1013,7 +1015,7 @@ select_i(dnode_t* node, void* arg_)
|
|
1013
1015
|
VALUE key = GET_KEY(node);
|
1014
1016
|
VALUE value = GET_VAL(node);
|
1015
1017
|
rbtree_select_if_arg_t* arg = arg_;
|
1016
|
-
|
1018
|
+
|
1017
1019
|
if (RTEST(rb_yield_values(2, key, value)) == arg->if_true) {
|
1018
1020
|
rbtree_aset(arg->result, key, value);
|
1019
1021
|
}
|
@@ -1024,7 +1026,7 @@ static VALUE
|
|
1024
1026
|
rbtree_select_if(VALUE self, const int if_true)
|
1025
1027
|
{
|
1026
1028
|
rbtree_select_if_arg_t arg;
|
1027
|
-
|
1029
|
+
|
1028
1030
|
RETURN_SIZED_ENUMERATOR(self, 0, NULL, rbtree_size);
|
1029
1031
|
arg.result = rbtree_alloc(CLASS_OF(self));
|
1030
1032
|
arg.if_true = if_true;
|
@@ -1063,7 +1065,7 @@ rbtree_shift_pop(VALUE self, const int shift)
|
|
1063
1065
|
|
1064
1066
|
if (dict_isempty(dict))
|
1065
1067
|
return rb_funcall(self, id_default, 1, Qnil);
|
1066
|
-
|
1068
|
+
|
1067
1069
|
if (shift)
|
1068
1070
|
node = dict_last(dict);
|
1069
1071
|
else
|
@@ -1145,7 +1147,7 @@ rbtree_update(VALUE self, VALUE other)
|
|
1145
1147
|
rb_obj_classname(other),
|
1146
1148
|
rb_obj_classname(self));
|
1147
1149
|
}
|
1148
|
-
|
1150
|
+
|
1149
1151
|
if (rb_block_given_p())
|
1150
1152
|
rbtree_for_each(other, update_block_i, (void*)self);
|
1151
1153
|
else
|
@@ -1295,7 +1297,7 @@ rbtree_to_hash(VALUE self)
|
|
1295
1297
|
VALUE hash;
|
1296
1298
|
if (!rb_obj_is_kind_of(self, RBTree))
|
1297
1299
|
rb_raise(rb_eTypeError, "can't convert MultiRBTree to Hash");
|
1298
|
-
|
1300
|
+
|
1299
1301
|
hash = rb_hash_new();
|
1300
1302
|
rbtree_for_each(self, to_hash_i, (void*)hash);
|
1301
1303
|
RHASH_SET_IFNONE(hash, IFNONE(self));
|
@@ -1351,7 +1353,7 @@ static VALUE
|
|
1351
1353
|
inspect_rbtree(VALUE self, VALUE result)
|
1352
1354
|
{
|
1353
1355
|
VALUE str;
|
1354
|
-
|
1356
|
+
|
1355
1357
|
rb_str_cat2(result, "{");
|
1356
1358
|
RSTRING_PTR(result)[0] = '-';
|
1357
1359
|
rbtree_for_each(self, inspect_i, (void*)result);
|
@@ -1362,7 +1364,7 @@ inspect_rbtree(VALUE self, VALUE result)
|
|
1362
1364
|
rb_str_cat2(result, ", default=");
|
1363
1365
|
rb_str_append(result, str);
|
1364
1366
|
OBJ_INFECT(result, str);
|
1365
|
-
|
1367
|
+
|
1366
1368
|
str = rb_inspect(CMP_PROC(self));
|
1367
1369
|
rb_str_cat2(result, ", cmp_proc=");
|
1368
1370
|
rb_str_append(result, str);
|
@@ -1495,18 +1497,18 @@ rbtree_bound_size(VALUE self, VALUE args)
|
|
1495
1497
|
dnode_t* upper_node = dict_upper_bound(DICT(self), TO_KEY(key2));
|
1496
1498
|
dictcount_t count = 0;
|
1497
1499
|
dnode_t* node;
|
1498
|
-
|
1500
|
+
|
1499
1501
|
if (lower_node == NULL || upper_node == NULL ||
|
1500
1502
|
DICT(self)->dict_compare(dnode_getkey(lower_node),
|
1501
1503
|
dnode_getkey(upper_node),
|
1502
1504
|
DICT(self)->dict_context) > 0) {
|
1503
1505
|
return INT2FIX(0);
|
1504
1506
|
}
|
1505
|
-
|
1507
|
+
|
1506
1508
|
for (node = lower_node;
|
1507
1509
|
node != NULL;
|
1508
1510
|
node = dict_next(DICT(self), node)) {
|
1509
|
-
|
1511
|
+
|
1510
1512
|
count++;
|
1511
1513
|
if (node == upper_node) {
|
1512
1514
|
break;
|
@@ -1533,7 +1535,7 @@ rbtree_bound_size(VALUE self, VALUE args)
|
|
1533
1535
|
* mrbtree = MultiRBTree["az", 10, "ba", 20, "ba", 30, "bz", 40]
|
1534
1536
|
* mrbtree.bound("ba").to_a # => [["ba", 20], ["ba", 30]]
|
1535
1537
|
* mrbtree.bound("b", "c").to_a # => [["ba", 20], ["ba", 30], ["bz", 40]]
|
1536
|
-
*
|
1538
|
+
*
|
1537
1539
|
* # the lower bound ("ba") exceeds the upper bound ("az")
|
1538
1540
|
* mrbtree.bound("b").to_a # => []
|
1539
1541
|
*/
|
@@ -1544,15 +1546,15 @@ rbtree_bound(int argc, VALUE* argv, VALUE self)
|
|
1544
1546
|
dnode_t* lower_node;
|
1545
1547
|
dnode_t* upper_node;
|
1546
1548
|
VALUE result;
|
1547
|
-
|
1549
|
+
|
1548
1550
|
rbtree_check_argument_count(argc, 1, 2);
|
1549
|
-
|
1551
|
+
|
1550
1552
|
RETURN_SIZED_ENUMERATOR(self, argc, argv, rbtree_bound_size);
|
1551
|
-
|
1553
|
+
|
1552
1554
|
lower_node = dict_lower_bound(dict, TO_KEY(argv[0]));
|
1553
1555
|
upper_node = dict_upper_bound(dict, TO_KEY(argv[argc - 1]));
|
1554
1556
|
result = rb_block_given_p() ? self : rb_ary_new();
|
1555
|
-
|
1557
|
+
|
1556
1558
|
if (lower_node == NULL || upper_node == NULL ||
|
1557
1559
|
DICT(self)->dict_compare(dnode_getkey(lower_node),
|
1558
1560
|
dnode_getkey(upper_node),
|
@@ -1577,7 +1579,7 @@ rbtree_first_last(VALUE self, const int first)
|
|
1577
1579
|
|
1578
1580
|
if (dict_isempty(dict))
|
1579
1581
|
return rb_funcall(self, id_default, 1, Qnil);
|
1580
|
-
|
1582
|
+
|
1581
1583
|
if (first)
|
1582
1584
|
node = dict_first(dict);
|
1583
1585
|
else
|
@@ -1627,7 +1629,7 @@ rbtree_last(VALUE self)
|
|
1627
1629
|
* rbtree = RBTree["a", 10, "b", 20]
|
1628
1630
|
* rbtree.readjust {|a, b| b <=> a }
|
1629
1631
|
* rbtree.first # => ["b", 20]
|
1630
|
-
*
|
1632
|
+
*
|
1631
1633
|
* rbtree.readjust(nil)
|
1632
1634
|
* rbtree.first # => ["a", 10]
|
1633
1635
|
*/
|
@@ -1636,7 +1638,7 @@ rbtree_readjust(int argc, VALUE* argv, VALUE self)
|
|
1636
1638
|
{
|
1637
1639
|
dict_comp_t cmp_func = NULL;
|
1638
1640
|
VALUE cmp_proc = Qnil;
|
1639
|
-
|
1641
|
+
|
1640
1642
|
rbtree_modify(self);
|
1641
1643
|
|
1642
1644
|
if (rb_block_given_p()) {
|
@@ -1728,7 +1730,7 @@ pp_pair(VALUE nil, pp_pair_arg_t* pair_arg)
|
|
1728
1730
|
group_args[1] = INT2FIX(1);
|
1729
1731
|
group_args[2] = rb_str_new(NULL, 0);
|
1730
1732
|
group_args[3] = rb_str_new(NULL, 0);
|
1731
|
-
|
1733
|
+
|
1732
1734
|
rb_funcall(pp, id_pp, 1, GET_KEY(pair_arg->node));
|
1733
1735
|
rb_funcall(pp, id_text, 1, rb_str_new2("=>"));
|
1734
1736
|
return rb_iterate(pp_group, (VALUE)&group_args, pp_value, (VALUE)pair_arg);
|
@@ -1745,21 +1747,21 @@ pp_each_pair_i(dnode_t* node, void* each_pair_arg_)
|
|
1745
1747
|
pp_each_pair_arg_t* each_pair_arg = (pp_each_pair_arg_t*)each_pair_arg_;
|
1746
1748
|
VALUE group_args[4];
|
1747
1749
|
pp_pair_arg_t pair_arg;
|
1748
|
-
|
1750
|
+
|
1749
1751
|
if (each_pair_arg->first) {
|
1750
1752
|
each_pair_arg->first = 0;
|
1751
1753
|
} else {
|
1752
1754
|
rb_funcall(each_pair_arg->pp, id_comma_breakable, 0);
|
1753
1755
|
}
|
1754
|
-
|
1756
|
+
|
1755
1757
|
group_args[0] = each_pair_arg->pp;
|
1756
1758
|
group_args[1] = INT2FIX(0);
|
1757
1759
|
group_args[2] = rb_str_new(NULL, 0);
|
1758
1760
|
group_args[3] = rb_str_new(NULL, 0);
|
1759
|
-
|
1761
|
+
|
1760
1762
|
pair_arg.pp = each_pair_arg->pp;
|
1761
1763
|
pair_arg.node = node;
|
1762
|
-
|
1764
|
+
|
1763
1765
|
rb_iterate(pp_group, (VALUE)&group_args, pp_pair, (VALUE)&pair_arg);
|
1764
1766
|
return EACH_NEXT;
|
1765
1767
|
}
|
@@ -1783,13 +1785,13 @@ pp_rbtree(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
1783
1785
|
{
|
1784
1786
|
VALUE pp = rbtree_arg->pp;
|
1785
1787
|
VALUE rbtree = rbtree_arg->rbtree;
|
1786
|
-
|
1788
|
+
|
1787
1789
|
VALUE group_args[4];
|
1788
1790
|
group_args[0] = pp;
|
1789
1791
|
group_args[1] = INT2FIX(1);
|
1790
1792
|
group_args[2] = rb_str_new2("{");
|
1791
1793
|
group_args[3] = rb_str_new2("}");
|
1792
|
-
|
1794
|
+
|
1793
1795
|
rb_funcall(pp, id_text, 1, rb_str_new2(": "));
|
1794
1796
|
rb_iterate(pp_group, (VALUE)&group_args, pp_each_pair, (VALUE)rbtree_arg);
|
1795
1797
|
rb_funcall(pp, id_comma_breakable, 0);
|
@@ -1840,17 +1842,17 @@ rbtree_dump(VALUE self, VALUE limit)
|
|
1840
1842
|
{
|
1841
1843
|
VALUE ary;
|
1842
1844
|
VALUE result;
|
1843
|
-
|
1845
|
+
|
1844
1846
|
if (FL_TEST(self, RBTREE_PROC_DEFAULT))
|
1845
1847
|
rb_raise(rb_eTypeError, "can't dump rbtree with default proc");
|
1846
1848
|
if (CMP_PROC(self) != Qnil)
|
1847
1849
|
rb_raise(rb_eTypeError, "can't dump rbtree with comparison proc");
|
1848
|
-
|
1850
|
+
|
1849
1851
|
ary = rb_ary_new2(dict_count(DICT(self)) * 2 + 1);
|
1850
1852
|
rbtree_for_each(self, to_flat_ary_i, (void*)ary);
|
1851
1853
|
rb_ary_push(ary, IFNONE(self));
|
1852
1854
|
|
1853
|
-
result = rb_marshal_dump(ary,
|
1855
|
+
result = rb_marshal_dump(ary, Qnil);
|
1854
1856
|
#ifdef HAVE_RB_ARY_RESIZE
|
1855
1857
|
rb_ary_resize(ary, 0);
|
1856
1858
|
#else
|
@@ -1869,11 +1871,11 @@ rbtree_s_load(VALUE klass, VALUE str)
|
|
1869
1871
|
VALUE ary = rb_marshal_load(str);
|
1870
1872
|
long len = RARRAY_LEN(ary) - 1;
|
1871
1873
|
long i;
|
1872
|
-
|
1874
|
+
|
1873
1875
|
for (i = 0; i < len; i += 2)
|
1874
1876
|
rbtree_aset(rbtree, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i + 1));
|
1875
1877
|
IFNONE(rbtree) = RARRAY_AREF(ary, len);
|
1876
|
-
|
1878
|
+
|
1877
1879
|
#ifdef HAVE_RB_ARY_RESIZE
|
1878
1880
|
rb_ary_resize(ary, 0);
|
1879
1881
|
#else
|
@@ -1975,7 +1977,7 @@ void Init_rbtree()
|
|
1975
1977
|
|
1976
1978
|
rb_define_method(MultiRBTree, "_dump", rbtree_dump, 1);
|
1977
1979
|
rb_define_singleton_method(MultiRBTree, "_load", rbtree_s_load, 1);
|
1978
|
-
|
1980
|
+
|
1979
1981
|
id_cmp = rb_intern("<=>");
|
1980
1982
|
id_call = rb_intern("call");
|
1981
1983
|
id_default = rb_intern("default");
|
data/test.rb
CHANGED
@@ -620,7 +620,7 @@ class RBTreeTest < Test::Unit::TestCase
|
|
620
620
|
tree, default, cmp_proc = match.to_a[1..-1]
|
621
621
|
assert_equal(%({"a"=>"A", "b"=>"B", "c"=>"C", "d"=>"D"}), tree)
|
622
622
|
assert_equal(%("e"), default)
|
623
|
-
assert_match(/#<Proc:\w+(
|
623
|
+
assert_match(/#<Proc:\w+([@ ]#{__FILE__}:\d+)?>/o, cmp_proc)
|
624
624
|
|
625
625
|
rbtree = RBTree.new
|
626
626
|
assert_match(re, rbtree.send(method))
|
metadata
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OZAWA Takuma
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A RBTree is a sorted associative collection that is implemented with a
|
15
15
|
Red-Black Tree. It maps keys to values like a Hash, but maintains its
|
16
16
|
elements in ascending key order. The interface is the almost identical
|
17
17
|
to that of Hash.
|
18
|
-
email:
|
18
|
+
email:
|
19
19
|
executables: []
|
20
20
|
extensions:
|
21
21
|
- extconf.rb
|
@@ -36,7 +36,7 @@ homepage: http://rbtree.rubyforge.org/
|
|
36
36
|
licenses:
|
37
37
|
- MIT
|
38
38
|
metadata: {}
|
39
|
-
post_install_message:
|
39
|
+
post_install_message:
|
40
40
|
rdoc_options:
|
41
41
|
- "--title"
|
42
42
|
- Ruby/RBTree
|
@@ -57,9 +57,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
|
-
|
61
|
-
|
62
|
-
signing_key:
|
60
|
+
rubygems_version: 3.2.3
|
61
|
+
signing_key:
|
63
62
|
specification_version: 4
|
64
63
|
summary: A sorted associative collection.
|
65
64
|
test_files:
|