sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,314 @@
|
|
1
|
+
/*
|
2
|
+
* File: IntHash.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#ifndef _INTHASH_H
|
8
|
+
#define _INTHASH_H
|
9
|
+
|
10
|
+
#include "common/sedna.h"
|
11
|
+
|
12
|
+
// T - value type
|
13
|
+
// 32-bit integer is hashed by the following template:
|
14
|
+
// 000000...001111................11110000.........0000
|
15
|
+
// \_________/\______________________/\_______________/
|
16
|
+
// middle_significan_bits right_zero_bits
|
17
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
18
|
+
class IntHash
|
19
|
+
{
|
20
|
+
private:
|
21
|
+
|
22
|
+
struct add_cell
|
23
|
+
{
|
24
|
+
int key;
|
25
|
+
T val;
|
26
|
+
add_cell *next;
|
27
|
+
};
|
28
|
+
|
29
|
+
struct cell
|
30
|
+
{
|
31
|
+
int key;
|
32
|
+
T val;
|
33
|
+
add_cell *next;
|
34
|
+
bool is_present;
|
35
|
+
};
|
36
|
+
|
37
|
+
int templ;
|
38
|
+
|
39
|
+
cell tbl[1 << middle_significan_bits];
|
40
|
+
|
41
|
+
public:
|
42
|
+
|
43
|
+
IntHash();
|
44
|
+
~IntHash();
|
45
|
+
|
46
|
+
// functions return 0 if all OK
|
47
|
+
|
48
|
+
int insert(int key, T val);
|
49
|
+
int find(int key, T &val);
|
50
|
+
int remove(int key);
|
51
|
+
int find_remove(int key, T &val);
|
52
|
+
int replace(int key, T &new_val, T &old_val);
|
53
|
+
void clear();
|
54
|
+
};
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
59
|
+
IntHash<T, middle_significan_bits, right_zero_bits>::IntHash()
|
60
|
+
{
|
61
|
+
int k = 32 - middle_significan_bits - right_zero_bits;
|
62
|
+
templ = 0xFFFFFFFF << k >> k >> right_zero_bits << right_zero_bits;
|
63
|
+
|
64
|
+
for (int i = 0; i < (1 << middle_significan_bits); i++)
|
65
|
+
{
|
66
|
+
tbl[i].next = NULL;
|
67
|
+
tbl[i].key = 0;
|
68
|
+
tbl[i].is_present = false;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
|
73
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
74
|
+
IntHash<T, middle_significan_bits, right_zero_bits>::~IntHash()
|
75
|
+
{
|
76
|
+
for (int i = 0; i < (1 << middle_significan_bits); i++)
|
77
|
+
{
|
78
|
+
add_cell * p = tbl[i].next;
|
79
|
+
|
80
|
+
for (; p != NULL; )
|
81
|
+
{
|
82
|
+
add_cell * tmp = p;
|
83
|
+
p = p->next;
|
84
|
+
delete tmp;
|
85
|
+
}
|
86
|
+
|
87
|
+
tbl[i].next = NULL;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
93
|
+
int IntHash<T, middle_significan_bits, right_zero_bits>::insert(int key, T val)
|
94
|
+
{
|
95
|
+
cell &start = tbl[(key & templ) >> right_zero_bits];
|
96
|
+
if (start.is_present)
|
97
|
+
{
|
98
|
+
add_cell * new_cell = se_new add_cell;
|
99
|
+
new_cell->key = key;
|
100
|
+
new_cell->val = val;
|
101
|
+
new_cell->next = start.next;
|
102
|
+
start.next = new_cell;
|
103
|
+
}
|
104
|
+
else
|
105
|
+
{
|
106
|
+
start.key = key;
|
107
|
+
start.val = val;
|
108
|
+
start.next = NULL;
|
109
|
+
start.is_present = true;
|
110
|
+
}
|
111
|
+
|
112
|
+
return 0;
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
117
|
+
int IntHash<T, middle_significan_bits, right_zero_bits>::find(int key, T &val)
|
118
|
+
{
|
119
|
+
cell &start = tbl[(key & templ) >> right_zero_bits];
|
120
|
+
if (start.is_present)
|
121
|
+
{
|
122
|
+
if (start.key == key)
|
123
|
+
{
|
124
|
+
val = start.val;
|
125
|
+
return 0;
|
126
|
+
}
|
127
|
+
|
128
|
+
add_cell * p = start.next;
|
129
|
+
for (; p != NULL; p = p->next)
|
130
|
+
{
|
131
|
+
if (p->key == key)
|
132
|
+
{
|
133
|
+
val = p->val;
|
134
|
+
return 0;
|
135
|
+
}
|
136
|
+
}
|
137
|
+
return 1;
|
138
|
+
}
|
139
|
+
else return 1;
|
140
|
+
|
141
|
+
return 0;
|
142
|
+
}
|
143
|
+
|
144
|
+
|
145
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
146
|
+
int IntHash<T, middle_significan_bits, right_zero_bits>::remove(int key)
|
147
|
+
{
|
148
|
+
cell &start = tbl[(key & templ) >> right_zero_bits];
|
149
|
+
if (start.is_present)
|
150
|
+
{
|
151
|
+
if (start.key == key)
|
152
|
+
{
|
153
|
+
if (start.next == NULL)
|
154
|
+
{
|
155
|
+
start.key = 0;
|
156
|
+
start.is_present = false;
|
157
|
+
}
|
158
|
+
else
|
159
|
+
{
|
160
|
+
start.key = start.next->key;
|
161
|
+
start.val = start.next->val;
|
162
|
+
add_cell *p = start.next;
|
163
|
+
start.next = start.next->next;
|
164
|
+
delete p;
|
165
|
+
start.is_present = true;
|
166
|
+
}
|
167
|
+
return 0;
|
168
|
+
}
|
169
|
+
else
|
170
|
+
{
|
171
|
+
if (start.next == NULL) return 1;
|
172
|
+
|
173
|
+
if (start.next->key == key)
|
174
|
+
{
|
175
|
+
add_cell * p = start.next;
|
176
|
+
start.next = start.next->next;
|
177
|
+
delete p;
|
178
|
+
return 0;
|
179
|
+
}
|
180
|
+
|
181
|
+
add_cell * pred = start.next;
|
182
|
+
add_cell * cur = start.next->next;
|
183
|
+
|
184
|
+
for (; cur != NULL; cur = cur->next, pred = pred->next)
|
185
|
+
{
|
186
|
+
if (cur->key == key)
|
187
|
+
{
|
188
|
+
pred->next = cur->next;
|
189
|
+
delete cur;
|
190
|
+
return 0;
|
191
|
+
}
|
192
|
+
}
|
193
|
+
return 1;
|
194
|
+
|
195
|
+
}
|
196
|
+
}
|
197
|
+
else return 1;
|
198
|
+
|
199
|
+
return 0;
|
200
|
+
}
|
201
|
+
|
202
|
+
|
203
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
204
|
+
int IntHash<T, middle_significan_bits, right_zero_bits>::find_remove(int key, T &val)
|
205
|
+
{
|
206
|
+
cell &start = tbl[(key & templ) >> right_zero_bits];
|
207
|
+
if (start.is_present)
|
208
|
+
{
|
209
|
+
if (start.key == key)
|
210
|
+
{
|
211
|
+
if (start.next == NULL)
|
212
|
+
{
|
213
|
+
val = start.val;
|
214
|
+
start.key = 0;
|
215
|
+
start.is_present = false;
|
216
|
+
}
|
217
|
+
else
|
218
|
+
{
|
219
|
+
val = start.val;
|
220
|
+
start.key = start.next->key;
|
221
|
+
start.val = start.next->val;
|
222
|
+
add_cell *p = start.next;
|
223
|
+
start.next = start.next->next;
|
224
|
+
delete p;
|
225
|
+
start.is_present = true;
|
226
|
+
}
|
227
|
+
return 0;
|
228
|
+
}
|
229
|
+
else
|
230
|
+
{
|
231
|
+
if (start.next == NULL) return 1;
|
232
|
+
|
233
|
+
if (start.next->key == key)
|
234
|
+
{
|
235
|
+
val = start.next->val;
|
236
|
+
add_cell * p = start.next;
|
237
|
+
start.next = start.next->next;
|
238
|
+
delete p;
|
239
|
+
return 0;
|
240
|
+
}
|
241
|
+
|
242
|
+
add_cell * pred = start.next;
|
243
|
+
add_cell * cur = start.next->next;
|
244
|
+
|
245
|
+
for (; cur != NULL; cur = cur->next, pred = pred->next)
|
246
|
+
{
|
247
|
+
if (cur->key == key)
|
248
|
+
{
|
249
|
+
val = cur->val;
|
250
|
+
pred->next = cur->next;
|
251
|
+
delete cur;
|
252
|
+
return 0;
|
253
|
+
}
|
254
|
+
}
|
255
|
+
return 1;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
else return 1;
|
259
|
+
|
260
|
+
return 0;
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
265
|
+
int IntHash<T, middle_significan_bits, right_zero_bits>::replace(int key, T &new_val, T &old_val)
|
266
|
+
{
|
267
|
+
cell &start = tbl[(key & templ) >> right_zero_bits];
|
268
|
+
if (start.is_present)
|
269
|
+
{
|
270
|
+
if (start.key == key)
|
271
|
+
{
|
272
|
+
old_val = start.val;
|
273
|
+
start.val = new_val;
|
274
|
+
return 0;
|
275
|
+
}
|
276
|
+
|
277
|
+
add_cell * p = start.next;
|
278
|
+
for (; p != NULL; p = p->next)
|
279
|
+
{
|
280
|
+
if (p->key == key)
|
281
|
+
{
|
282
|
+
old_val = p->val;
|
283
|
+
p->val = new_val;
|
284
|
+
return 0;
|
285
|
+
}
|
286
|
+
}
|
287
|
+
return 1;
|
288
|
+
}
|
289
|
+
else return 1;
|
290
|
+
|
291
|
+
return 0;
|
292
|
+
}
|
293
|
+
|
294
|
+
template <class T, int middle_significan_bits, int right_zero_bits>
|
295
|
+
void IntHash<T, middle_significan_bits, right_zero_bits>::clear()
|
296
|
+
{
|
297
|
+
for (int i = 0; i < (1 << middle_significan_bits); i++)
|
298
|
+
{
|
299
|
+
add_cell *cur = tbl[i].next, *tmp = NULL;
|
300
|
+
while (cur)
|
301
|
+
{
|
302
|
+
tmp = cur;
|
303
|
+
cur = cur->next;
|
304
|
+
delete tmp;
|
305
|
+
}
|
306
|
+
|
307
|
+
tbl[i].next = NULL;
|
308
|
+
tbl[i].key = 0;
|
309
|
+
tbl[i].is_present = false;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
|
313
|
+
#endif
|
314
|
+
|
@@ -0,0 +1,224 @@
|
|
1
|
+
/*
|
2
|
+
* File: IntList.h
|
3
|
+
* Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
|
7
|
+
#ifndef _INTLIST_H
|
8
|
+
#define _INTLIST_H
|
9
|
+
|
10
|
+
#include "common/sedna.h"
|
11
|
+
#include "common/IntHash.h"
|
12
|
+
|
13
|
+
|
14
|
+
// middle_significan_bits, right_zero_bits - parameters of HashTable
|
15
|
+
template <int middle_significan_bits, int right_zero_bits>
|
16
|
+
class IntList
|
17
|
+
{
|
18
|
+
private:
|
19
|
+
|
20
|
+
struct elem
|
21
|
+
{
|
22
|
+
int val;
|
23
|
+
elem *next;
|
24
|
+
elem *pred;
|
25
|
+
};
|
26
|
+
|
27
|
+
elem * start;
|
28
|
+
elem * last;
|
29
|
+
int num;
|
30
|
+
|
31
|
+
IntHash<elem*, middle_significan_bits, right_zero_bits> tbl;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
class ilit
|
36
|
+
{
|
37
|
+
private:
|
38
|
+
elem *p;
|
39
|
+
|
40
|
+
ilit(elem *_p_) : p(_p_) {}
|
41
|
+
|
42
|
+
public:
|
43
|
+
static ilit begin(IntList *_lst_) { return ilit(_lst_->start); }
|
44
|
+
static ilit end(IntList *_lst_) { return ilit(NULL); }
|
45
|
+
|
46
|
+
ilit() : p(NULL) {}
|
47
|
+
ilit(const ilit& x) : p(x.p) {}
|
48
|
+
ilit& operator=(const ilit &x) { p = x.p; return *this; }
|
49
|
+
|
50
|
+
bool operator==(const ilit &x) { return p == x.p; }
|
51
|
+
bool operator!=(const ilit &x) { return !operator==(x); }
|
52
|
+
|
53
|
+
ilit &operator++() { if (p) p = p->next; return *this; }
|
54
|
+
const int &operator*() { return p->val; }
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
public:
|
59
|
+
|
60
|
+
friend class ilit;
|
61
|
+
typedef ilit iterator;
|
62
|
+
|
63
|
+
IntList();
|
64
|
+
~IntList();
|
65
|
+
|
66
|
+
int size() { return num; }
|
67
|
+
|
68
|
+
// functions return 0 if all OK
|
69
|
+
|
70
|
+
int push (int /*in*/ val);
|
71
|
+
int pop (int& /*out*/ val);
|
72
|
+
int find (int /*in*/ val);
|
73
|
+
int find_remove(int /*in*/ val);
|
74
|
+
void clear ();
|
75
|
+
|
76
|
+
iterator begin() { return ilit::begin(this); }
|
77
|
+
iterator end() { return ilit::end(this); }
|
78
|
+
};
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
template <int middle_significan_bits, int right_zero_bits>
|
83
|
+
IntList<middle_significan_bits, right_zero_bits>::IntList()
|
84
|
+
{
|
85
|
+
num = 0;
|
86
|
+
start = NULL;
|
87
|
+
last = NULL;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
template <int middle_significan_bits, int right_zero_bits>
|
92
|
+
IntList<middle_significan_bits, right_zero_bits>::~IntList()
|
93
|
+
{
|
94
|
+
elem * p = start;
|
95
|
+
for (; p != NULL; )
|
96
|
+
{
|
97
|
+
elem * tmp = p;
|
98
|
+
p = p->next;
|
99
|
+
delete tmp;
|
100
|
+
}
|
101
|
+
|
102
|
+
start = NULL;
|
103
|
+
last = NULL;
|
104
|
+
num = 0;
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
template <int middle_significan_bits, int right_zero_bits>
|
109
|
+
int IntList<middle_significan_bits, right_zero_bits>::push(int /*in*/ val)
|
110
|
+
{
|
111
|
+
elem * tmp = se_new elem;
|
112
|
+
tmp->val = val;
|
113
|
+
tmp->pred = NULL;
|
114
|
+
num++;
|
115
|
+
tbl.insert(val, tmp);
|
116
|
+
|
117
|
+
if (start == NULL)
|
118
|
+
{
|
119
|
+
tmp->next = NULL;
|
120
|
+
start = last = tmp;
|
121
|
+
}
|
122
|
+
else
|
123
|
+
{
|
124
|
+
tmp->next = start;
|
125
|
+
start->pred = tmp;
|
126
|
+
start = tmp;
|
127
|
+
}
|
128
|
+
|
129
|
+
return 0;
|
130
|
+
}
|
131
|
+
|
132
|
+
|
133
|
+
template <int middle_significan_bits, int right_zero_bits>
|
134
|
+
int IntList<middle_significan_bits, right_zero_bits>::pop(int& /*out*/ val)
|
135
|
+
{
|
136
|
+
if (last == NULL) return 1;
|
137
|
+
|
138
|
+
val = last->val;
|
139
|
+
num--;
|
140
|
+
tbl.remove(val);
|
141
|
+
|
142
|
+
if (start == last)
|
143
|
+
{
|
144
|
+
delete last;
|
145
|
+
start = last = NULL;
|
146
|
+
}
|
147
|
+
else
|
148
|
+
{
|
149
|
+
last = last->pred;
|
150
|
+
delete (last->next);
|
151
|
+
last->next = NULL;
|
152
|
+
}
|
153
|
+
|
154
|
+
return 0;
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
template <int middle_significan_bits, int right_zero_bits>
|
159
|
+
int IntList<middle_significan_bits, right_zero_bits>::find(int /*in*/ val)
|
160
|
+
{
|
161
|
+
elem * tmp = NULL;
|
162
|
+
|
163
|
+
return tbl.find(val, tmp);
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
template <int middle_significan_bits, int right_zero_bits>
|
168
|
+
int IntList<middle_significan_bits, right_zero_bits>::find_remove(int /*in*/ val)
|
169
|
+
{
|
170
|
+
elem * tmp = NULL;
|
171
|
+
|
172
|
+
if (tbl.find_remove(val, tmp) == 0)
|
173
|
+
{
|
174
|
+
num--;
|
175
|
+
|
176
|
+
if (tmp->next == NULL && tmp->pred == NULL) // the only elem in the list
|
177
|
+
{
|
178
|
+
start = last = NULL;
|
179
|
+
}
|
180
|
+
else if (tmp->next == NULL) // the last elem in the list
|
181
|
+
{
|
182
|
+
last = tmp->pred;
|
183
|
+
last->next = NULL;
|
184
|
+
}
|
185
|
+
else if (tmp->pred == NULL) // the first elem in the list
|
186
|
+
{
|
187
|
+
start = tmp->next;
|
188
|
+
start->pred = NULL;
|
189
|
+
}
|
190
|
+
else
|
191
|
+
{
|
192
|
+
tmp->pred->next = tmp->next;
|
193
|
+
tmp->next->pred = tmp->pred;
|
194
|
+
}
|
195
|
+
|
196
|
+
delete tmp;
|
197
|
+
return 0;
|
198
|
+
}
|
199
|
+
|
200
|
+
return 1;
|
201
|
+
}
|
202
|
+
|
203
|
+
template <int middle_significan_bits, int right_zero_bits>
|
204
|
+
void IntList<middle_significan_bits, right_zero_bits>::clear()
|
205
|
+
{
|
206
|
+
elem *cur = start, *tmp = NULL;
|
207
|
+
while (tmp)
|
208
|
+
{
|
209
|
+
tmp = cur;
|
210
|
+
cur = cur->next;
|
211
|
+
delete tmp;
|
212
|
+
}
|
213
|
+
|
214
|
+
tbl.clear();
|
215
|
+
|
216
|
+
num = 0;
|
217
|
+
start = NULL;
|
218
|
+
last = NULL;
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
#endif
|
224
|
+
|