Go to the source code of this file.
◆ IntRBTreeNode
◆ create_int_rbtree()
static RBTree * create_int_rbtree |
( |
void |
| ) |
|
|
static |
Definition at line 80 of file test_rbtree.c.
81{
87 NULL);
88}
RBTree * rbt_create(Size node_size, rbt_comparator comparator, rbt_combiner combiner, rbt_allocfunc allocfunc, rbt_freefunc freefunc, void *arg)
static RBTNode * irbt_alloc(void *arg)
static void irbt_free(RBTNode *node, void *arg)
static void irbt_combine(RBTNode *existing, const RBTNode *newdata, void *arg)
static int irbt_cmp(const RBTNode *a, const RBTNode *b, void *arg)
References irbt_alloc(), irbt_cmp(), irbt_combine(), irbt_free(), and rbt_create().
Referenced by testdelete(), testfind(), testfindltgt(), testleftmost(), testleftright(), and testrightleft().
◆ GetPermutation()
static int * GetPermutation |
( |
int |
size | ) |
|
|
static |
Definition at line 94 of file test_rbtree.c.
95{
96 int *permutation;
98
99 permutation = (
int *)
palloc(size *
sizeof(
int));
100
101 permutation[0] = 0;
102
103
104
105
106
107
108
109
110 for (
i = 1;
i < size;
i++)
111 {
113
115 permutation[
i] = permutation[
j];
117 }
118
119 return permutation;
120}
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
pg_prng_state pg_global_prng_state
References i, j, palloc(), pg_global_prng_state, and pg_prng_uint64_range().
Referenced by rbt_populate().
◆ irbt_alloc()
static RBTNode * irbt_alloc |
( |
void * |
arg | ) |
|
|
static |
◆ irbt_cmp()
static int irbt_cmp |
( |
const RBTNode * |
a, |
|
|
const RBTNode * |
b, |
|
|
void * |
arg |
|
) |
| |
|
static |
◆ irbt_combine()
static void irbt_combine |
( |
RBTNode * |
existing, |
|
|
const RBTNode * |
newdata, |
|
|
void * |
arg |
|
) |
| |
|
static |
◆ irbt_free()
static void irbt_free |
( |
RBTNode * |
node, |
|
|
void * |
arg |
|
) |
| |
|
static |
◆ PG_FUNCTION_INFO_V1()
◆ rbt_populate()
static void rbt_populate |
( |
RBTree * |
tree, |
|
|
int |
size, |
|
|
int |
step |
|
) |
| |
|
static |
Definition at line 127 of file test_rbtree.c.
128{
131 bool isNew;
133
134
135 for (
i = 0;
i < size;
i++)
136 {
137 node.
key = step * permutation[
i];
139 if (!isNew)
140 elog(
ERROR,
"unexpected !isNew result from rbt_insert");
141 }
142
143
144
145
146
147 if (size > 0)
148 {
149 node.
key = step * permutation[0];
151 if (isNew)
152 elog(
ERROR,
"unexpected isNew result from rbt_insert");
153 }
154
156}
RBTNode * rbt_insert(RBTree *rbt, const RBTNode *data, bool *isNew)
static int * GetPermutation(int size)
References elog, ERROR, GetPermutation(), i, IntRBTreeNode::key, pfree(), rbt_insert(), and tree.
Referenced by testdelete(), testfind(), testfindltgt(), testleftmost(), testleftright(), and testrightleft().
◆ test_rb_tree()
Definition at line 503 of file test_rbtree.c.
504{
506
508 elog(
ERROR,
"invalid size for test_rb_tree: %d", size);
516}
#define PG_GETARG_INT32(n)
static void testleftright(int size)
static void testleftmost(int size)
static void testdelete(int size, int delsize)
static void testfindltgt(int size)
static void testrightleft(int size)
static void testfind(int size)
References elog, ERROR, Max, MaxAllocSize, PG_GETARG_INT32, PG_RETURN_VOID, testdelete(), testfind(), testfindltgt(), testleftmost(), testleftright(), and testrightleft().
◆ testdelete()
static void testdelete |
( |
int |
size, |
|
|
int |
delsize |
|
) |
| |
|
static |
Definition at line 409 of file test_rbtree.c.
410{
412 int *deleteIds;
413 bool *chosen;
415
416
418
419
420 deleteIds = (
int *)
palloc(delsize *
sizeof(
int));
421 chosen = (
bool *)
palloc0(size *
sizeof(
bool));
422
423 for (
i = 0;
i < delsize;
i++)
424 {
426
427 while (chosen[k])
428 k = (k + 1) % size;
430 chosen[k] = true;
431 }
432
433
434 for (
i = 0;
i < delsize;
i++)
435 {
438
439 find.key = deleteIds[
i];
440
442 if (node == NULL || node->
key != deleteIds[
i])
443 elog(
ERROR,
"expected element was not found during deleting");
444
446 }
447
448
449 for (
i = 0;
i < size;
i++)
450 {
453
457 {
458
459 if (result != NULL)
460 elog(
ERROR,
"deleted element still present in the rbtree");
461 }
462 else
463 {
464
465 if (result == NULL || result->
key !=
i)
466 elog(
ERROR,
"delete operation removed wrong rbtree value");
467 }
468 }
469
470
471 for (
i = 0;
i < size;
i++)
472 {
475
477 continue;
479
481 if (node == NULL || node->
key !=
i)
482 elog(
ERROR,
"expected element was not found during deleting");
483
485 }
486
487
489 elog(
ERROR,
"deleting all elements failed");
490
493}
void * palloc0(Size size)
RBTNode * rbt_find(RBTree *rbt, const RBTNode *data)
RBTNode * rbt_leftmost(RBTree *rbt)
void rbt_delete(RBTree *rbt, RBTNode *node)
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
static void rbt_populate(RBTree *tree, int size, int step)
static RBTree * create_int_rbtree(void)
References create_int_rbtree(), elog, ERROR, find(), i, IntRBTreeNode::key, palloc(), palloc0(), pfree(), pg_global_prng_state, pg_prng_uint64_range(), rbt_delete(), rbt_find(), rbt_leftmost(), rbt_populate(), and tree.
Referenced by test_rb_tree().
◆ testfind()
static void testfind |
( |
int |
size | ) |
|
|
static |
Definition at line 243 of file test_rbtree.c.
244{
247
248
250
251
252 for (
i = 0;
i < size;
i++)
253 {
256
259 if (resultNode == NULL)
260 elog(
ERROR,
"inserted element was not found");
261 if (node.
key != resultNode->
key)
262 elog(
ERROR,
"find operation in rbtree gave wrong result");
263 }
264
265
266
267
268
269 for (
i = -1;
i <= 2 * size;
i += 2)
270 {
273
276 if (resultNode != NULL)
277 elog(
ERROR,
"not-inserted element was found");
278 }
279}
References create_int_rbtree(), elog, ERROR, i, IntRBTreeNode::key, rbt_find(), rbt_populate(), and tree.
Referenced by test_rb_tree().
◆ testfindltgt()
static void testfindltgt |
( |
int |
size | ) |
|
|
static |
Definition at line 287 of file test_rbtree.c.
288{
290
291
292
293
294
296 bool keyDeleted;
301
302
304
305
306
307
308
311
312 if (lteNode == NULL || lteNode->
key != searchNode.
key)
313 elog(
ERROR,
"rbt_find_less() didn't find the equal key");
314
315 if (gteNode == NULL || gteNode->
key != searchNode.
key)
316 elog(
ERROR,
"rbt_find_great() didn't find the equal key");
317
318 if (lteNode != gteNode)
319 elog(
ERROR,
"rbt_find_less() and rbt_find_great() found different equal keys");
320
321
322 keyDeleted = false;
323 for (; searchNode.
key > 0; searchNode.
key--)
324 {
325
326
327
328
330 keyDeleted);
331
332
333 if (!node || !(node->
key < searchNode.
key))
334 elog(
ERROR,
"rbt_find_less() didn't find a lesser key");
335
336
338 if (keyDeleted)
340 }
341
342
343 keyDeleted = false;
344 for (searchNode.
key = randomKey; searchNode.
key < size - 1; searchNode.
key++)
345 {
346
347
348
349
351 keyDeleted);
352
353
354 if (!node || !(node->
key > searchNode.
key))
355 elog(
ERROR,
"rbt_find_great() didn't find a greater key");
356
357
359 if (keyDeleted)
361 }
362
363
366 if (node != NULL)
367 elog(
ERROR,
"rbt_find_less() found non-inserted element");
370 if (node != NULL)
371 elog(
ERROR,
"rbt_find_less() found non-inserted element");
372 searchNode.
key = size;
374 if (node != NULL)
375 elog(
ERROR,
"rbt_find_great() found non-inserted element");
376 searchNode.
key = size - 1;
378 if (node != NULL)
379 elog(
ERROR,
"rbt_find_great() found non-inserted element");
380}
RBTNode * rbt_find_great(RBTree *rbt, const RBTNode *data, bool equal_match)
RBTNode * rbt_find_less(RBTree *rbt, const RBTNode *data, bool equal_match)
References create_int_rbtree(), elog, ERROR, IntRBTreeNode::key, pg_global_prng_state, pg_prng_uint64_range(), rbt_delete(), rbt_find_great(), rbt_find_less(), rbt_populate(), and tree.
Referenced by test_rb_tree().
◆ testleftmost()
static void testleftmost |
( |
int |
size | ) |
|
|
static |
◆ testleftright()
static void testleftright |
( |
int |
size | ) |
|
|
static |
Definition at line 164 of file test_rbtree.c.
165{
169 int lastKey = -1;
170 int count = 0;
171
172
175 elog(
ERROR,
"left-right walk over empty tree produced an element");
176
177
179
180
182
184 {
185
186 if (node->
key <= lastKey)
187 elog(
ERROR,
"left-right walk gives elements not in sorted order");
189 count++;
190 }
191
192 if (lastKey != size - 1)
193 elog(
ERROR,
"left-right walk did not reach end");
194 if (count != size)
195 elog(
ERROR,
"left-right walk missed some elements");
196}
RBTNode * rbt_iterate(RBTreeIterator *iter)
void rbt_begin_iterate(RBTree *rbt, RBTOrderControl ctrl, RBTreeIterator *iter)
References create_int_rbtree(), elog, ERROR, IntRBTreeNode::key, LeftRightWalk, rbt_begin_iterate(), rbt_iterate(), rbt_populate(), and tree.
Referenced by test_rb_tree().
◆ testrightleft()
static void testrightleft |
( |
int |
size | ) |
|
|
static |
Definition at line 204 of file test_rbtree.c.
205{
209 int lastKey = size;
210 int count = 0;
211
212
215 elog(
ERROR,
"right-left walk over empty tree produced an element");
216
217
219
220
222
224 {
225
226 if (node->
key >= lastKey)
227 elog(
ERROR,
"right-left walk gives elements not in sorted order");
229 count++;
230 }
231
232 if (lastKey != 0)
233 elog(
ERROR,
"right-left walk did not reach end");
234 if (count != size)
235 elog(
ERROR,
"right-left walk missed some elements");
236}
References create_int_rbtree(), elog, ERROR, IntRBTreeNode::key, rbt_begin_iterate(), rbt_iterate(), rbt_populate(), RightLeftWalk, and tree.
Referenced by test_rb_tree().
◆ PG_MODULE_MAGIC