Ejemplo n.º 1
0
TEST_END

TEST_BEGIN(test_rtree_extrema)
{
	unsigned i;
	extent_node_t node_a, node_b;

	for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
		rtree_t rtree;
		assert_false(rtree_new(&rtree, i, node_alloc, node_dalloc),
		    "Unexpected rtree_new() failure");

		assert_false(rtree_set(&rtree, 0, &node_a),
		    "Unexpected rtree_set() failure");
		assert_ptr_eq(rtree_get(&rtree, 0, true), &node_a,
		    "rtree_get() should return previously set value");

		assert_false(rtree_set(&rtree, ~((uintptr_t)0), &node_b),
		    "Unexpected rtree_set() failure");
		assert_ptr_eq(rtree_get(&rtree, ~((uintptr_t)0), true), &node_b,
		    "rtree_get() should return previously set value");

		rtree_delete(&rtree);
	}
}
Ejemplo n.º 2
0
TEST_END

TEST_BEGIN(test_rtree_bits)
{
	unsigned i, j, k;

	for (i = 1; i < (sizeof(uintptr_t) << 3); i++) {
		uintptr_t keys[] = {0, 1,
		    (((uintptr_t)1) << (sizeof(uintptr_t)*8-i)) - 1};
		rtree_t *rtree = rtree_new(i, malloc, free);

		for (j = 0; j < sizeof(keys)/sizeof(uintptr_t); j++) {
			rtree_set(rtree, keys[j], 1);
			for (k = 0; k < sizeof(keys)/sizeof(uintptr_t); k++) {
				assert_u_eq(rtree_get(rtree, keys[k]), 1,
				    "rtree_get() should return previously set "
				    "value and ignore insignificant key bits; "
				    "i=%u, j=%u, k=%u, set key=%#"PRIxPTR", "
				    "get key=%#"PRIxPTR, i, j, k, keys[j],
				    keys[k]);
			}
			assert_u_eq(rtree_get(rtree,
			    (((uintptr_t)1) << (sizeof(uintptr_t)*8-i))), 0,
			    "Only leftmost rtree leaf should be set; "
			    "i=%u, j=%u", i, j);
			rtree_set(rtree, keys[j], 0);
		}

		rtree_delete(rtree);
	}
}
Ejemplo n.º 3
0
TEST_END

TEST_BEGIN(test_rtree_random)
{
	unsigned i;
	sfmt_t *sfmt;
#define	NSET 16
#define	SEED 42

	sfmt = init_gen_rand(SEED);
	for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
		uintptr_t keys[NSET];
		extent_node_t node;
		unsigned j;
		rtree_t rtree;

		assert_false(rtree_new(&rtree, i, node_alloc, node_dalloc),
		    "Unexpected rtree_new() failure");

		for (j = 0; j < NSET; j++) {
			keys[j] = (uintptr_t)gen_rand64(sfmt);
			assert_false(rtree_set(&rtree, keys[j], &node),
			    "Unexpected rtree_set() failure");
			assert_ptr_eq(rtree_get(&rtree, keys[j], true), &node,
			    "rtree_get() should return previously set value");
		}
		for (j = 0; j < NSET; j++) {
			assert_ptr_eq(rtree_get(&rtree, keys[j], true), &node,
			    "rtree_get() should return previously set value");
		}

		for (j = 0; j < NSET; j++) {
			assert_false(rtree_set(&rtree, keys[j], NULL),
			    "Unexpected rtree_set() failure");
			assert_ptr_null(rtree_get(&rtree, keys[j], true),
			    "rtree_get() should return previously set value");
		}
		for (j = 0; j < NSET; j++) {
			assert_ptr_null(rtree_get(&rtree, keys[j], true),
			    "rtree_get() should return previously set value");
		}

		rtree_delete(&rtree);
	}
	fini_gen_rand(sfmt);
#undef NSET
#undef SEED
}
Ejemplo n.º 4
0
TEST_END

TEST_BEGIN(test_rtree_random)
{
	unsigned i;
	sfmt_t *sfmt;
#define	NSET 100
#define	SEED 42

	sfmt = init_gen_rand(SEED);
	for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
		rtree_t *rtree = rtree_new(i, malloc, free);
		uintptr_t keys[NSET];
		unsigned j;

		for (j = 0; j < NSET; j++) {
			keys[j] = (uintptr_t)gen_rand64(sfmt);
			rtree_set(rtree, keys[j], 1);
			assert_u_eq(rtree_get(rtree, keys[j]), 1,
			    "rtree_get() should return previously set value");
		}
		for (j = 0; j < NSET; j++) {
			assert_u_eq(rtree_get(rtree, keys[j]), 1,
			    "rtree_get() should return previously set value");
		}

		for (j = 0; j < NSET; j++) {
			rtree_set(rtree, keys[j], 0);
			assert_u_eq(rtree_get(rtree, keys[j]), 0,
			    "rtree_get() should return previously set value");
		}
		for (j = 0; j < NSET; j++) {
			assert_u_eq(rtree_get(rtree, keys[j]), 0,
			    "rtree_get() should return previously set value");
		}

		rtree_delete(rtree);
	}
	fini_gen_rand(sfmt);
#undef NSET
#undef SEED
}
Ejemplo n.º 5
0
TEST_END

TEST_BEGIN(test_rtree_extrema)
{
	unsigned i;

	for (i = 1; i <= (sizeof(uintptr_t) << 3); i++) {
		rtree_t *rtree = rtree_new(i, malloc, free);

		rtree_set(rtree, 0, 1);
		assert_u_eq(rtree_get(rtree, 0), 1,
		    "rtree_get() should return previously set value");

		rtree_set(rtree, ~((uintptr_t)0), 1);
		assert_u_eq(rtree_get(rtree, ~((uintptr_t)0)), 1,
		    "rtree_get() should return previously set value");

		rtree_delete(rtree);
	}
}
Ejemplo n.º 6
0
TEST_END

TEST_BEGIN(test_rtree_bits)
{
	unsigned i, j, k;

	for (i = 1; i < (sizeof(uintptr_t) << 3); i++) {
		uintptr_t keys[] = {0, 1,
		    (((uintptr_t)1) << (sizeof(uintptr_t)*8-i)) - 1};
		extent_node_t node;
		rtree_t rtree;

		assert_false(rtree_new(&rtree, i, node_alloc, node_dalloc),
		    "Unexpected rtree_new() failure");

		for (j = 0; j < sizeof(keys)/sizeof(uintptr_t); j++) {
			assert_false(rtree_set(&rtree, keys[j], &node),
			    "Unexpected rtree_set() failure");
			for (k = 0; k < sizeof(keys)/sizeof(uintptr_t); k++) {
				assert_ptr_eq(rtree_get(&rtree, keys[k], true),
				    &node, "rtree_get() should return "
				    "previously set value and ignore "
				    "insignificant key bits; i=%u, j=%u, k=%u, "
				    "set key=%#"FMTxPTR", get key=%#"FMTxPTR, i,
				    j, k, keys[j], keys[k]);
			}
			assert_ptr_null(rtree_get(&rtree,
			    (((uintptr_t)1) << (sizeof(uintptr_t)*8-i)), false),
			    "Only leftmost rtree leaf should be set; "
			    "i=%u, j=%u", i, j);
			assert_false(rtree_set(&rtree, keys[j], NULL),
			    "Unexpected rtree_set() failure");
		}

		rtree_delete(&rtree);
	}
}
Ejemplo n.º 7
0
void rtree_set_intptr(RTree *tree, intptr_t ptr, void *data)
{
	unsigned char buffer[sizeof(intptr_t)];
	intptr_to_padded_array_le(buffer, ptr);
	rtree_set(tree, buffer, sizeof(intptr_t), data);
}
Ejemplo n.º 8
0
void rtree_set_ple_int(RTree *tree, int number, void *data)
{
	unsigned char buffer[sizeof(int)];
	int_to_padded_array_le(buffer, number);
	rtree_set(tree, buffer, sizeof(int), data);
}