Exemple #1
0
void lookups_tree_2(void)
{
	struct avltree_node *node = NULL;
	avl_unit_val_t *v2, *v;
	char s[256];
	int ix;

	/* attempts 100K mits, 100K misses */
	for (ix = 0; ix < 200000; ++ix) {
		sprintf(s, "file%d", ix);
		v = avl_unit_new_val(s);
		v2 = qp_avl_lookup_s(&avl_tree_1, v, 1);
		if (!v2) {
			if (ix < 100000) {
				abort();
			} else {
				/*
				printf("%d %d %s\n", ix, v2->hk.p, v2->name);
				*/
			}
		}
	}

	/* free v */
	avl_unit_free_val(v);
}
Exemple #2
0
void lookups_tree_1(void)
{
	struct avltree_node *node;
	avl_unit_val_t *v2, *v;
	char *s;
	int ix;

	ix = 0;
	while ((s = dir_data[ix].name) != NULL) {
		v = avl_unit_new_val(s);

		/* lookup mapping */
		v2 = qp_avl_lookup_s(&avl_tree_1, v, 1);
		if (!v2) {
			abort();
		} else {
			/*
			printf("%d %d %s\n", ix, v2->hk.p, v2->name);
			*/
		}
		++ix;
	}

	/* free v */
	avl_unit_free_val(v);
}
Exemple #3
0
void checks_supremum(void)
{
	struct avltree_node *node;
	avl_unit_val_t *v2, *v = avl_unit_new_val(0);
	int ix;

	for (ix = 100; ix < 1000; ix += 100) {

		/* reuse v */
		v->key = (ix - 2);	/* a value -just less than ix- */

		/* lookup mapping */
		node = avltree_sup(&v->node_k, &avl_tree_2);
		CU_ASSERT(node != NULL);
		if (node) {
			v2 = avltree_container_of(node, avl_unit_val_t, node_k);
			CU_ASSERT((unsigned long)v2->val == (ix + 1));
		}

		/* ok, now find the -infimum- */
		v->key = ix + 2;	/* a value just above ix */

		/* lookup mapping */
		node = avltree_inf(&v->node_k, &avl_tree_2);
		CU_ASSERT(node != NULL);
		if (node) {
			v2 = avltree_container_of(node, avl_unit_val_t, node_k);
			CU_ASSERT((unsigned long)v2->val == (ix + 1));
		}

	}

	/* now check the boundary case for supremum */
	v->key = 500;

	node = avltree_sup(&v->node_k, &avl_tree_2);
	CU_ASSERT(node != NULL);
	if (node) {
		v2 = avltree_container_of(node, avl_unit_val_t, node_k);
		CU_ASSERT((unsigned long)v2->val == (v->key + 1));
	}

	/* and infimum */
	node = avltree_inf(&v->node_k, &avl_tree_2);
	CU_ASSERT(node != NULL);
	if (node) {
		v2 = avltree_container_of(node, avl_unit_val_t, node_k);
		CU_ASSERT((unsigned long)v2->val == (v->key + 1));
	}

	/* free v */
	avl_unit_free_val(v);
}
Exemple #4
0
void insert_long_val(struct avltree *t, unsigned long l)
{
	avl_unit_val_t *v;

	/* new k, v */
	v = avl_unit_new_val(l);

	/* if actual key cannot be marshalled as a pointer */
	v->key = l;

	/* insert mapping */
	avltree_insert(&v->node_k, t);
}
Exemple #5
0
void insert_long_val_safe(struct avltree *t, unsigned long l)
{
	struct avltree_node *node;
	avl_unit_val_t *v;

	/* new k, v */
	v = avl_unit_new_val(l);
	v->key = l;

	node = avltree_lookup(&v->node_k, t);
	if (node == NULL)
		avltree_insert(&v->node_k, t);
	else
		avl_unit_free_val(v);
}
Exemple #6
0
void inserts_tree_2(void)
{
	avl_unit_val_t *v;
	char s[256];
	int ix, code;

	for (ix = 0; ix < 100000; ++ix) {
		sprintf(s, "file%d", ix);
		v = avl_unit_new_val(gsh_strdup(s));
		code = qp_avl_insert(&avl_tree_1, v);
		if (code == -1)
			abort();
		if (v->hk.p > 0)
			printf("%d positive p %d %s\n", ix, v->hk.p, s);
	}
}
Exemple #7
0
void inserts_tree_10000(void)
{
	avl_unit_val_t *v;
	int ix;

	for (ix = 1; ix < 10001; ++ix) {

		/* new k, v */
		v = avl_unit_new_val(ix);

		/* if actual key cannot be marshalled as a pointer */
		v->key = ix;

		/* insert mapping */
		avltree_insert(&v->node_k, &avl_tree_10000);
	}
}
Exemple #8
0
void inserts_tree_1(void)
{
	avl_unit_val_t *v;
	char *s;
	int ix, code;

	ix = 0;
	while ((s = dir_data[ix].name) != NULL) {
		v = avl_unit_new_val(gsh_strdup(s));
		code = qp_avl_insert(&avl_tree_1, v);
		if (code == -1)
			abort();
		if (v->hk.p > 0)
			printf("%d positive p %d %s\n", ix, v->hk.p, s);
		++ix;
	}
}
Exemple #9
0
void check_delete_1(void)
{
	struct avltree_node *node;
	avl_unit_val_t *v, *v2;

	avl_unit_clear_and_destroy_tree(&avl_tree_1);

	avltree_init(&avl_tree_1, avl_unit_cmpf, 0 /* flags */);

	insert_long_val(&avl_tree_1, 4);
	insert_long_val(&avl_tree_1, 1);
	insert_long_val(&avl_tree_1, 10010);
	insert_long_val(&avl_tree_1, 267);
	insert_long_val(&avl_tree_1, 3382);
	insert_long_val(&avl_tree_1, 22);
	insert_long_val(&avl_tree_1, 82);
	insert_long_val(&avl_tree_1, 3);

	node = avltree_first(&avl_tree_1);
	v2 = avltree_container_of(node, avl_unit_val_t, node_k);
	CU_ASSERT(v2->val == (1 + 1));

	delete_long_val(&avl_tree_1, 1);

	/* new key */
	v = avl_unit_new_val(4);
	v->key = 4;
	node = avltree_lookup(&v->node_k, &avl_tree_1);
	v2 = avltree_container_of(node, avl_unit_val_t, node_k);

	CU_ASSERT(v2->val == (4 + 1));

	delete_long_val(&avl_tree_1, 267);

	v->key = 3382;
	node = avltree_lookup(&v->node_k, &avl_tree_1);
	v2 = avltree_container_of(node, avl_unit_val_t, node_k);

	CU_ASSERT(v2->val == (3382 + 1));

	avl_unit_free_val(v);

}
Exemple #10
0
void lookups_tree_10000(void)
{
	struct avltree_node *node;
	avl_unit_val_t *v2, *v = avl_unit_new_val(0);
	int ix;

	for (ix = 1; ix < 2; ++ix) {

		/* reuse v */
		v->key = ix;

		/* lookup mapping */
		node = avltree_lookup(&v->node_k, &avl_tree_10000);
		v2 = avltree_container_of(node, avl_unit_val_t, node_k);
		CU_ASSERT((unsigned long)v2->val == (ix + 1));
	}

	/* free v */
	avl_unit_free_val(v);
}
Exemple #11
0
void delete_long_val(struct avltree *t, unsigned long l)
{
	struct avltree_node *node;
	avl_unit_val_t *v, *v2;

	/* new key, v */
	v = avl_unit_new_val(l);
	v->key = l;

	/* find mapping */
	node = avltree_lookup(&v->node_k, t);
	v2 = avltree_container_of(node, avl_unit_val_t, node_k);
	CU_ASSERT(v2->key == l);

	/* delete mapping */
	avltree_remove(&v2->node_k, t);

	/* free original v */
	avl_unit_free_val(v2);

	/* free search k, v */
	avl_unit_free_val(v);
}
Exemple #12
0
void deletes_tree_10000(void)
{
	struct avltree_node *node;
	avl_unit_val_t *v2, *v = avl_unit_new_val(0);
	int ix;

	for (ix = 1; ix < 10001; ++ix) {

		/* reuse key */
		v->key = ix;

		/* find mapping */
		node = avltree_lookup(&v->node_k, &avl_tree_10000);
		v2 = avltree_container_of(node, avl_unit_val_t, node_k);
		CU_ASSERT(v2->val == (ix + 1));

		/* and remove it */
		avltree_remove(&v2->node_k, &avl_tree_10000);
		avl_unit_free_val(v2);
	}

	/* free search k */
	avl_unit_free_val(v);
}