sedna 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. data/{CHANGES → CHANGES.rdoc} +9 -0
  2. data/{README → README.rdoc} +23 -25
  3. data/Rakefile +32 -9
  4. data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
  5. data/ext/{sedna.c → sedna/sedna.c} +48 -40
  6. data/test/sedna_test.rb +9 -9
  7. data/vendor/sedna/AUTHORS +18 -0
  8. data/vendor/sedna/COPYRIGHT +90 -0
  9. data/vendor/sedna/LICENSE +202 -0
  10. data/vendor/sedna/Makefile.include +423 -0
  11. data/vendor/sedna/Makefile.platform +31 -0
  12. data/vendor/sedna/depend.sed +48 -0
  13. data/vendor/sedna/driver/c/Makefile +98 -0
  14. data/vendor/sedna/driver/c/libsedna.c +1998 -0
  15. data/vendor/sedna/driver/c/libsedna.h +199 -0
  16. data/vendor/sedna/driver/c/sednamt.def +21 -0
  17. data/vendor/sedna/driver/c/sp_defs.h +186 -0
  18. data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
  19. data/vendor/sedna/kernel/common/IntHash.h +314 -0
  20. data/vendor/sedna/kernel/common/IntList.h +224 -0
  21. data/vendor/sedna/kernel/common/Makefile +30 -0
  22. data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
  23. data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
  24. data/vendor/sedna/kernel/common/XptrHash.h +435 -0
  25. data/vendor/sedna/kernel/common/argtable.c +972 -0
  26. data/vendor/sedna/kernel/common/argtable.h +896 -0
  27. data/vendor/sedna/kernel/common/base.cpp +339 -0
  28. data/vendor/sedna/kernel/common/base.h +226 -0
  29. data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
  30. data/vendor/sedna/kernel/common/bit_set.h +55 -0
  31. data/vendor/sedna/kernel/common/commutil.h +67 -0
  32. data/vendor/sedna/kernel/common/config.h +62 -0
  33. data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
  34. data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
  35. data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
  36. data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
  37. data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
  38. data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
  39. data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
  40. data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
  41. data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
  42. data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
  43. data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
  44. data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
  45. data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
  46. data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
  47. data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
  48. data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
  49. data/vendor/sedna/kernel/common/gmm.cpp +192 -0
  50. data/vendor/sedna/kernel/common/gmm.h +29 -0
  51. data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
  52. data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
  53. data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
  54. data/vendor/sedna/kernel/common/lm_base.h +90 -0
  55. data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
  56. data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
  57. data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
  58. data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
  59. data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
  60. data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
  61. data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
  62. data/vendor/sedna/kernel/common/pping.cpp +672 -0
  63. data/vendor/sedna/kernel/common/pping.h +119 -0
  64. data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
  65. data/vendor/sedna/kernel/common/rcv_test.h +19 -0
  66. data/vendor/sedna/kernel/common/sedna.c +128 -0
  67. data/vendor/sedna/kernel/common/sedna.h +49 -0
  68. data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
  69. data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
  70. data/vendor/sedna/kernel/common/sp.c +93 -0
  71. data/vendor/sedna/kernel/common/sp.h +36 -0
  72. data/vendor/sedna/kernel/common/st/Makefile +20 -0
  73. data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
  74. data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
  75. data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
  76. data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
  77. data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
  78. data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
  79. data/vendor/sedna/kernel/common/tr_debug.h +22 -0
  80. data/vendor/sedna/kernel/common/u/Makefile +14 -0
  81. data/vendor/sedna/kernel/common/u/u.c +268 -0
  82. data/vendor/sedna/kernel/common/u/u.h +715 -0
  83. data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
  84. data/vendor/sedna/kernel/common/u/udl.h +31 -0
  85. data/vendor/sedna/kernel/common/u/uevent.c +406 -0
  86. data/vendor/sedna/kernel/common/u/uevent.h +71 -0
  87. data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
  88. data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
  89. data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
  90. data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
  91. data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
  92. data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
  93. data/vendor/sedna/kernel/common/u/ummap.h +60 -0
  94. data/vendor/sedna/kernel/common/u/umutex.c +145 -0
  95. data/vendor/sedna/kernel/common/u/umutex.h +65 -0
  96. data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
  97. data/vendor/sedna/kernel/common/u/upipe.h +74 -0
  98. data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
  99. data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
  100. data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
  101. data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
  102. data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
  103. data/vendor/sedna/kernel/common/u/usem.c +891 -0
  104. data/vendor/sedna/kernel/common/u/usem.h +83 -0
  105. data/vendor/sedna/kernel/common/u/ushm.c +222 -0
  106. data/vendor/sedna/kernel/common/u/ushm.h +46 -0
  107. data/vendor/sedna/kernel/common/u/usocket.c +541 -0
  108. data/vendor/sedna/kernel/common/u/usocket.h +118 -0
  109. data/vendor/sedna/kernel/common/u/usystem.c +57 -0
  110. data/vendor/sedna/kernel/common/u/usystem.h +46 -0
  111. data/vendor/sedna/kernel/common/u/uthread.c +259 -0
  112. data/vendor/sedna/kernel/common/u/uthread.h +95 -0
  113. data/vendor/sedna/kernel/common/u/utime.c +65 -0
  114. data/vendor/sedna/kernel/common/u/utime.h +40 -0
  115. data/vendor/sedna/kernel/common/u/uutils.c +142 -0
  116. data/vendor/sedna/kernel/common/u/uutils.h +65 -0
  117. data/vendor/sedna/kernel/common/ugc.cpp +156 -0
  118. data/vendor/sedna/kernel/common/ugc.h +15 -0
  119. data/vendor/sedna/kernel/common/utils.cpp +156 -0
  120. data/vendor/sedna/kernel/common/utils.h +133 -0
  121. data/vendor/sedna/kernel/common/version.c +16 -0
  122. data/vendor/sedna/kernel/common/version.h +21 -0
  123. data/vendor/sedna/kernel/common/wustructures.h +18 -0
  124. data/vendor/sedna/kernel/common/wutypes.h +34 -0
  125. data/vendor/sedna/kernel/common/xptr.cpp +17 -0
  126. data/vendor/sedna/kernel/common/xptr.h +211 -0
  127. data/vendor/sedna/ver +1 -0
  128. metadata +142 -14
@@ -0,0 +1,142 @@
1
+ /*
2
+ * File: SSMMsg.h
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #ifndef __SSMMsg_H
8
+ #define __SSMMsg_H
9
+
10
+ // SSMMsg stands for Simple Shared Memory Messages Client/Server Architecture
11
+
12
+ #include <string>
13
+
14
+ #include "common/sedna.h"
15
+
16
+ #include "common/u/usem.h"
17
+ #include "common/u/uthread.h"
18
+ #include "common/u/ushm.h"
19
+
20
+ #define SSMMSG_DEFAULT_TIMEOUT 10000
21
+
22
+
23
+
24
+ // function that serves client msg on the server side
25
+ // it has only arg - addres of block with input data; output data must be
26
+ // written at the same block
27
+ typedef int (*process_msg_func)(void *);
28
+
29
+ class SSMMsg;
30
+
31
+ struct SSMMsg_server_thread_param
32
+ {
33
+ process_msg_func func;
34
+ SSMMsg *ssmmsg;
35
+ int i;
36
+ };
37
+
38
+
39
+ class SSMMsg
40
+ {
41
+ friend U_THREAD_PROC(SSMMsg_server_proc, arg);
42
+
43
+ public:
44
+ // type mode for SSMMsg object
45
+ enum mode {Server, Client};
46
+
47
+ private:
48
+ mode m;
49
+ int msg_size;
50
+ int servers_amount;
51
+
52
+ int real_block_size;
53
+ int shared_memory_size;
54
+ int *waiting;
55
+ int *slot;
56
+ int *process_messages; // is server accept messages (1 - accept, 0 - don't accept)
57
+ int *busy_servers_amount; // amount of the busy servers
58
+ void *shar_mem;
59
+ void *buf_addr;
60
+ void *sysinf_addr;
61
+ int sems_num;
62
+
63
+ char g_names__buf__ [256];
64
+
65
+ global_name g_name_shmem;
66
+ global_name g_name_sems;
67
+
68
+
69
+ SSMMsg_server_thread_param *server_param;
70
+
71
+ unsigned int millisec;
72
+
73
+
74
+ UTHANDLE *thread_handles;
75
+ UShMem sh_mem;
76
+ USemaphoreArr sems;
77
+ /*
78
+ Semaphore array sems consists of the following semaphores:
79
+ semaphore initial value
80
+ ----------------------------------
81
+ sem_clients 0
82
+ sem_servers 0
83
+ sem_mutex 1
84
+
85
+ sem_pact 1
86
+ sem_pact_written 0
87
+ sem_pact_read 0
88
+
89
+ sem_data_written[] 0
90
+ sem_data_processed[] 0
91
+ sem_data_read[] 0
92
+ */
93
+
94
+ bool shutdown_server_proc;
95
+
96
+ public:
97
+
98
+ // initializing SSMMsg object
99
+ // constructor has four parameters:
100
+ // m - mode, in which object should work
101
+ // msg_size - size for memory region that will store intermediate data (size
102
+ // must be specified in bytes, but notice that it will be round up
103
+ // to page size (4Kb on x86))
104
+ // shared_memory_name - name of shared memory region (unique name in the
105
+ // system)
106
+ // servers_amount - amount of server threads
107
+ // msg_size, shared_memory_name, servers_amount must be the same at the
108
+ // server side and at all clients (system doesn't control it, so be
109
+ // careful)
110
+ SSMMsg(mode _m_,
111
+ int _msg_size_,
112
+ global_name _g_name_,
113
+ int _servers_amount_,
114
+ unsigned int _millisec_ = SSMMSG_DEFAULT_TIMEOUT);
115
+
116
+
117
+ // for all functions below assumed that they return 0 as success and 1 otherwise
118
+
119
+ // init object (call it before using object)
120
+ int init();
121
+
122
+ // shutdown object (call it to free resources)
123
+ int shutdown();
124
+
125
+ // send msg to server and wait for answer (this is blocking operation)
126
+ // buf contains data sending to server and it will contains result if function
127
+ // completes successfully (assumes that size of buf is msg_size)
128
+ int send_msg(void * buf);
129
+
130
+ // starts serving clients
131
+ // it has only one arg - a function that processing msg
132
+ int serve_clients(process_msg_func func);
133
+
134
+ // stops accept new messages and wait until all processing messages finish
135
+ int stop_serve_clients();
136
+
137
+ static void ipc_cleanup(global_name name);
138
+ };
139
+
140
+
141
+ #endif
142
+
@@ -0,0 +1,435 @@
1
+ /*
2
+ * File: XptrHash.h
3
+ * Copyright (C) 2004 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
4
+ */
5
+
6
+
7
+ #ifndef _XPTRHASH_H
8
+ #define _XPTRHASH_H
9
+
10
+ #include "common/sedna.h"
11
+ #include "common/xptr.h"
12
+
13
+ // T - value type
14
+ // 32-bit part of xptr is hashed by the following template:
15
+ // 000000...001111................11110000.........0000
16
+ // \_________/\______________________/\_______________/
17
+ // middle_significan_bits right_zero_bits
18
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
19
+ class XptrHash
20
+ {
21
+ private:
22
+
23
+ struct add_cell
24
+ {
25
+ xptr key;
26
+ T val;
27
+ add_cell *next;
28
+ };
29
+
30
+ struct cell
31
+ {
32
+ xptr key;
33
+ T val;
34
+ add_cell *next;
35
+ bool is_present;
36
+ };
37
+
38
+ __uint32 templ;
39
+
40
+ typedef cell t_tbl[1 << middle_significan_bits];
41
+
42
+ t_tbl tbl;
43
+ int num;
44
+
45
+
46
+
47
+ class xhit
48
+ {
49
+ private:
50
+ int pos;
51
+ add_cell *p;
52
+ XptrHash *hash;
53
+
54
+ xhit &next()
55
+ {
56
+ bool flag = true;
57
+ if (p != NULL)
58
+ {
59
+ p = p->next;
60
+ if (p == NULL) flag = false;
61
+ }
62
+
63
+ if (p == NULL)
64
+ {
65
+ if (flag && hash->tbl[pos].next != NULL)
66
+ p = hash->tbl[pos].next;
67
+ else
68
+ while (++pos < (1 << middle_significan_bits))
69
+ if (hash->tbl[pos].is_present) break;
70
+ }
71
+
72
+ return *this;
73
+ }
74
+
75
+ xhit(int _pos_, add_cell *_p_, XptrHash *_hash_) : pos(_pos_), p(_p_), hash(_hash_) {}
76
+
77
+ public:
78
+ static xhit begin(XptrHash *_hash_) { xhit x(0, NULL, _hash_); return _hash_->tbl[0].is_present ? x : x.next(); }
79
+ static xhit end(XptrHash *_hash_) { return xhit(1 << middle_significan_bits, NULL, _hash_); }
80
+
81
+ xhit() : pos(0), p(NULL), hash(NULL) {}
82
+ xhit(const xhit& x) : pos(x.pos), p(x.p), hash(x.hash) {}
83
+ xhit& operator=(const xhit &x) { pos = x.pos; p = x.p; hash = x.hash; return *this; }
84
+
85
+ bool operator==(const xhit &x) { return hash == x.hash && ((p == x.p && p != NULL) || (p == x.p && p == NULL && pos == x.pos)); }
86
+ bool operator!=(const xhit &x) { return !operator==(x); }
87
+
88
+ const xptr &getKey()
89
+ {
90
+ if (p == NULL)
91
+ {
92
+ if (pos >= (1 << middle_significan_bits))
93
+ throw SYSTEM_EXCEPTION("Out of bounds");
94
+ else
95
+ return hash->tbl[pos].key;
96
+ }
97
+ else
98
+ return p->key;
99
+ }
100
+
101
+ xhit &operator++() { return next(); }
102
+ const T &operator*()
103
+ {
104
+ if (p == NULL)
105
+ {
106
+ if (pos >= (1 << middle_significan_bits)) throw SYSTEM_EXCEPTION("Out of bounds");
107
+ else return hash->tbl[pos].val;
108
+ }
109
+ else return p->val;
110
+ }
111
+ };
112
+
113
+ public:
114
+
115
+ friend class xhit;
116
+
117
+ typedef xhit iterator;
118
+
119
+ XptrHash();
120
+ ~XptrHash();
121
+
122
+ // functions return 0 if all OK
123
+
124
+ int insert(xptr key, T val);
125
+ int find(xptr key, T &val);
126
+ int remove(xptr key);
127
+ int find_remove(xptr key, T &val);
128
+ int replace(xptr key, const T &new_val, T &old_val);
129
+ void clear();
130
+
131
+ size_t size() const { return (size_t)num; }
132
+
133
+ iterator begin() { return xhit::begin(this); }
134
+ iterator end() { return xhit::end(this); }
135
+ };
136
+
137
+
138
+
139
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
140
+ XptrHash<T, middle_significan_bits, right_zero_bits>::XptrHash()
141
+ {
142
+ __uint32 k = (__uint32)32 - middle_significan_bits - right_zero_bits;
143
+ templ = (__uint32)0xFFFFFFFF << k >> k >> right_zero_bits << right_zero_bits;
144
+
145
+ for (__uint32 i = 0; i < ((__uint32)1 << middle_significan_bits); i++)
146
+ {
147
+ tbl[i].next = NULL;
148
+ tbl[i].key.clear();
149
+ tbl[i].is_present = false;
150
+ }
151
+
152
+ num = 0;
153
+ }
154
+
155
+
156
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
157
+ XptrHash<T, middle_significan_bits, right_zero_bits>::~XptrHash()
158
+ {
159
+ clear();
160
+ }
161
+
162
+ /*
163
+ Multiple entries with the same key may exist!!!
164
+ */
165
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
166
+ int XptrHash<T, middle_significan_bits, right_zero_bits>::insert(xptr key, T val)
167
+ {
168
+ // T val1;
169
+ // if (find(key, val1) == 0) throw USER_ENV_EXCEPTION("xxx", false);
170
+ cell &start = tbl[((__uint32)(XADDR(key)) & templ) >> right_zero_bits];
171
+ if (start.is_present)
172
+ {
173
+ add_cell * new_cell = se_new add_cell;
174
+ new_cell->key = key;
175
+ new_cell->val = val;
176
+ new_cell->next = start.next;
177
+ start.next = new_cell;
178
+ }
179
+ else
180
+ {
181
+ start.key = key;
182
+ start.val = val;
183
+ start.next = NULL;
184
+ start.is_present = true;
185
+ }
186
+
187
+ num++;
188
+
189
+ return 0;
190
+ }
191
+
192
+
193
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
194
+ int XptrHash<T, middle_significan_bits, right_zero_bits>::find(xptr key, T &val)
195
+ {
196
+ cell &start = tbl[((__uint32)(XADDR(key)) & templ) >> right_zero_bits];
197
+ if (start.is_present)
198
+ {
199
+ if (start.key == key)
200
+ {
201
+ val = start.val;
202
+ return 0;
203
+ }
204
+
205
+ add_cell * p = start.next;
206
+ for (; p != NULL; p = p->next)
207
+ {
208
+ if (p->key == key)
209
+ {
210
+ val = p->val;
211
+ return 0;
212
+ }
213
+ }
214
+ return 1;
215
+ }
216
+ else return 1;
217
+
218
+ return 0;
219
+ }
220
+
221
+
222
+ /*
223
+ Remove from XPtrHash invalidates all iterators!
224
+ Consider the following standard example:
225
+
226
+ Container container;
227
+ for (Container::iterator it=container.begin(); it!=container.end(); false)
228
+ {
229
+ Container::iterator temp=it;
230
+ ++it; // (1)
231
+ Container.remove(temp); // (2)
232
+ }
233
+
234
+ If you swap (1) and (2) you are in trouble, at least with STL.
235
+ XptrHash doesn't have a remove(Iterator) function, however it
236
+ has remove-by-key function which has the same issues.
237
+
238
+ See code below for labels (A,B,C).
239
+ (A) Removing an element that is stored in tbl[] invalidates a iterator
240
+ pointing to the first element in the collision list attached to the same cell.
241
+ An iterator pointing to the removed element is now pointing to the former first
242
+ element of the list.
243
+ (B,C) Removing an element from collision list invalidates iterators pointing
244
+ to the removed element. Other iterators are not affected.
245
+
246
+ The outlined inconsistency in iterator invalidation rules makes it impossible
247
+ to write a safe code that does for-each-element-remove-those-that-meet-some-condition with
248
+ XptrHash.
249
+ */
250
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
251
+ int XptrHash<T, middle_significan_bits, right_zero_bits>::remove(xptr key)
252
+ {
253
+ cell &start = tbl[((__uint32)(XADDR(key)) & templ) >> right_zero_bits];
254
+
255
+ if (start.is_present)
256
+ {
257
+ if (start.key == key)
258
+ {
259
+ if (start.next == NULL)
260
+ {
261
+ start.key.clear();
262
+ start.is_present = false;
263
+ }
264
+ else
265
+ {
266
+ start.key = start.next->key;
267
+ start.val = start.next->val; /* (A) */
268
+ add_cell *p = start.next;
269
+ start.next = start.next->next;
270
+ delete p;
271
+ start.is_present = true;
272
+ }
273
+ --num;
274
+ return 0;
275
+ }
276
+ else
277
+ {
278
+ if (start.next == NULL) return 1;
279
+
280
+ if (start.next->key == key)
281
+ {
282
+ add_cell * p = start.next;
283
+ start.next = start.next->next; /* (B) */
284
+ delete p;
285
+ --num;
286
+ return 0;
287
+ }
288
+
289
+ add_cell * pred = start.next;
290
+ add_cell * cur = start.next->next;
291
+
292
+ for (; cur != NULL; cur = cur->next, pred = pred->next)
293
+ {
294
+ if (cur->key == key)
295
+ {
296
+ pred->next = cur->next; /* (C) */
297
+ delete cur;
298
+ --num;
299
+ return 0;
300
+ }
301
+ }
302
+ return 1;
303
+
304
+ }
305
+ }
306
+ else return 1;
307
+
308
+ --num;
309
+ return 0;
310
+ }
311
+
312
+
313
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
314
+ int XptrHash<T, middle_significan_bits, right_zero_bits>::find_remove(xptr key, T &val)
315
+ {
316
+ cell &start = tbl[((__uint32)(XADDR(key)) & templ) >> right_zero_bits];
317
+
318
+ if (start.is_present)
319
+ {
320
+ if (start.key == key)
321
+ {
322
+ if (start.next == NULL)
323
+ {
324
+ val = start.val;
325
+ start.key.clear();
326
+ start.is_present = false;
327
+ }
328
+ else
329
+ {
330
+ val = start.val;
331
+ start.key = start.next->key;
332
+ start.val = start.next->val;
333
+ add_cell *p = start.next;
334
+ start.next = start.next->next;
335
+ delete p;
336
+ start.is_present = true;
337
+ }
338
+ --num;
339
+ return 0;
340
+ }
341
+ else
342
+ {
343
+ if (start.next == NULL) return 1;
344
+
345
+ if (start.next->key == key)
346
+ {
347
+ val = start.next->val;
348
+ add_cell * p = start.next;
349
+ start.next = start.next->next;
350
+ delete p;
351
+ --num;
352
+ return 0;
353
+ }
354
+
355
+ add_cell * pred = start.next;
356
+ add_cell * cur = start.next->next;
357
+
358
+ for (; cur != NULL; cur = cur->next, pred = pred->next)
359
+ {
360
+ if (cur->key == key)
361
+ {
362
+ val = cur->val;
363
+ pred->next = cur->next;
364
+ delete cur;
365
+ --num;
366
+ return 0;
367
+ }
368
+ }
369
+ return 1;
370
+ }
371
+ }
372
+ else return 1;
373
+
374
+ --num;
375
+ return 0;
376
+ }
377
+
378
+
379
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
380
+ int XptrHash<T, middle_significan_bits, right_zero_bits>::replace(xptr key, const T &new_val, T &old_val)
381
+ {
382
+ cell &start = tbl[((__uint32)(XADDR(key)) & templ) >> right_zero_bits];
383
+ if (start.is_present)
384
+ {
385
+ if (start.key == key)
386
+ {
387
+ old_val = start.val;
388
+ start.val = new_val;
389
+ return 0;
390
+ }
391
+
392
+ add_cell * p = start.next;
393
+ for (; p != NULL; p = p->next)
394
+ {
395
+ if (p->key == key)
396
+ {
397
+ old_val = p->val;
398
+ p->val = new_val;
399
+ return 0;
400
+ }
401
+ }
402
+ return 1;
403
+ }
404
+ else return 1;
405
+
406
+ return 0;
407
+ }
408
+
409
+ template <class T, __uint32 middle_significan_bits, __uint32 right_zero_bits>
410
+ void XptrHash<T, middle_significan_bits, right_zero_bits>::clear()
411
+ {
412
+ if (num != 0)
413
+ {
414
+ add_cell *p = NULL, *tmp = NULL;
415
+
416
+ for (__uint32 i = 0; i < ((__uint32)1 << middle_significan_bits); i++)
417
+ {
418
+ p = tbl[i].next;
419
+ while (p)
420
+ {
421
+ tmp = p;
422
+ p = tmp->next;
423
+ delete tmp;
424
+ }
425
+ tbl[i].key = XNULL;
426
+ tbl[i].next = NULL;
427
+ tbl[i].is_present = false;
428
+ }
429
+
430
+ num = 0;
431
+ }
432
+ }
433
+
434
+ #endif
435
+