26 #define UINT64_HEX_FORMAT "%" INT64_MODIFIER "X"
29 #define EXPECT_TRUE(expr) \
33 "%s was unexpectedly false in file \"%s\" line %u", \
34 #expr, __FILE__, __LINE__); \
37 #define EXPECT_FALSE(expr) \
41 "%s was unexpectedly true in file \"%s\" line %u", \
42 #expr, __FILE__, __LINE__); \
45 #define EXPECT_EQ_U64(result_expr, expected_expr) \
47 uint64 _result = (result_expr); \
48 uint64 _expected = (expected_expr); \
49 if (_result != _expected) \
51 "%s yielded " UINT64_HEX_FORMAT ", expected " UINT64_HEX_FORMAT " (%s) in file \"%s\" line %u", \
52 #result_expr, _result, _expected, #expected_expr, __FILE__, __LINE__); \
79 .class_name =
"node-16-lo",
83 .class_name =
"node-16-hi",
87 .class_name =
"node-48",
91 .class_name =
"node-256",
102 #define RT_USE_DELETE
103 #define RT_VALUE_TYPE TestValueType
104 #ifdef TEST_SHARED_RT
117 return tree->ctl->num_keys;
128 rt_radix_tree *radixtree;
131 #ifdef TEST_SHARED_RT
140 #ifdef TEST_SHARED_RT
144 radixtree = rt_create(radixtree_ctx, dsa, tranche_id);
146 radixtree = rt_create(radixtree_ctx);
157 iter = rt_begin_iterate(radixtree);
159 rt_end_iterate(iter);
163 #ifdef TEST_SHARED_RT
173 rt_radix_tree *radixtree;
176 int children = test_info->
nkeys;
177 #ifdef TEST_SHARED_RT
186 #ifdef TEST_SHARED_RT
190 radixtree = rt_create(radixtree_ctx, dsa, tranche_id);
192 radixtree = rt_create(radixtree_ctx);
195 elog(
NOTICE,
"testing node %s with shift %d and %s keys",
196 test_info->
class_name, shift, asc ?
"ascending" :
"descending");
198 keys =
palloc(
sizeof(uint64) * children);
199 for (
int i = 0;
i < children;
i++)
202 keys[
i] = (uint64)
i << shift;
204 keys[
i] = (uint64) (children - 1 -
i) << shift;
211 for (
int i = 0;
i < children;
i++)
217 for (
int i = 0;
i < children;
i++)
221 value = rt_find(radixtree, keys[
i]);
229 for (
int i = 0;
i < children;
i++)
238 for (
int i = 0;
i < children;
i++)
245 for (
int i = 0;
i < children;
i++)
249 value = rt_find(radixtree, keys[
i]);
257 iter = rt_begin_iterate(radixtree);
259 for (
int i = 0;
i < children;
i++)
269 expected = keys[children - 1 -
i];
271 iterval = rt_iterate_next(iter, &iterkey);
278 rt_end_iterate(iter);
281 for (
int i = 0;
i < children;
i++)
285 for (
int i = 0;
i < children;
i++)
293 #ifdef TEST_SHARED_RT
301 return pg_cmp_u64(*(
const uint64 *)
a, *(
const uint64 *)
b);
308 rt_radix_tree *radixtree;
313 uint64 filter = ((uint64) (0x07 << 24) | (0xFF << 16) | 0xFF);
315 int num_keys = 100000;
317 #ifdef TEST_SHARED_RT
326 #ifdef TEST_SHARED_RT
330 radixtree = rt_create(radixtree_ctx, dsa, tranche_id);
332 radixtree = rt_create(radixtree_ctx);
338 for (uint64
i = 0;
i < num_keys;
i++)
346 rt_set(radixtree,
key, &
val);
351 for (uint64
i = 0;
i < num_keys;
i++)
355 value = rt_find(radixtree, keys[
i]);
366 for (uint64
i = 0;
i < num_keys - 1;
i++)
371 if (keys[
i + 1] == keys[
i] || keys[
i + 1] == keys[
i] + 1)
375 value = rt_find(radixtree, keys[
i] + 1);
380 for (uint64
key = 0;
key < keys[0];
key++)
393 for (uint64
i = 1;
i < 10000;
i++)
397 value = rt_find(radixtree, keys[num_keys - 1] +
i);
402 iter = rt_begin_iterate(radixtree);
404 for (
int i = 0;
i < num_keys;
i++)
411 if (
i < num_keys - 1 && keys[
i + 1] == keys[
i])
415 iterval = rt_iterate_next(iter, &iterkey);
422 rt_end_iterate(iter);
428 for (uint64
i = 0;
i < num_keys;
i++)
432 rt_delete(radixtree,
key);
440 #ifdef TEST_SHARED_RT
TimestampTz GetCurrentTimestamp(void)
void dsa_detach(dsa_area *area)
#define dsa_create(tranch_id)
static int pg_cmp_u64(uint64 a, uint64 b)
void LWLockRegisterTranche(int tranche_id, const char *tranche_name)
int LWLockNewTrancheId(void)
void pfree(void *pointer)
MemoryContext CurrentMemoryContext
#define AllocSetContextCreate
#define ALLOCSET_SMALL_SIZES
uint64 pg_prng_uint64(pg_prng_state *state)
void pg_prng_seed(pg_prng_state *state, uint64 seed)
#define qsort(a, b, c, d)
#define EXPECT_TRUE(expr)
PG_FUNCTION_INFO_V1(test_radixtree)
static uint64 rt_num_entries(rt_radix_tree *tree)
#define EXPECT_FALSE(expr)
#define EXPECT_EQ_U64(result_expr, expected_expr)
static void test_random(void)
Datum test_radixtree(PG_FUNCTION_ARGS)
static void test_empty(void)
static void test_basic(rt_node_class_test_elem *test_info, int shift, bool asc)
static int key_cmp(const void *a, const void *b)
struct rt_node_class_test_elem rt_node_class_test_elem
static rt_node_class_test_elem rt_node_class_tests[]