57 if (eexist->
key != enew->
key)
58 elog(
ERROR,
"red-black tree combines %d into %d",
99 permutation = (
int *)
palloc(
size *
sizeof(
int));
115 permutation[
i] = permutation[
j];
137 node.
key = step * permutation[
i];
140 elog(
ERROR,
"unexpected !isNew result from rbt_insert");
149 node.
key = step * permutation[0];
152 elog(
ERROR,
"unexpected isNew result from rbt_insert");
175 elog(
ERROR,
"left-right walk over empty tree produced an element");
186 if (node->
key <= lastKey)
187 elog(
ERROR,
"left-right walk gives elements not in sorted order");
192 if (lastKey !=
size - 1)
193 elog(
ERROR,
"left-right walk did not reach end");
195 elog(
ERROR,
"left-right walk missed some elements");
215 elog(
ERROR,
"right-left walk over empty tree produced an element");
226 if (node->
key >= lastKey)
227 elog(
ERROR,
"right-left walk gives elements not in sorted order");
233 elog(
ERROR,
"right-left walk did not reach end");
235 elog(
ERROR,
"right-left walk missed some elements");
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");
269 for (
i = -1;
i <= 2 *
size;
i += 2)
276 if (resultNode != NULL)
277 elog(
ERROR,
"not-inserted element was found");
312 if (lteNode == NULL || lteNode->
key != searchNode.
key)
313 elog(
ERROR,
"rbt_find_less() didn't find the equal key");
315 if (gteNode == NULL || gteNode->
key != searchNode.
key)
316 elog(
ERROR,
"rbt_find_great() didn't find the equal key");
318 if (lteNode != gteNode)
319 elog(
ERROR,
"rbt_find_less() and rbt_find_great() found different equal keys");
323 for (; searchNode.
key > 0; searchNode.
key--)
333 if (!node || !(node->
key < searchNode.
key))
334 elog(
ERROR,
"rbt_find_less() didn't find a lesser key");
344 for (searchNode.
key = randomKey; searchNode.
key <
size - 1; searchNode.
key++)
354 if (!node || !(node->
key > searchNode.
key))
355 elog(
ERROR,
"rbt_find_great() didn't find a greater key");
367 elog(
ERROR,
"rbt_find_less() found non-inserted element");
371 elog(
ERROR,
"rbt_find_less() found non-inserted element");
375 elog(
ERROR,
"rbt_find_great() found non-inserted element");
379 elog(
ERROR,
"rbt_find_great() found non-inserted element");
394 elog(
ERROR,
"leftmost node of empty tree is not NULL");
401 if (result == NULL || result->
key != 0)
402 elog(
ERROR,
"rbt_leftmost gave wrong result");
420 deleteIds = (
int *)
palloc(delsize *
sizeof(
int));
423 for (
i = 0;
i < delsize;
i++)
434 for (
i = 0;
i < delsize;
i++)
439 find.key = deleteIds[
i];
442 if (node == NULL || node->
key != deleteIds[
i])
443 elog(
ERROR,
"expected element was not found during deleting");
460 elog(
ERROR,
"deleted element still present in the rbtree");
465 if (result == NULL || result->
key !=
i)
466 elog(
ERROR,
"delete operation removed wrong rbtree value");
481 if (node == NULL || node->
key !=
i)
482 elog(
ERROR,
"expected element was not found during deleting");
489 elog(
ERROR,
"deleting all elements failed");
#define PG_GETARG_INT32(n)
void pfree(void *pointer)
void * palloc0(Size size)
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
pg_prng_state pg_global_prng_state
RBTNode * rbt_find_great(RBTree *rbt, const RBTNode *data, bool equal_match)
RBTNode * rbt_iterate(RBTreeIterator *iter)
RBTNode * rbt_insert(RBTree *rbt, const RBTNode *data, bool *isNew)
void rbt_begin_iterate(RBTree *rbt, RBTOrderControl ctrl, RBTreeIterator *iter)
RBTree * rbt_create(Size node_size, rbt_comparator comparator, rbt_combiner combiner, rbt_allocfunc allocfunc, rbt_freefunc freefunc, void *arg)
RBTNode * rbt_find_less(RBTree *rbt, const RBTNode *data, bool equal_match)
RBTNode * rbt_leftmost(RBTree *rbt)
void rbt_delete(RBTree *rbt, RBTNode *node)
RBTNode * rbt_find(RBTree *rbt, const RBTNode *data)
static int find(struct vars *v, struct cnfa *cnfa, struct colormap *cm)
static pg_noinline void Size size
Datum test_rb_tree(PG_FUNCTION_ARGS)
static void irbt_free(RBTNode *node, void *arg)
static int * GetPermutation(int size)
static void testleftright(int size)
static void irbt_combine(RBTNode *existing, const RBTNode *newdata, void *arg)
PG_FUNCTION_INFO_V1(test_rb_tree)
static void rbt_populate(RBTree *tree, int size, int step)
static RBTree * create_int_rbtree(void)
static void testleftmost(int size)
static void testdelete(int size, int delsize)
static void testfindltgt(int size)
struct IntRBTreeNode IntRBTreeNode
static int irbt_cmp(const RBTNode *a, const RBTNode *b, void *arg)
static RBTNode * irbt_alloc(void *arg)
static void testrightleft(int size)
static void testfind(int size)