archipelago_rbtree 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/dict.h ADDED
@@ -0,0 +1,123 @@
1
+ /*
2
+ * Dictionary Abstract Data Type
3
+ * Copyright (C) 1997 Kaz Kylheku <kaz@ashi.footprints.net>
4
+ *
5
+ * Free Software License:
6
+ *
7
+ * All rights are reserved by the author, with the following exceptions:
8
+ * Permission is granted to freely reproduce and distribute this software,
9
+ * possibly in exchange for a fee, provided that this copyright notice appears
10
+ * intact. Permission is also granted to adapt this software to produce
11
+ * derivative works, as long as the modified versions carry this copyright
12
+ * notice and additional notices stating that the work has been modified.
13
+ * This source code may be translated into executable form and incorporated
14
+ * into proprietary software; there is no requirement for such software to
15
+ * contain a copyright notice related to this source.
16
+ *
17
+ * $Id: dict.h,v 1.9 2005/10/06 05:16:35 kuma Exp $
18
+ * $Name: $
19
+ */
20
+
21
+ /*
22
+ * Modified for Ruby/RBTree by OZAWA Takuma.
23
+ */
24
+
25
+ #ifndef DICT_H
26
+ #define DICT_H
27
+
28
+ #include <limits.h>
29
+
30
+ /*
31
+ * Blurb for inclusion into C++ translation units
32
+ */
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ typedef unsigned long dictcount_t;
39
+ #define DICTCOUNT_T_MAX ULONG_MAX
40
+
41
+ /*
42
+ * The dictionary is implemented as a red-black tree
43
+ */
44
+
45
+ typedef enum { dnode_red, dnode_black } dnode_color_t;
46
+
47
+ typedef struct dnode_t {
48
+ struct dnode_t *dict_left;
49
+ struct dnode_t *dict_right;
50
+ struct dnode_t *dict_parent;
51
+ dnode_color_t dict_color;
52
+ const void *dict_key;
53
+ void *dict_data;
54
+ } dnode_t;
55
+
56
+ typedef int (*dict_comp_t)(const void *, const void *, void *);
57
+ typedef dnode_t *(*dnode_alloc_t)(void *);
58
+ typedef void (*dnode_free_t)(dnode_t *, void *);
59
+
60
+ typedef int (*dict_value_eql_t)(const void *, const void *);
61
+
62
+ typedef struct dict_t {
63
+ dnode_t dict_nilnode;
64
+ dictcount_t dict_nodecount;
65
+ dict_comp_t dict_compare;
66
+ dnode_alloc_t dict_allocnode;
67
+ dnode_free_t dict_freenode;
68
+ void *dict_context;
69
+ int dict_dupes;
70
+ } dict_t;
71
+
72
+ typedef void (*dnode_process_t)(dict_t *, dnode_t *, void *);
73
+
74
+ typedef struct dict_load_t {
75
+ dict_t *dict_dictptr;
76
+ dnode_t dict_nilnode;
77
+ } dict_load_t;
78
+
79
+ extern dict_t *dict_create(dict_comp_t);
80
+ extern void dict_set_allocator(dict_t *, dnode_alloc_t, dnode_free_t, void *);
81
+ extern void dict_destroy(dict_t *);
82
+ extern void dict_free_nodes(dict_t *);
83
+ extern void dict_free(dict_t *);
84
+ extern dict_t *dict_init(dict_t *, dict_comp_t);
85
+ extern void dict_init_like(dict_t *, const dict_t *);
86
+ extern int dict_verify(dict_t *);
87
+ extern int dict_similar(const dict_t *, const dict_t *);
88
+ extern dnode_t *dict_lookup(dict_t *, const void *);
89
+ extern dnode_t *dict_lower_bound(dict_t *, const void *);
90
+ extern dnode_t *dict_upper_bound(dict_t *, const void *);
91
+ extern int dict_insert(dict_t *, dnode_t *, const void *);
92
+ extern dnode_t *dict_delete(dict_t *, dnode_t *);
93
+ extern int dict_alloc_insert(dict_t *, const void *, void *);
94
+ extern void dict_delete_free(dict_t *, dnode_t *);
95
+ extern dnode_t *dict_first(dict_t *);
96
+ extern dnode_t *dict_last(dict_t *);
97
+ extern dnode_t *dict_next(dict_t *, dnode_t *);
98
+ extern dnode_t *dict_prev(dict_t *, dnode_t *);
99
+ extern dictcount_t dict_count(dict_t *);
100
+ extern int dict_isempty(dict_t *);
101
+ extern int dict_isfull(dict_t *);
102
+ extern int dict_contains(dict_t *, dnode_t *);
103
+ extern void dict_allow_dupes(dict_t *);
104
+ extern int dnode_is_in_a_dict(dnode_t *);
105
+ extern dnode_t *dnode_create(void *);
106
+ extern dnode_t *dnode_init(dnode_t *, void *);
107
+ extern void dnode_destroy(dnode_t *);
108
+ extern void *dnode_get(dnode_t *);
109
+ extern const void *dnode_getkey(dnode_t *);
110
+ extern void dnode_put(dnode_t *, void *);
111
+ extern void dict_process(dict_t *, void *, dnode_process_t);
112
+ extern void dict_load_begin(dict_load_t *, dict_t *);
113
+ extern void dict_load_next(dict_load_t *, dnode_t *, const void *);
114
+ extern void dict_load_end(dict_load_t *);
115
+ extern void dict_merge(dict_t *, dict_t *);
116
+
117
+ int dict_equal(dict_t*, dict_t*, dict_value_eql_t);
118
+
119
+ #ifdef __cplusplus
120
+ }
121
+ #endif
122
+
123
+ #endif
data/ext/extconf.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'mkmf'
2
+
3
+ def print(*args)
4
+ STDOUT.print *args
5
+ STDOUT.flush
6
+ end
7
+
8
+
9
+ $CFLAGS << ' -std=c89 -pedantic -Wall -Wno-long-long'
10
+ $defs << ' -DNDEBUG'
11
+
12
+
13
+ print 'checking for allocation framework... '
14
+ if Object.respond_to?(:allocate)
15
+ print "yes\n"
16
+ $defs << '-DHAVE_OBJECT_ALLOCATE'
17
+ else
18
+ print "no\n"
19
+ end
20
+
21
+ have_func('rb_obj_init_copy')
22
+ have_func('rb_block_proc')
23
+ have_func('rb_yield_values')
24
+ have_func('rb_marshal_dump')
25
+ have_func('rb_marshal_load')
26
+
27
+ print 'checking for inline keyword... '
28
+ inline = ['inline', '__inline', '__inline__', ''].find {|e|
29
+ try_link(<<EOS)
30
+ int main() { return 0; }
31
+ #{e} void foo() {}
32
+ EOS
33
+ }
34
+ print "#{inline}\n"
35
+ $defs << "-Dinline=#{inline}"
36
+
37
+
38
+ create_makefile('archipelago_rbtree')
data/mkmf.log ADDED
@@ -0,0 +1,175 @@
1
+ have_func: checking for rb_obj_init_copy()... -------------------- yes
2
+
3
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
4
+ conftest.c: In function ‘t’:
5
+ conftest.c:3: error: ‘rb_obj_init_copy’ undeclared (first use in this function)
6
+ conftest.c:3: error: (Each undeclared identifier is reported only once
7
+ conftest.c:3: error: for each function it appears in.)
8
+ checked program was:
9
+ /* begin */
10
+ 1: /*top*/
11
+ 2: int main() { return 0; }
12
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_obj_init_copy; return 0; }
13
+ /* end */
14
+
15
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
16
+ conftest.c: In function ‘t’:
17
+ conftest.c:3: warning: implicit declaration of function ‘rb_obj_init_copy’
18
+ /usr/bin/ld: warning multiple definitions of symbol _setregid
19
+ /opt/local/lib/libruby-static.a(process.o) definition of _setregid in section (__TEXT,__text)
20
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
21
+ /usr/bin/ld: warning multiple definitions of symbol _setreuid
22
+ /opt/local/lib/libruby-static.a(process.o) definition of _setreuid in section (__TEXT,__text)
23
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid
24
+ checked program was:
25
+ /* begin */
26
+ 1: /*top*/
27
+ 2: int main() { return 0; }
28
+ 3: int t() { rb_obj_init_copy(); return 0; }
29
+ /* end */
30
+
31
+ --------------------
32
+
33
+ have_func: checking for rb_block_proc()... -------------------- yes
34
+
35
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
36
+ conftest.c: In function ‘t’:
37
+ conftest.c:3: error: ‘rb_block_proc’ undeclared (first use in this function)
38
+ conftest.c:3: error: (Each undeclared identifier is reported only once
39
+ conftest.c:3: error: for each function it appears in.)
40
+ checked program was:
41
+ /* begin */
42
+ 1: /*top*/
43
+ 2: int main() { return 0; }
44
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_block_proc; return 0; }
45
+ /* end */
46
+
47
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
48
+ conftest.c: In function ‘t’:
49
+ conftest.c:3: warning: implicit declaration of function ‘rb_block_proc’
50
+ /usr/bin/ld: warning multiple definitions of symbol _setregid
51
+ /opt/local/lib/libruby-static.a(process.o) definition of _setregid in section (__TEXT,__text)
52
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
53
+ /usr/bin/ld: warning multiple definitions of symbol _setreuid
54
+ /opt/local/lib/libruby-static.a(process.o) definition of _setreuid in section (__TEXT,__text)
55
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid
56
+ checked program was:
57
+ /* begin */
58
+ 1: /*top*/
59
+ 2: int main() { return 0; }
60
+ 3: int t() { rb_block_proc(); return 0; }
61
+ /* end */
62
+
63
+ --------------------
64
+
65
+ have_func: checking for rb_yield_values()... -------------------- yes
66
+
67
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
68
+ conftest.c: In function ‘t’:
69
+ conftest.c:3: error: ‘rb_yield_values’ undeclared (first use in this function)
70
+ conftest.c:3: error: (Each undeclared identifier is reported only once
71
+ conftest.c:3: error: for each function it appears in.)
72
+ checked program was:
73
+ /* begin */
74
+ 1: /*top*/
75
+ 2: int main() { return 0; }
76
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_yield_values; return 0; }
77
+ /* end */
78
+
79
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
80
+ conftest.c: In function ‘t’:
81
+ conftest.c:3: warning: implicit declaration of function ‘rb_yield_values’
82
+ /usr/bin/ld: warning multiple definitions of symbol _setregid
83
+ /opt/local/lib/libruby-static.a(process.o) definition of _setregid in section (__TEXT,__text)
84
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
85
+ /usr/bin/ld: warning multiple definitions of symbol _setreuid
86
+ /opt/local/lib/libruby-static.a(process.o) definition of _setreuid in section (__TEXT,__text)
87
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid
88
+ checked program was:
89
+ /* begin */
90
+ 1: /*top*/
91
+ 2: int main() { return 0; }
92
+ 3: int t() { rb_yield_values(); return 0; }
93
+ /* end */
94
+
95
+ --------------------
96
+
97
+ have_func: checking for rb_marshal_dump()... -------------------- yes
98
+
99
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
100
+ conftest.c: In function ‘t’:
101
+ conftest.c:3: error: ‘rb_marshal_dump’ undeclared (first use in this function)
102
+ conftest.c:3: error: (Each undeclared identifier is reported only once
103
+ conftest.c:3: error: for each function it appears in.)
104
+ checked program was:
105
+ /* begin */
106
+ 1: /*top*/
107
+ 2: int main() { return 0; }
108
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_marshal_dump; return 0; }
109
+ /* end */
110
+
111
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
112
+ conftest.c: In function ‘t’:
113
+ conftest.c:3: warning: implicit declaration of function ‘rb_marshal_dump’
114
+ /usr/bin/ld: warning multiple definitions of symbol _setregid
115
+ /opt/local/lib/libruby-static.a(process.o) definition of _setregid in section (__TEXT,__text)
116
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
117
+ /usr/bin/ld: warning multiple definitions of symbol _setreuid
118
+ /opt/local/lib/libruby-static.a(process.o) definition of _setreuid in section (__TEXT,__text)
119
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid
120
+ checked program was:
121
+ /* begin */
122
+ 1: /*top*/
123
+ 2: int main() { return 0; }
124
+ 3: int t() { rb_marshal_dump(); return 0; }
125
+ /* end */
126
+
127
+ --------------------
128
+
129
+ have_func: checking for rb_marshal_load()... -------------------- yes
130
+
131
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
132
+ conftest.c: In function ‘t’:
133
+ conftest.c:3: error: ‘rb_marshal_load’ undeclared (first use in this function)
134
+ conftest.c:3: error: (Each undeclared identifier is reported only once
135
+ conftest.c:3: error: for each function it appears in.)
136
+ checked program was:
137
+ /* begin */
138
+ 1: /*top*/
139
+ 2: int main() { return 0; }
140
+ 3: int t() { void ((*volatile p)()); p = (void ((*)()))rb_marshal_load; return 0; }
141
+ /* end */
142
+
143
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
144
+ conftest.c: In function ‘t’:
145
+ conftest.c:3: warning: implicit declaration of function ‘rb_marshal_load’
146
+ /usr/bin/ld: warning multiple definitions of symbol _setregid
147
+ /opt/local/lib/libruby-static.a(process.o) definition of _setregid in section (__TEXT,__text)
148
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setregid.So) definition of _setregid
149
+ /usr/bin/ld: warning multiple definitions of symbol _setreuid
150
+ /opt/local/lib/libruby-static.a(process.o) definition of _setreuid in section (__TEXT,__text)
151
+ /usr/lib/gcc/i686-apple-darwin8/4.0.1/../../../libpthread.dylib(setreuid.So) definition of _setreuid
152
+ checked program was:
153
+ /* begin */
154
+ 1: /*top*/
155
+ 2: int main() { return 0; }
156
+ 3: int t() { rb_marshal_load(); return 0; }
157
+ /* end */
158
+
159
+ --------------------
160
+
161
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
162
+ conftest.c:2: error: syntax error before ‘void’
163
+ checked program was:
164
+ /* begin */
165
+ 1: int main() { return 0; }
166
+ 2: inline void foo() {}
167
+ /* end */
168
+
169
+ "gcc -o conftest -I. -I/opt/local/lib/ruby/1.8/i686-darwin8.9.1 -Iext -I/opt/local/include -O2 -fno-common -pipe -fno-common -std=c89 -pedantic -Wall -Wno-long-long conftest.c -L"/opt/local/lib" -L/opt/local/lib -lruby-static -lpthread -ldl -lobjc "
170
+ checked program was:
171
+ /* begin */
172
+ 1: int main() { return 0; }
173
+ 2: __inline void foo() {}
174
+ /* end */
175
+