コード例 #1
0
ファイル: b_plus_tree.c プロジェクト: firstboy0513/fcodelab
/**
* @brief test case for random number insert, search and delete.
*/
void testcase_for_random() {
	TREE* T = bptree_create();
	int i = 0, n = 100;
	int _t = 0;
	srand(time(NULL));
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("bptree_insert(T, %d) = %d\n", _t, bptree_insert(T, _t));
	}
	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("bptree_search(T, %d) = %d\n", _t, bptree_search(T, _t));
	}

	printf("bptree_traveral: ");
	bptree_traveral(T, printout_node);
	printf("\n");

	for (i = 0; i < n; i ++) {
		_t = rand() % n;
		printf("bptree_delete(T, %d) = %d\n", _t, bptree_delete(T, _t));
	}

	printf("bptree_traveral: ");
	bptree_traveral(T, printout_node);
	printf("\n");

	bptree_destory(T);
}
コード例 #2
0
ファイル: tcp.c プロジェクト: atomic77/mosql-storage
static void handle_bptree_delete(tcp_client* c,struct evbuffer* buffer)
{
	int rv;
	bptree_session *bps;
	int32_t ksize, vsize;
	char k[MAX_TRANSACTION_SIZE];
	char v[MAX_TRANSACTION_SIZE];
	bzero(k,MAX_TRANSACTION_SIZE);
	bzero(v,MAX_TRANSACTION_SIZE);

	struct evbuffer* b = evbuffer_copy(buffer);
	transaction_set_get_cb(c->t, on_bptree_delete, c);
	if (bptree_message_incomplete(b)) return;

	bps = retrieve_bptree_session(c,b);
	evbuffer_remove(b,&ksize, sizeof(int32_t));
	evbuffer_remove(b,k, ksize);
	evbuffer_remove(b,&vsize, sizeof(int32_t));
	evbuffer_remove(b,v, vsize);

	rv = bptree_delete(bps,k,ksize,v,vsize);
	if (rv == BPTREE_OP_TAPIOCA_NOT_READY) return;

	evbuffer_free(b);
	evbuffer_drain(buffer, evbuffer_get_length(buffer));
	send_result(c->buffer_ev, rv);
}
コード例 #3
0
ファイル: b_plus_tree.c プロジェクト: firstboy0513/fcodelab
/**
* @brief test case for single insert, search and delete method.
*/
void testcase_for_single() {
	TREE* T = bptree_create();

	printf("bptree_insert(T, 32) = %d\n", bptree_insert(T, 32));

	printf("bptree_search(T, 32) = %d\n", bptree_search(T, 32));

	printf("bptree_delete(T, 32) = %d\n", bptree_delete(T, 32));

	printf("bptree_search(T, 32) = %d\n", bptree_search(T, 32));

	printf("bptree_traveral: ");
	bptree_traveral(T, printout_node);
	printf("\n");

	bptree_destory(T);
}