rbtree 0.4.5 → 0.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README +3 -0
- data/extconf.rb +1 -0
- data/rbtree.c +72 -24
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a5ec1fb39918d82821706cea18cb63b25fd4d20a989579664f7b95774f43881f
|
4
|
+
data.tar.gz: 3795d33cbbf811cdfd7b92664eca4156760c8d3bb36fa28a9854720279c6c1dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3df17e8770de0b0e7396b454905ca5a1d1de24d2dc006de0283a29c9a0805b772442f510dd9ce66bbe590499128d5375da4e61ae7e8396abed455833204af79d
|
7
|
+
data.tar.gz: ba6402624a047e104e2ddb70a37b19f1d01c2ce7b88752f19c9396fd197c8b58c8e3e3daa21974038b1a44676ee2af40c220dfc1fd300ad6796590fecdca5e30
|
data/README
CHANGED
data/extconf.rb
CHANGED
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
|
@@ -134,22 +137,24 @@ static int
|
|
134
137
|
rbtree_cmp(const void* key1, const void* key2, void* context)
|
135
138
|
{
|
136
139
|
VALUE result;
|
137
|
-
if (TYPE(key1) == T_STRING && TYPE(key2) == T_STRING)
|
140
|
+
if (TYPE((VALUE)key1) == T_STRING && TYPE((VALUE)key2) == T_STRING)
|
138
141
|
return rb_str_cmp((VALUE)key1, (VALUE)key2);
|
139
142
|
result = rb_funcall2((VALUE)key1, id_cmp, 1, (VALUE*)&key2);
|
140
143
|
return rb_cmpint(result, (VALUE)key1, (VALUE)key2);
|
141
144
|
}
|
142
145
|
|
143
146
|
static VALUE
|
144
|
-
rbtree_user_cmp_ensure(
|
147
|
+
rbtree_user_cmp_ensure(VALUE arg)
|
145
148
|
{
|
149
|
+
rbtree_t* rbtree = (rbtree_t*)arg;
|
146
150
|
rbtree->iter_lev--;
|
147
151
|
return Qnil;
|
148
152
|
}
|
149
153
|
|
150
154
|
static VALUE
|
151
|
-
rbtree_user_cmp_body(VALUE
|
155
|
+
rbtree_user_cmp_body(VALUE arg)
|
152
156
|
{
|
157
|
+
VALUE *args = (VALUE*)arg;
|
153
158
|
rbtree_t* rbtree = (rbtree_t*)args[2];
|
154
159
|
rbtree->iter_lev++;
|
155
160
|
return rb_funcall2(rbtree->cmp_proc, id_call, 2, args);
|
@@ -323,8 +328,9 @@ typedef struct {
|
|
323
328
|
} rbtree_insert_arg_t;
|
324
329
|
|
325
330
|
static VALUE
|
326
|
-
insert_node_body(
|
331
|
+
insert_node_body(VALUE arg_)
|
327
332
|
{
|
333
|
+
rbtree_insert_arg_t* arg = (rbtree_insert_arg_t*)arg_;
|
328
334
|
dict_t* dict = arg->dict;
|
329
335
|
dnode_t* node = arg->node;
|
330
336
|
|
@@ -341,8 +347,9 @@ insert_node_body(rbtree_insert_arg_t* arg)
|
|
341
347
|
}
|
342
348
|
|
343
349
|
static VALUE
|
344
|
-
insert_node_ensure(
|
350
|
+
insert_node_ensure(VALUE arg_)
|
345
351
|
{
|
352
|
+
rbtree_insert_arg_t* arg = (rbtree_insert_arg_t*)arg_;
|
346
353
|
dict_t* dict = arg->dict;
|
347
354
|
dnode_t* node = arg->node;
|
348
355
|
|
@@ -594,8 +601,9 @@ rbtree_each_ensure(VALUE self)
|
|
594
601
|
}
|
595
602
|
|
596
603
|
static VALUE
|
597
|
-
rbtree_each_body(
|
604
|
+
rbtree_each_body(VALUE arg_)
|
598
605
|
{
|
606
|
+
rbtree_each_arg_t* arg = (rbtree_each_arg_t*)arg_;
|
599
607
|
VALUE self = arg->self;
|
600
608
|
dict_t* dict = DICT(self);
|
601
609
|
dnode_t* node;
|
@@ -765,7 +773,11 @@ copy_dict(VALUE src, VALUE dest, dict_comp_t cmp_func, VALUE cmp_proc)
|
|
765
773
|
}
|
766
774
|
rbtree_free(RBTREE(temp));
|
767
775
|
RBTREE(temp) = NULL;
|
776
|
+
#if defined(RUBY_API_VERSION_CODE) && RUBY_API_VERSION_CODE >= 30100
|
777
|
+
/* do nothing */
|
778
|
+
#else
|
768
779
|
rb_gc_force_recycle(temp);
|
780
|
+
#endif
|
769
781
|
|
770
782
|
DICT(dest)->dict_context = RBTREE(dest);
|
771
783
|
CMP_PROC(dest) = cmp_proc;
|
@@ -892,8 +904,9 @@ typedef struct {
|
|
892
904
|
} rbtree_remove_if_arg_t;
|
893
905
|
|
894
906
|
static VALUE
|
895
|
-
rbtree_remove_if_ensure(
|
907
|
+
rbtree_remove_if_ensure(VALUE arg_)
|
896
908
|
{
|
909
|
+
rbtree_remove_if_arg_t* arg = (rbtree_remove_if_arg_t*)arg_;
|
897
910
|
dict_t* dict = DICT(arg->self);
|
898
911
|
dnode_list_t* list = arg->list;
|
899
912
|
|
@@ -910,8 +923,9 @@ rbtree_remove_if_ensure(rbtree_remove_if_arg_t* arg)
|
|
910
923
|
}
|
911
924
|
|
912
925
|
static VALUE
|
913
|
-
rbtree_remove_if_body(
|
926
|
+
rbtree_remove_if_body(VALUE arg_)
|
914
927
|
{
|
928
|
+
rbtree_remove_if_arg_t* arg = (rbtree_remove_if_arg_t*)arg_;
|
915
929
|
VALUE self = arg->self;
|
916
930
|
dict_t* dict = DICT(self);
|
917
931
|
dnode_t* node;
|
@@ -1269,6 +1283,13 @@ to_a_i(dnode_t* node, void* ary)
|
|
1269
1283
|
return EACH_NEXT;
|
1270
1284
|
}
|
1271
1285
|
|
1286
|
+
|
1287
|
+
#if defined(RUBY_API_VERSION_CODE) && RUBY_API_VERSION_CODE >= 30100
|
1288
|
+
# define RBTREE_OBJ_INFECT(obj1, obj2)
|
1289
|
+
#else
|
1290
|
+
# define RBTREE_OBJ_INFECT(obj1, obj2) OBJ_INFECT(obj1, obj2)
|
1291
|
+
#endif
|
1292
|
+
|
1272
1293
|
/*
|
1273
1294
|
*
|
1274
1295
|
*/
|
@@ -1277,7 +1298,7 @@ rbtree_to_a(VALUE self)
|
|
1277
1298
|
{
|
1278
1299
|
VALUE ary = rb_ary_new2(dict_count(DICT(self)));
|
1279
1300
|
rbtree_for_each(self, to_a_i, (void*)ary);
|
1280
|
-
|
1301
|
+
RBTREE_OBJ_INFECT(ary, self);
|
1281
1302
|
return ary;
|
1282
1303
|
}
|
1283
1304
|
|
@@ -1303,7 +1324,7 @@ rbtree_to_hash(VALUE self)
|
|
1303
1324
|
RHASH_SET_IFNONE(hash, IFNONE(self));
|
1304
1325
|
if (FL_TEST(self, RBTREE_PROC_DEFAULT))
|
1305
1326
|
FL_SET(hash, HASH_PROC_DEFAULT);
|
1306
|
-
|
1327
|
+
RBTREE_OBJ_INFECT(hash, self);
|
1307
1328
|
return hash;
|
1308
1329
|
}
|
1309
1330
|
|
@@ -1338,13 +1359,13 @@ inspect_i(dnode_t* node, void* result_)
|
|
1338
1359
|
|
1339
1360
|
str = rb_inspect(GET_KEY(node));
|
1340
1361
|
rb_str_append(result, str);
|
1341
|
-
|
1362
|
+
RBTREE_OBJ_INFECT(result, str);
|
1342
1363
|
|
1343
1364
|
rb_str_cat2(result, "=>");
|
1344
1365
|
|
1345
1366
|
str = rb_inspect(GET_VAL(node));
|
1346
1367
|
rb_str_append(result, str);
|
1347
|
-
|
1368
|
+
RBTREE_OBJ_INFECT(result, str);
|
1348
1369
|
|
1349
1370
|
return EACH_NEXT;
|
1350
1371
|
}
|
@@ -1363,15 +1384,15 @@ inspect_rbtree(VALUE self, VALUE result)
|
|
1363
1384
|
str = rb_inspect(IFNONE(self));
|
1364
1385
|
rb_str_cat2(result, ", default=");
|
1365
1386
|
rb_str_append(result, str);
|
1366
|
-
|
1387
|
+
RBTREE_OBJ_INFECT(result, str);
|
1367
1388
|
|
1368
1389
|
str = rb_inspect(CMP_PROC(self));
|
1369
1390
|
rb_str_cat2(result, ", cmp_proc=");
|
1370
1391
|
rb_str_append(result, str);
|
1371
|
-
|
1392
|
+
RBTREE_OBJ_INFECT(result, str);
|
1372
1393
|
|
1373
1394
|
rb_str_cat2(result, ">");
|
1374
|
-
|
1395
|
+
RBTREE_OBJ_INFECT(result, self);
|
1375
1396
|
return result;
|
1376
1397
|
}
|
1377
1398
|
|
@@ -1462,8 +1483,9 @@ typedef struct {
|
|
1462
1483
|
} rbtree_bound_arg_t;
|
1463
1484
|
|
1464
1485
|
static VALUE
|
1465
|
-
rbtree_bound_body(
|
1486
|
+
rbtree_bound_body(VALUE arg_)
|
1466
1487
|
{
|
1488
|
+
rbtree_bound_arg_t* arg = (rbtree_bound_arg_t*)arg_;
|
1467
1489
|
VALUE self = arg->self;
|
1468
1490
|
dict_t* dict = DICT(self);
|
1469
1491
|
dnode_t* lower_node = arg->lower_node;
|
@@ -1701,12 +1723,28 @@ static ID id_object_group;
|
|
1701
1723
|
static ID id_pp;
|
1702
1724
|
static ID id_text;
|
1703
1725
|
|
1726
|
+
#if defined(RUBY_VERSION_MAJOR) && RUBY_VERSION_MAJOR == 1 && RUBY_VERSION_MINOR == 8
|
1727
|
+
#define RUBY_1_8
|
1728
|
+
#endif
|
1729
|
+
|
1730
|
+
#ifdef RUBY_1_8
|
1704
1731
|
static VALUE
|
1705
1732
|
pp_group(VALUE args_)
|
1706
1733
|
{
|
1707
1734
|
VALUE* args = (VALUE*)args_;
|
1708
1735
|
return rb_funcall(args[0], id_group, 3, args[1], args[2], args[3]);
|
1709
1736
|
}
|
1737
|
+
#endif
|
1738
|
+
|
1739
|
+
static VALUE
|
1740
|
+
call_group_with_block(VALUE *group_args, VALUE (*blk)(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg)), VALUE data)
|
1741
|
+
{
|
1742
|
+
#ifdef RUBY_1_8
|
1743
|
+
return rb_iterate(pp_group, (VALUE)&group_args, blk, data);
|
1744
|
+
#else
|
1745
|
+
return rb_block_call(group_args[0], id_group, 3, group_args + 1, blk, data);
|
1746
|
+
#endif
|
1747
|
+
}
|
1710
1748
|
|
1711
1749
|
typedef struct {
|
1712
1750
|
VALUE pp;
|
@@ -1714,16 +1752,18 @@ typedef struct {
|
|
1714
1752
|
} pp_pair_arg_t;
|
1715
1753
|
|
1716
1754
|
static VALUE
|
1717
|
-
pp_value(
|
1755
|
+
pp_value(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
1718
1756
|
{
|
1757
|
+
pp_pair_arg_t* pair_arg = (pp_pair_arg_t*)arg;
|
1719
1758
|
VALUE pp = pair_arg->pp;
|
1720
1759
|
rb_funcall(pp, id_breakable, 1, rb_str_new(NULL, 0));
|
1721
1760
|
return rb_funcall(pp, id_pp, 1, GET_VAL(pair_arg->node));
|
1722
1761
|
}
|
1723
1762
|
|
1724
1763
|
static VALUE
|
1725
|
-
pp_pair(
|
1764
|
+
pp_pair(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
1726
1765
|
{
|
1766
|
+
pp_pair_arg_t* pair_arg = (pp_pair_arg_t*)arg;
|
1727
1767
|
VALUE pp = pair_arg->pp;
|
1728
1768
|
VALUE group_args[4];
|
1729
1769
|
group_args[0] = pp;
|
@@ -1733,7 +1773,7 @@ pp_pair(VALUE nil, pp_pair_arg_t* pair_arg)
|
|
1733
1773
|
|
1734
1774
|
rb_funcall(pp, id_pp, 1, GET_KEY(pair_arg->node));
|
1735
1775
|
rb_funcall(pp, id_text, 1, rb_str_new2("=>"));
|
1736
|
-
return
|
1776
|
+
return call_group_with_block(group_args, pp_value, (VALUE)pair_arg);
|
1737
1777
|
}
|
1738
1778
|
|
1739
1779
|
typedef struct {
|
@@ -1762,7 +1802,7 @@ pp_each_pair_i(dnode_t* node, void* each_pair_arg_)
|
|
1762
1802
|
pair_arg.pp = each_pair_arg->pp;
|
1763
1803
|
pair_arg.node = node;
|
1764
1804
|
|
1765
|
-
|
1805
|
+
call_group_with_block(group_args, pp_pair, (VALUE)&pair_arg);
|
1766
1806
|
return EACH_NEXT;
|
1767
1807
|
}
|
1768
1808
|
|
@@ -1772,8 +1812,9 @@ typedef struct {
|
|
1772
1812
|
} pp_rbtree_arg_t;
|
1773
1813
|
|
1774
1814
|
static VALUE
|
1775
|
-
pp_each_pair(
|
1815
|
+
pp_each_pair(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
1776
1816
|
{
|
1817
|
+
pp_rbtree_arg_t* rbtree_arg = (pp_rbtree_arg_t*)arg;
|
1777
1818
|
pp_each_pair_arg_t each_pair_arg;
|
1778
1819
|
each_pair_arg.pp = rbtree_arg->pp;
|
1779
1820
|
each_pair_arg.first = 1;
|
@@ -1781,8 +1822,9 @@ pp_each_pair(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
1781
1822
|
}
|
1782
1823
|
|
1783
1824
|
static VALUE
|
1784
|
-
pp_rbtree(
|
1825
|
+
pp_rbtree(RB_BLOCK_CALL_FUNC_ARGLIST(nil, arg))
|
1785
1826
|
{
|
1827
|
+
pp_rbtree_arg_t* rbtree_arg = (pp_rbtree_arg_t*)arg;
|
1786
1828
|
VALUE pp = rbtree_arg->pp;
|
1787
1829
|
VALUE rbtree = rbtree_arg->rbtree;
|
1788
1830
|
|
@@ -1793,7 +1835,7 @@ pp_rbtree(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
1793
1835
|
group_args[3] = rb_str_new2("}");
|
1794
1836
|
|
1795
1837
|
rb_funcall(pp, id_text, 1, rb_str_new2(": "));
|
1796
|
-
|
1838
|
+
call_group_with_block(group_args, pp_each_pair, (VALUE)rbtree_arg);
|
1797
1839
|
rb_funcall(pp, id_comma_breakable, 0);
|
1798
1840
|
rb_funcall(pp, id_text, 1, rb_str_new2("default="));
|
1799
1841
|
rb_funcall(pp, id_pp, 1, IFNONE(rbtree));
|
@@ -1802,12 +1844,14 @@ pp_rbtree(VALUE nil, pp_rbtree_arg_t* rbtree_arg)
|
|
1802
1844
|
return rb_funcall(pp, id_pp, 1, CMP_PROC(rbtree));
|
1803
1845
|
}
|
1804
1846
|
|
1847
|
+
#ifdef RUBY_1_8
|
1805
1848
|
static VALUE
|
1806
1849
|
pp_rbtree_group(VALUE arg_)
|
1807
1850
|
{
|
1808
1851
|
pp_rbtree_arg_t* arg = (pp_rbtree_arg_t*)arg_;
|
1809
1852
|
return rb_funcall(arg->pp, id_object_group, 1, arg->rbtree);
|
1810
1853
|
}
|
1854
|
+
#endif
|
1811
1855
|
|
1812
1856
|
/*********************************************************************/
|
1813
1857
|
|
@@ -1820,7 +1864,11 @@ rbtree_pretty_print(VALUE self, VALUE pp)
|
|
1820
1864
|
pp_rbtree_arg_t arg;
|
1821
1865
|
arg.rbtree = self;
|
1822
1866
|
arg.pp = pp;
|
1867
|
+
#ifdef RUBY_1_8
|
1823
1868
|
return rb_iterate(pp_rbtree_group, (VALUE)&arg, pp_rbtree, (VALUE)&arg);
|
1869
|
+
#else
|
1870
|
+
return rb_block_call(arg.pp, id_object_group, 1, &self, pp_rbtree, (VALUE)&arg);
|
1871
|
+
#endif
|
1824
1872
|
}
|
1825
1873
|
|
1826
1874
|
/* :nodoc:
|
@@ -1895,7 +1943,7 @@ rbtree_s_load(VALUE klass, VALUE str)
|
|
1895
1943
|
* A sorted associative collection that cannot contain duplicate
|
1896
1944
|
* keys. RBTree is a subclass of MultiRBTree.
|
1897
1945
|
*/
|
1898
|
-
void Init_rbtree()
|
1946
|
+
void Init_rbtree(void)
|
1899
1947
|
{
|
1900
1948
|
MultiRBTree = rb_define_class("MultiRBTree",
|
1901
1949
|
#ifdef HAVE_RB_CDATA
|
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.6
|
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: 2022-
|
11
|
+
date: 2022-12-10 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
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
60
60
|
rubygems_version: 3.4.0.dev
|
61
|
-
signing_key:
|
61
|
+
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: A sorted associative collection.
|
64
64
|
test_files: []
|