rbtree 0.4.5 → 0.4.7
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 +4 -4
- data/README +6 -0
- data/extconf.rb +0 -8
- data/rbtree.c +76 -94
- data/test.rb +135 -131
- metadata +37 -39
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72f18733355c87536d364795cdd7fcf58df0da573a6783c990640421e2a86053
|
|
4
|
+
data.tar.gz: 36a91f75a7fe0dd31124dc59484728d418c76571e9f998e37c9df7aaa3ff8688
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3d86bf49df4a5e270ff242203dd0f7af50f4588392766b20274678b441dd09f622621312817799073e0f3edb2a0246bc62667dcd36faa5c168198d6d7fa97b2
|
|
7
|
+
data.tar.gz: f9fb843cd939997bbb4231f85f7eedd48b51c37b32200835567f4875130fc84ac9cc546a82e908567338e40d6874cc0fbd3658216aae2ec09a110c446c7413fb
|
data/README
CHANGED
|
@@ -57,6 +57,12 @@ Run the following command.
|
|
|
57
57
|
$ sudo gem install rbtree
|
|
58
58
|
|
|
59
59
|
== Changes
|
|
60
|
+
=== 0.4.7
|
|
61
|
+
* Use the typed data API, as the untyped data API will be removed in Ruby 4.1.
|
|
62
|
+
|
|
63
|
+
=== 0.4.6
|
|
64
|
+
* Make it work with clang 15.
|
|
65
|
+
|
|
60
66
|
=== 0.4.5
|
|
61
67
|
* Support Ruby 3.2.0-dev (development branch).
|
|
62
68
|
|
data/extconf.rb
CHANGED
|
@@ -5,14 +5,6 @@ if enable_config('debug')
|
|
|
5
5
|
else
|
|
6
6
|
$defs << '-DNDEBUG'
|
|
7
7
|
end
|
|
8
|
-
have_func('rb_exec_recursive', 'ruby.h')
|
|
9
|
-
have_func('rb_exec_recursive_paired', 'ruby.h')
|
|
10
|
-
have_func('rb_proc_lambda_p', 'ruby.h')
|
|
11
|
-
have_func('rb_ary_resize', 'ruby.h')
|
|
12
|
-
have_func('rb_obj_hide', 'ruby.h')
|
|
13
8
|
have_func('rb_safe_level', 'ruby.h')
|
|
14
9
|
have_func('rb_cData', 'ruby.h')
|
|
15
|
-
if Hash.method_defined?(:flatten)
|
|
16
|
-
$defs << '-DHAVE_HASH_FLATTEN'
|
|
17
|
-
end
|
|
18
10
|
create_makefile('rbtree')
|
data/rbtree.c
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
* Copyright (c) 2002-2013 OZAWA Takuma
|
|
4
4
|
*/
|
|
5
5
|
#include <ruby.h>
|
|
6
|
+
#ifdef HAVE_RUBY_VERSION_H
|
|
7
|
+
#include <ruby/version.h>
|
|
8
|
+
#endif
|
|
6
9
|
#ifdef HAVE_RUBY_ST_H
|
|
7
10
|
#include <ruby/st.h>
|
|
8
11
|
#else
|
|
@@ -13,24 +16,6 @@
|
|
|
13
16
|
#define RBTREE_PROC_DEFAULT FL_USER2
|
|
14
17
|
#define HASH_PROC_DEFAULT FL_USER2
|
|
15
18
|
|
|
16
|
-
#ifdef RETURN_SIZED_ENUMERATOR
|
|
17
|
-
#define HAVE_SIZED_ENUMERATOR
|
|
18
|
-
#else
|
|
19
|
-
#ifdef RETURN_ENUMERATOR
|
|
20
|
-
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) RETURN_ENUMERATOR(obj, argc, argv)
|
|
21
|
-
#else
|
|
22
|
-
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) ((void)0)
|
|
23
|
-
#endif
|
|
24
|
-
#endif
|
|
25
|
-
|
|
26
|
-
#ifndef RARRAY_AREF
|
|
27
|
-
#define RARRAY_AREF(a, i) (RARRAY_PTR(a)[i])
|
|
28
|
-
#endif
|
|
29
|
-
|
|
30
|
-
#ifndef RHASH_SET_IFNONE
|
|
31
|
-
#define RHASH_SET_IFNONE(h, v) (RHASH(h)->ifnone = (v))
|
|
32
|
-
#endif
|
|
33
|
-
|
|
34
19
|
VALUE RBTree;
|
|
35
20
|
VALUE MultiRBTree;
|
|
36
21
|
|
|
@@ -61,16 +46,18 @@ typedef struct {
|
|
|
61
46
|
/*********************************************************************/
|
|
62
47
|
|
|
63
48
|
static void
|
|
64
|
-
rbtree_free(
|
|
49
|
+
rbtree_free(void* arg)
|
|
65
50
|
{
|
|
51
|
+
rbtree_t* rbtree = arg;
|
|
66
52
|
dict_free_nodes(rbtree->dict);
|
|
67
53
|
xfree(rbtree->dict);
|
|
68
54
|
xfree(rbtree);
|
|
69
55
|
}
|
|
70
56
|
|
|
71
57
|
static void
|
|
72
|
-
rbtree_mark(
|
|
58
|
+
rbtree_mark(void* arg)
|
|
73
59
|
{
|
|
60
|
+
rbtree_t* rbtree = arg;
|
|
74
61
|
if (rbtree == NULL) return;
|
|
75
62
|
|
|
76
63
|
if (rbtree->dict != NULL) {
|
|
@@ -88,6 +75,15 @@ rbtree_mark(rbtree_t* rbtree)
|
|
|
88
75
|
rb_gc_mark(rbtree->cmp_proc);
|
|
89
76
|
}
|
|
90
77
|
|
|
78
|
+
#ifdef TypedData_Make_Struct
|
|
79
|
+
static const rb_data_type_t rbtree_type = {
|
|
80
|
+
"RBTree",
|
|
81
|
+
{
|
|
82
|
+
rbtree_mark, rbtree_free,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
#endif
|
|
86
|
+
|
|
91
87
|
static dnode_t*
|
|
92
88
|
rbtree_alloc_node(void* context)
|
|
93
89
|
{
|
|
@@ -118,7 +114,6 @@ rbtree_check_argument_count(const int argc, const int min, const int max)
|
|
|
118
114
|
static void
|
|
119
115
|
rbtree_check_proc_arity(VALUE proc, const int expected)
|
|
120
116
|
{
|
|
121
|
-
#ifdef HAVE_RB_PROC_LAMBDA_P
|
|
122
117
|
if (rb_proc_lambda_p(proc)) {
|
|
123
118
|
const int arity = rb_proc_arity(proc);
|
|
124
119
|
const int min = arity < 0 ? -arity - 1 : arity;
|
|
@@ -127,29 +122,30 @@ rbtree_check_proc_arity(VALUE proc, const int expected)
|
|
|
127
122
|
rb_raise(rb_eTypeError, "proc takes %d arguments", expected);
|
|
128
123
|
}
|
|
129
124
|
}
|
|
130
|
-
#endif
|
|
131
125
|
}
|
|
132
126
|
|
|
133
127
|
static int
|
|
134
128
|
rbtree_cmp(const void* key1, const void* key2, void* context)
|
|
135
129
|
{
|
|
136
130
|
VALUE result;
|
|
137
|
-
if (TYPE(key1) == T_STRING && TYPE(key2) == T_STRING)
|
|
131
|
+
if (TYPE((VALUE)key1) == T_STRING && TYPE((VALUE)key2) == T_STRING)
|
|
138
132
|
return rb_str_cmp((VALUE)key1, (VALUE)key2);
|
|
139
133
|
result = rb_funcall2((VALUE)key1, id_cmp, 1, (VALUE*)&key2);
|
|
140
134
|
return rb_cmpint(result, (VALUE)key1, (VALUE)key2);
|
|
141
135
|
}
|
|
142
136
|
|
|
143
137
|
static VALUE
|
|
144
|
-
rbtree_user_cmp_ensure(
|
|
138
|
+
rbtree_user_cmp_ensure(VALUE arg)
|
|
145
139
|
{
|
|
140
|
+
rbtree_t* rbtree = (rbtree_t*)arg;
|
|
146
141
|
rbtree->iter_lev--;
|
|
147
142
|
return Qnil;
|
|
148
143
|
}
|
|
149
144
|
|
|
150
145
|
static VALUE
|
|
151
|
-
rbtree_user_cmp_body(VALUE
|
|
146
|
+
rbtree_user_cmp_body(VALUE arg)
|
|
152
147
|
{
|
|
148
|
+
VALUE *args = (VALUE*)arg;
|
|
153
149
|
rbtree_t* rbtree = (rbtree_t*)args[2];
|
|
154
150
|
rbtree->iter_lev++;
|
|
155
151
|
return rb_funcall2(rbtree->cmp_proc, id_call, 2, args);
|
|
@@ -186,20 +182,22 @@ static VALUE
|
|
|
186
182
|
rbtree_alloc(VALUE klass)
|
|
187
183
|
{
|
|
188
184
|
dict_t* dict;
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
185
|
+
rbtree_t *t;
|
|
186
|
+
#ifdef TypedData_Make_Struct
|
|
187
|
+
VALUE rbtree = TypedData_Make_Struct(klass, rbtree_t, &rbtree_type, t);
|
|
188
|
+
#else
|
|
189
|
+
VALUE rbtree = Data_Make_Struct(klass, rbtree_mark, rbtree_free, t);
|
|
190
|
+
#endif
|
|
192
191
|
|
|
193
192
|
dict = ALLOC(dict_t);
|
|
194
193
|
dict_init(dict, rbtree_cmp);
|
|
195
|
-
dict_set_allocator(dict, rbtree_alloc_node, rbtree_free_node,
|
|
196
|
-
RBTREE(rbtree));
|
|
194
|
+
dict_set_allocator(dict, rbtree_alloc_node, rbtree_free_node, t);
|
|
197
195
|
if (!RTEST(rb_class_inherited_p(klass, RBTree)))
|
|
198
196
|
dict_allow_dupes(dict);
|
|
199
197
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
t->dict = dict;
|
|
199
|
+
t->ifnone = Qnil;
|
|
200
|
+
t->cmp_proc = Qnil;
|
|
203
201
|
return rbtree;
|
|
204
202
|
}
|
|
205
203
|
|
|
@@ -323,8 +321,9 @@ typedef struct {
|
|
|
323
321
|
} rbtree_insert_arg_t;
|
|
324
322
|
|
|
325
323
|
static VALUE
|
|
326
|
-
insert_node_body(
|
|
324
|
+
insert_node_body(VALUE arg_)
|
|
327
325
|
{
|
|
326
|
+
rbtree_insert_arg_t* arg = (rbtree_insert_arg_t*)arg_;
|
|
328
327
|
dict_t* dict = arg->dict;
|
|
329
328
|
dnode_t* node = arg->node;
|
|
330
329
|
|
|
@@ -341,8 +340,9 @@ insert_node_body(rbtree_insert_arg_t* arg)
|
|
|
341
340
|
}
|
|
342
341
|
|
|
343
342
|
static VALUE
|
|
344
|
-
insert_node_ensure(
|
|
343
|
+
insert_node_ensure(VALUE arg_)
|
|
345
344
|
{
|
|
345
|
+
rbtree_insert_arg_t* arg = (rbtree_insert_arg_t*)arg_;
|
|
346
346
|
dict_t* dict = arg->dict;
|
|
347
347
|
dnode_t* node = arg->node;
|
|
348
348
|
|
|
@@ -562,13 +562,7 @@ rbtree_equal(VALUE self, VALUE other)
|
|
|
562
562
|
|
|
563
563
|
return Qfalse;
|
|
564
564
|
}
|
|
565
|
-
#if defined(HAVE_RB_EXEC_RECURSIVE_PAIRED)
|
|
566
565
|
return rb_exec_recursive_paired(rbtree_recursive_equal, self, other, other);
|
|
567
|
-
#elif defined(HAVE_RB_EXEC_RECURSIVE)
|
|
568
|
-
return rb_exec_recursive(rbtree_recursive_equal, self, other);
|
|
569
|
-
#else
|
|
570
|
-
return rbtree_recursive_equal(self, other, 0);
|
|
571
|
-
#endif
|
|
572
566
|
}
|
|
573
567
|
|
|
574
568
|
/*********************************************************************/
|
|
@@ -594,8 +588,9 @@ rbtree_each_ensure(VALUE self)
|
|
|
594
588
|
}
|
|
595
589
|
|
|
596
590
|
static VALUE
|
|
597
|
-
rbtree_each_body(
|
|
591
|
+
rbtree_each_body(VALUE arg_)
|
|
598
592
|
{
|
|
593
|
+
rbtree_each_arg_t* arg = (rbtree_each_arg_t*)arg_;
|
|
599
594
|
VALUE self = arg->self;
|
|
600
595
|
dict_t* dict = DICT(self);
|
|
601
596
|
dnode_t* node;
|
|
@@ -749,11 +744,7 @@ static void
|
|
|
749
744
|
copy_dict(VALUE src, VALUE dest, dict_comp_t cmp_func, VALUE cmp_proc)
|
|
750
745
|
{
|
|
751
746
|
VALUE temp = rbtree_alloc(CLASS_OF(dest));
|
|
752
|
-
#ifdef HAVE_RB_OBJ_HIDE
|
|
753
747
|
rb_obj_hide(temp);
|
|
754
|
-
#else
|
|
755
|
-
RBASIC(temp)->klass = 0;
|
|
756
|
-
#endif
|
|
757
748
|
DICT(temp)->dict_compare = cmp_func;
|
|
758
749
|
CMP_PROC(temp) = cmp_proc;
|
|
759
750
|
|
|
@@ -765,7 +756,11 @@ copy_dict(VALUE src, VALUE dest, dict_comp_t cmp_func, VALUE cmp_proc)
|
|
|
765
756
|
}
|
|
766
757
|
rbtree_free(RBTREE(temp));
|
|
767
758
|
RBTREE(temp) = NULL;
|
|
759
|
+
#if defined(RUBY_API_VERSION_CODE) && RUBY_API_VERSION_CODE >= 30100
|
|
760
|
+
/* do nothing */
|
|
761
|
+
#else
|
|
768
762
|
rb_gc_force_recycle(temp);
|
|
763
|
+
#endif
|
|
769
764
|
|
|
770
765
|
DICT(dest)->dict_context = RBTREE(dest);
|
|
771
766
|
CMP_PROC(dest) = cmp_proc;
|
|
@@ -892,8 +887,9 @@ typedef struct {
|
|
|
892
887
|
} rbtree_remove_if_arg_t;
|
|
893
888
|
|
|
894
889
|
static VALUE
|
|
895
|
-
rbtree_remove_if_ensure(
|
|
890
|
+
rbtree_remove_if_ensure(VALUE arg_)
|
|
896
891
|
{
|
|
892
|
+
rbtree_remove_if_arg_t* arg = (rbtree_remove_if_arg_t*)arg_;
|
|
897
893
|
dict_t* dict = DICT(arg->self);
|
|
898
894
|
dnode_list_t* list = arg->list;
|
|
899
895
|
|
|
@@ -910,8 +906,9 @@ rbtree_remove_if_ensure(rbtree_remove_if_arg_t* arg)
|
|
|
910
906
|
}
|
|
911
907
|
|
|
912
908
|
static VALUE
|
|
913
|
-
rbtree_remove_if_body(
|
|
909
|
+
rbtree_remove_if_body(VALUE arg_)
|
|
914
910
|
{
|
|
911
|
+
rbtree_remove_if_arg_t* arg = (rbtree_remove_if_arg_t*)arg_;
|
|
915
912
|
VALUE self = arg->self;
|
|
916
913
|
dict_t* dict = DICT(self);
|
|
917
914
|
dnode_t* node;
|
|
@@ -1269,6 +1266,13 @@ to_a_i(dnode_t* node, void* ary)
|
|
|
1269
1266
|
return EACH_NEXT;
|
|
1270
1267
|
}
|
|
1271
1268
|
|
|
1269
|
+
|
|
1270
|
+
#if defined(RUBY_API_VERSION_CODE) && RUBY_API_VERSION_CODE >= 30100
|
|
1271
|
+
# define RBTREE_OBJ_INFECT(obj1, obj2)
|
|
1272
|
+
#else
|
|
1273
|
+
# define RBTREE_OBJ_INFECT(obj1, obj2) OBJ_INFECT(obj1, obj2)
|
|
1274
|
+
#endif
|
|
1275
|
+
|
|
1272
1276
|
/*
|
|
1273
1277
|
*
|
|
1274
1278
|
*/
|
|
@@ -1277,7 +1281,7 @@ rbtree_to_a(VALUE self)
|
|
|
1277
1281
|
{
|
|
1278
1282
|
VALUE ary = rb_ary_new2(dict_count(DICT(self)));
|
|
1279
1283
|
rbtree_for_each(self, to_a_i, (void*)ary);
|
|
1280
|
-
|
|
1284
|
+
RBTREE_OBJ_INFECT(ary, self);
|
|
1281
1285
|
return ary;
|
|
1282
1286
|
}
|
|
1283
1287
|
|
|
@@ -1303,7 +1307,7 @@ rbtree_to_hash(VALUE self)
|
|
|
1303
1307
|
RHASH_SET_IFNONE(hash, IFNONE(self));
|
|
1304
1308
|
if (FL_TEST(self, RBTREE_PROC_DEFAULT))
|
|
1305
1309
|
FL_SET(hash, HASH_PROC_DEFAULT);
|
|
1306
|
-
|
|
1310
|
+
RBTREE_OBJ_INFECT(hash, self);
|
|
1307
1311
|
return hash;
|
|
1308
1312
|
}
|
|
1309
1313
|
|
|
@@ -1338,13 +1342,13 @@ inspect_i(dnode_t* node, void* result_)
|
|
|
1338
1342
|
|
|
1339
1343
|
str = rb_inspect(GET_KEY(node));
|
|
1340
1344
|
rb_str_append(result, str);
|
|
1341
|
-
|
|
1345
|
+
RBTREE_OBJ_INFECT(result, str);
|
|
1342
1346
|
|
|
1343
1347
|
rb_str_cat2(result, "=>");
|
|
1344
1348
|
|
|
1345
1349
|
str = rb_inspect(GET_VAL(node));
|
|
1346
1350
|
rb_str_append(result, str);
|
|
1347
|
-
|
|
1351
|
+
RBTREE_OBJ_INFECT(result, str);
|
|
1348
1352
|
|
|
1349
1353
|
return EACH_NEXT;
|
|
1350
1354
|
}
|
|
@@ -1363,15 +1367,15 @@ inspect_rbtree(VALUE self, VALUE result)
|
|
|
1363
1367
|
str = rb_inspect(IFNONE(self));
|
|
1364
1368
|
rb_str_cat2(result, ", default=");
|
|
1365
1369
|
rb_str_append(result, str);
|
|
1366
|
-
|
|
1370
|
+
RBTREE_OBJ_INFECT(result, str);
|
|
1367
1371
|
|
|
1368
1372
|
str = rb_inspect(CMP_PROC(self));
|
|
1369
1373
|
rb_str_cat2(result, ", cmp_proc=");
|
|
1370
1374
|
rb_str_append(result, str);
|
|
1371
|
-
|
|
1375
|
+
RBTREE_OBJ_INFECT(result, str);
|
|
1372
1376
|
|
|
1373
1377
|
rb_str_cat2(result, ">");
|
|
1374
|
-
|
|
1378
|
+
RBTREE_OBJ_INFECT(result, self);
|
|
1375
1379
|
return result;
|
|
1376
1380
|
}
|
|
1377
1381
|
|
|
@@ -1390,14 +1394,7 @@ rbtree_inspect_recursive(VALUE self, VALUE arg, int recursive)
|
|
|
1390
1394
|
VALUE
|
|
1391
1395
|
rbtree_inspect(VALUE self)
|
|
1392
1396
|
{
|
|
1393
|
-
#ifdef HAVE_RB_EXEC_RECURSIVE
|
|
1394
1397
|
return rb_exec_recursive(rbtree_inspect_recursive, self, Qnil);
|
|
1395
|
-
#else
|
|
1396
|
-
VALUE str = rbtree_begin_inspect(self);
|
|
1397
|
-
if (rb_inspecting_p(self))
|
|
1398
|
-
return rb_str_cat2(str, "...>");
|
|
1399
|
-
return rb_protect_inspect(inspect_rbtree, self, str);
|
|
1400
|
-
#endif
|
|
1401
1398
|
}
|
|
1402
1399
|
|
|
1403
1400
|
/*
|
|
@@ -1462,8 +1459,9 @@ typedef struct {
|
|
|
1462
1459
|
} rbtree_bound_arg_t;
|
|
1463
1460
|
|
|
1464
1461
|
static VALUE
|
|
1465
|
-
rbtree_bound_body(
|
|
1462
|
+
rbtree_bound_body(VALUE arg_)
|
|
1466
1463
|
{
|
|
1464
|
+
rbtree_bound_arg_t* arg = (rbtree_bound_arg_t*)arg_;
|
|
1467
1465
|
VALUE self = arg->self;
|
|
1468
1466
|
dict_t* dict = DICT(self);
|
|
1469
1467
|
dnode_t* lower_node = arg->lower_node;
|
|
@@ -1487,7 +1485,6 @@ rbtree_bound_body(rbtree_bound_arg_t* arg)
|
|
|
1487
1485
|
return result;
|
|
1488
1486
|
}
|
|
1489
1487
|
|
|
1490
|
-
#ifdef HAVE_SIZED_ENUMERATOR
|
|
1491
1488
|
static VALUE
|
|
1492
1489
|
rbtree_bound_size(VALUE self, VALUE args)
|
|
1493
1490
|
{
|
|
@@ -1516,7 +1513,6 @@ rbtree_bound_size(VALUE self, VALUE args)
|
|
|
1516
1513
|
}
|
|
1517
1514
|
return ULONG2NUM(count);
|
|
1518
1515
|
}
|
|
1519
|
-
#endif
|
|
1520
1516
|
|
|
1521
1517
|
/*********************************************************************/
|
|
1522
1518
|
|
|
@@ -1702,10 +1698,9 @@ static ID id_pp;
|
|
|
1702
1698
|
static ID id_text;
|
|
1703
1699
|
|
|
1704
1700
|
static VALUE
|
|
1705
|
-
|
|
1701
|
+
call_group_with_block(VALUE *group_args, VALUE (*blk)(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg)), VALUE data)
|
|
1706
1702
|
{
|
|
1707
|
-
|
|
1708
|
-
return rb_funcall(args[0], id_group, 3, args[1], args[2], args[3]);
|
|
1703
|
+
return rb_block_call(group_args[0], id_group, 3, group_args + 1, blk, data);
|
|
1709
1704
|
}
|
|
1710
1705
|
|
|
1711
1706
|
typedef struct {
|
|
@@ -1714,16 +1709,18 @@ typedef struct {
|
|
|
1714
1709
|
} pp_pair_arg_t;
|
|
1715
1710
|
|
|
1716
1711
|
static VALUE
|
|
1717
|
-
pp_value(
|
|
1712
|
+
pp_value(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
|
1718
1713
|
{
|
|
1714
|
+
pp_pair_arg_t* pair_arg = (pp_pair_arg_t*)arg;
|
|
1719
1715
|
VALUE pp = pair_arg->pp;
|
|
1720
1716
|
rb_funcall(pp, id_breakable, 1, rb_str_new(NULL, 0));
|
|
1721
1717
|
return rb_funcall(pp, id_pp, 1, GET_VAL(pair_arg->node));
|
|
1722
1718
|
}
|
|
1723
1719
|
|
|
1724
1720
|
static VALUE
|
|
1725
|
-
pp_pair(
|
|
1721
|
+
pp_pair(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
|
1726
1722
|
{
|
|
1723
|
+
pp_pair_arg_t* pair_arg = (pp_pair_arg_t*)arg;
|
|
1727
1724
|
VALUE pp = pair_arg->pp;
|
|
1728
1725
|
VALUE group_args[4];
|
|
1729
1726
|
group_args[0] = pp;
|
|
@@ -1733,7 +1730,7 @@ pp_pair(VALUE nil, pp_pair_arg_t* pair_arg)
|
|
|
1733
1730
|
|
|
1734
1731
|
rb_funcall(pp, id_pp, 1, GET_KEY(pair_arg->node));
|
|
1735
1732
|
rb_funcall(pp, id_text, 1, rb_str_new2("=>"));
|
|
1736
|
-
return
|
|
1733
|
+
return call_group_with_block(group_args, pp_value, (VALUE)pair_arg);
|
|
1737
1734
|
}
|
|
1738
1735
|
|
|
1739
1736
|
typedef struct {
|
|
@@ -1762,7 +1759,7 @@ pp_each_pair_i(dnode_t* node, void* each_pair_arg_)
|
|
|
1762
1759
|
pair_arg.pp = each_pair_arg->pp;
|
|
1763
1760
|
pair_arg.node = node;
|
|
1764
1761
|
|
|
1765
|
-
|
|
1762
|
+
call_group_with_block(group_args, pp_pair, (VALUE)&pair_arg);
|
|
1766
1763
|
return EACH_NEXT;
|
|
1767
1764
|
}
|
|
1768
1765
|
|
|
@@ -1772,8 +1769,9 @@ typedef struct {
|
|
|
1772
1769
|
} pp_rbtree_arg_t;
|
|
1773
1770
|
|
|
1774
1771
|
static VALUE
|
|
1775
|
-
pp_each_pair(
|
|
1772
|
+
pp_each_pair(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
|
1776
1773
|
{
|
|
1774
|
+
pp_rbtree_arg_t* rbtree_arg = (pp_rbtree_arg_t*)arg;
|
|
1777
1775
|
pp_each_pair_arg_t each_pair_arg;
|
|
1778
1776
|
each_pair_arg.pp = rbtree_arg->pp;
|
|
1779
1777
|
each_pair_arg.first = 1;
|
|
@@ -1781,8 +1779,9 @@ pp_each_pair(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
|
1781
1779
|
}
|
|
1782
1780
|
|
|
1783
1781
|
static VALUE
|
|
1784
|
-
pp_rbtree(
|
|
1782
|
+
pp_rbtree(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
|
1785
1783
|
{
|
|
1784
|
+
pp_rbtree_arg_t* rbtree_arg = (pp_rbtree_arg_t*)arg;
|
|
1786
1785
|
VALUE pp = rbtree_arg->pp;
|
|
1787
1786
|
VALUE rbtree = rbtree_arg->rbtree;
|
|
1788
1787
|
|
|
@@ -1793,7 +1792,7 @@ pp_rbtree(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
|
1793
1792
|
group_args[3] = rb_str_new2("}");
|
|
1794
1793
|
|
|
1795
1794
|
rb_funcall(pp, id_text, 1, rb_str_new2(": "));
|
|
1796
|
-
|
|
1795
|
+
call_group_with_block(group_args, pp_each_pair, (VALUE)rbtree_arg);
|
|
1797
1796
|
rb_funcall(pp, id_comma_breakable, 0);
|
|
1798
1797
|
rb_funcall(pp, id_text, 1, rb_str_new2("default="));
|
|
1799
1798
|
rb_funcall(pp, id_pp, 1, IFNONE(rbtree));
|
|
@@ -1802,13 +1801,6 @@ pp_rbtree(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
|
1802
1801
|
return rb_funcall(pp, id_pp, 1, CMP_PROC(rbtree));
|
|
1803
1802
|
}
|
|
1804
1803
|
|
|
1805
|
-
static VALUE
|
|
1806
|
-
pp_rbtree_group(VALUE arg_)
|
|
1807
|
-
{
|
|
1808
|
-
pp_rbtree_arg_t* arg = (pp_rbtree_arg_t*)arg_;
|
|
1809
|
-
return rb_funcall(arg->pp, id_object_group, 1, arg->rbtree);
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
1804
|
/*********************************************************************/
|
|
1813
1805
|
|
|
1814
1806
|
/* :nodoc:
|
|
@@ -1820,7 +1812,7 @@ rbtree_pretty_print(VALUE self, VALUE pp)
|
|
|
1820
1812
|
pp_rbtree_arg_t arg;
|
|
1821
1813
|
arg.rbtree = self;
|
|
1822
1814
|
arg.pp = pp;
|
|
1823
|
-
return
|
|
1815
|
+
return rb_block_call(arg.pp, id_object_group, 1, &self, pp_rbtree, (VALUE)&arg);
|
|
1824
1816
|
}
|
|
1825
1817
|
|
|
1826
1818
|
/* :nodoc:
|
|
@@ -1853,11 +1845,7 @@ rbtree_dump(VALUE self, VALUE limit)
|
|
|
1853
1845
|
rb_ary_push(ary, IFNONE(self));
|
|
1854
1846
|
|
|
1855
1847
|
result = rb_marshal_dump(ary, Qnil);
|
|
1856
|
-
#ifdef HAVE_RB_ARY_RESIZE
|
|
1857
1848
|
rb_ary_resize(ary, 0);
|
|
1858
|
-
#else
|
|
1859
|
-
rb_ary_clear(ary);
|
|
1860
|
-
#endif
|
|
1861
1849
|
return result;
|
|
1862
1850
|
}
|
|
1863
1851
|
|
|
@@ -1876,11 +1864,7 @@ rbtree_s_load(VALUE klass, VALUE str)
|
|
|
1876
1864
|
rbtree_aset(rbtree, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i + 1));
|
|
1877
1865
|
IFNONE(rbtree) = RARRAY_AREF(ary, len);
|
|
1878
1866
|
|
|
1879
|
-
#ifdef HAVE_RB_ARY_RESIZE
|
|
1880
1867
|
rb_ary_resize(ary, 0);
|
|
1881
|
-
#else
|
|
1882
|
-
rb_ary_clear(ary);
|
|
1883
|
-
#endif
|
|
1884
1868
|
return rbtree;
|
|
1885
1869
|
}
|
|
1886
1870
|
|
|
@@ -1895,7 +1879,7 @@ rbtree_s_load(VALUE klass, VALUE str)
|
|
|
1895
1879
|
* A sorted associative collection that cannot contain duplicate
|
|
1896
1880
|
* keys. RBTree is a subclass of MultiRBTree.
|
|
1897
1881
|
*/
|
|
1898
|
-
void Init_rbtree()
|
|
1882
|
+
void Init_rbtree(void)
|
|
1899
1883
|
{
|
|
1900
1884
|
MultiRBTree = rb_define_class("MultiRBTree",
|
|
1901
1885
|
#ifdef HAVE_RB_CDATA
|
|
@@ -1967,9 +1951,7 @@ void Init_rbtree()
|
|
|
1967
1951
|
rb_define_method(MultiRBTree, "merge!", rbtree_update, 1);
|
|
1968
1952
|
rb_define_method(MultiRBTree, "merge", rbtree_merge, 1);
|
|
1969
1953
|
rb_define_method(MultiRBTree, "replace", rbtree_initialize_copy, 1);
|
|
1970
|
-
#ifdef HAVE_HASH_FLATTEN
|
|
1971
1954
|
rb_define_method(MultiRBTree, "flatten", rbtree_flatten, -1);
|
|
1972
|
-
#endif
|
|
1973
1955
|
|
|
1974
1956
|
rb_define_method(MultiRBTree, "include?", rbtree_has_key, 1);
|
|
1975
1957
|
rb_define_method(MultiRBTree, "member?", rbtree_has_key, 1);
|