Commit 2eff86b2 authored by Yoni Fogel's avatar Yoni Fogel

Addresses #288

First set of test cases for range trees.
linear.c is stub implementation so we can compile and write tests before
we actually implement the range tree.

The makefiles were modified just enough to get this to work, and have to
be cleaned up a lot.

git-svn-id: file:///svn/tokudb@1740 c7de825b-a66e-492c-adef-691d508d4ae1
parent d2ef744f
# On OSX do:
# make OSX=OSX
LIBNAME=libdb
LIBNAME=librangetree
OPTFLAGS = -O2
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
......@@ -20,12 +20,9 @@ SHARED=-shared
endif
.PHONY: install logformat
install: logformat $(LIBNAME).$(LIBEXT) $(LIBNAME).a
cp $(LIBNAME).$(LIBEXT) ../lib/
cp $(LIBNAME).a ../lib
logformat:
(cd ../newbrt;make)
install: $(LIBNAME).$(LIBEXT) $(LIBNAME).a
cp $(LIBNAME).$(LIBEXT) ../../lib/
cp $(LIBNAME).a ../../lib
check: $(LIBNAME).$(LIBEXT)
python tokuglobals.py $(LIBNAME).$(LIBEXT)
......@@ -37,8 +34,9 @@ clean:
rm -rf $(LIBNAME).$(LIBEXT) $(LIBNAME).a *.o *.gcno *.gcda *.gcov
cd tests;make clean
ydb.o: ../include/db.h ../newbrt/cachetable.h ../newbrt/brt.h ../newbrt/log.c
DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/brt-verify.o ../newbrt/cachetable.o ../newbrt/fifo.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/mempool.o ../newbrt/pma.o ../newbrt/ybt.o ../newbrt/primes.o ../newbrt/log.o ../newbrt/fingerprint.o ../newbrt/log_code.o ../newbrt/roll.o
linear.o:
DBBINS = linear.o
$(LIBNAME).$(LIBEXT): $(DBBINS)
cc $(CPPFLAGS) $(DBBINS) $(SHARED) -o $@ $(CFLAGS) -lz
......
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007-8 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
/*
* Range trees
*
* This is the header file for range trees. */
//Currently this is a stub implementation just so we can write and compile tests
//before actually implementing the range tree.
#include "rangetree.h"
#define AA __attribute__((__unused__))
int toku_rt_create(toku_range_tree** a AA,
int (*b)(void*,void*) AA, int (*c)(void*,void*) AA,
BOOL d AA)
{return 0;}
int toku_rt_close(toku_range_tree*a AA)
{return 0;}
int toku_rt_find(toku_range_tree*b AA, toku_range*c AA, unsigned d AA, toku_range**e AA, unsigned*g AA, unsigned*f AA)
{return 0;}
int toku_rt_insert(toku_range_tree*a AA, toku_range*v AA)
{return 0;}
int toku_rt_delete(toku_range_tree*c AA, toku_range*q AA)
{return 0;}
int toku_rt_predecessor (toku_range_tree*f AA, void*g AA, toku_range*q AA, BOOL* v AA)
{return 0;}
int toku_rt_successor (toku_range_tree*e AA, void*c AA, toku_range*a AA, BOOL* q AA)
{return 0;}
/*
\marginpar{
static int __toku_lt_infinity;
static int __toku_lt_neg_infinity;
extern void* toku_lt_infinity = &__toku_lt_infinity;
extern void* toku_lt_neg_infinity = &__toku_lt_infinity;}
*/
......@@ -10,21 +10,21 @@ ifeq ($(OSX),OSX)
#Note: OSX 10.4 needs DYLD_LIBRARY_PATH. OSX 10.5 claims to support -rpath.
LIBEXT=dylib
VGRIND=
TDB_LOADLIBES = -L../ -ldb
TDB_LOADLIBES = -L../ -lrangetree
SETTOKUENV=export DYLD_LIBRARY_PATH=.. ;
UNSETTOKUENV=unset DYLD_LIBRARY_PATH ;
else
SETTOKUENV=
UNSETTOKUENV=
LIBEXT=so
TDB_LOADLIBES = -L../ -ldb -Wl,-rpath,.. -lpthread
TDB_LOADLIBES = -L../ -lrangetree -Wl,-rpath,.. -lpthread
VGRIND=valgrind --quiet --error-exitcode=1 --leak-check=yes
endif
LIBNAME=librt.$(LIBEXT)
# GCOV_FLAGS = -fprofile-arcs -ftest-coverage
CFLAGS = -Wall -Werror $(OPTFLAGS) -g $(GCOV_FLAGS)
TDB_CPPFLAGS = -I../ -I../../newbrt
TDB_CPPFLAGS = -I../ -I../../../newbrt
SRCS = $(wildcard *.c)
......@@ -33,7 +33,7 @@ TDB_TESTS = $(patsubst %.c,%.tdb,$(SRCS))
BDB_TESTS = $(patsubst %.c,%.bdb,$(SRCS))
LINEAR_TESTS = $(patsubst %.c,%.bdb,$(SRCS))
ALL_TESTS = $(TDB_TESTS) $(BDB_TESTS)
ALL_TESTS = $(TDB_TESTS) #$(BDB_TESTS)
RUN_TDB_TESTS = $(patsubst %.tdb,%.tdbrun,$(TDB_TESTS))
RUN_BDB_TESTS = $(patsubst %.bdb,%.bdbrun,$(BDB_TESTS))
......@@ -126,15 +126,14 @@ $(patsubst %,test_%.bdbrun,$(NO_VGRIND)): BDB_SUPPRESSIONS=
libs:
cd ..;make
%.bdb: %.c
$(UNSETTOKUENV) cc -DDIR=\"dir.$<.bdb\" $(BDB_CPPFLAGS) -DUSE_BDB -DIS_TDB=0 $(CFLAGS) $< $(BDB_LDFLAGS) -ldb -o $@
%.tdb: %.c
%.bdb: %.c ../rangetree.h test.h
$(UNSETTOKUENV) cc -DDIR=\"dir.$<.bdb\" $(BDB_CPPFLAGS) -DUSE_BDB -DIS_TDB=0 $(CFLAGS) $< $(BDB_LDFLAGS) -lrangetree -o $@
%.tdb: %.c ../rangetree.h test.h
$(SETTOKUENV) cc -DDIR=\"dir.$<.tdb\" -DUSE_TDB -DIS_TDB=1 $(CFLAGS) $(TDB_CPPFLAGS) $(TDB_LOADLIBES) $< -o $@
.PHONY: %.recover
all.recover: test_log2.recover test_log3.recover test_log4.recover test_log5.recover
%.recover: %.tdb
$(MAYBEATSIGN) cd ../../newbrt;make $(VERBQUIET) recover;make $(VERBQUIET)
$(MAYBEATSIGN) cd ..;make $(VERBQUIET)
$(MAYBEATSIGN) $(VGRIND) ./$<
$(MAYBEATSIGN) rm -rf dir.$(patsubst %.tdb,%.c.tdb,$<).recover
......
......@@ -2,8 +2,9 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <db.h>
#include <assert.h>
#include <rangetree.h>
#include <errno.h>
int verbose=0;
#define CKERR(r) ({ if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, strerror(r)); assert(r==0); })
......@@ -38,3 +39,36 @@ static inline uint32_t myrandom (void) {
return rstate;
}
int dummy_cmp(void *a __attribute__((__unused__)),
void *b __attribute__((__unused__))) {
return 0;
}
int ptr_cmp(void *a, void *b) {
return a < b ? -1 : (a != b); /* \marginpar{!?} */
}
int int_cmp(void *a, void *b) {
int x = *(int*)a;
int y = *(int*)b;
return x -y;
}
int char_cmp(void *a, void *b) {
int x = *(char*)a;
int y = *(char*)b;
return x -y;
}
void* toku_malloc(size_t size) {
return malloc(size);
}
void toku_free(void* p) {
free(p);
}
void* toku_realloc(void *ptr, size_t size) {
return realloc(ptr, size);
}
/* We are going to test whether we can create and close range trees */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
parse_args(argc, argv);
/* Test no overlap */
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE);
CKERR(r);
assert(tree!=NULL);
r = toku_rt_close(tree);
CKERR(r);
tree = NULL;
/* Test overlap */
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, TRUE);
CKERR(r);
assert(tree!=NULL);
r = toku_rt_close(tree);
CKERR(r);
tree = NULL;
return 0;
}
/* We are going to test whether create and close properly check their input. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree = NULL;
toku_range range;
parse_args(argc, argv);
/* Create tests */
r = toku_rt_create(NULL, dummy_cmp, dummy_cmp, FALSE);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, NULL, dummy_cmp, FALSE);
CKERR2(r, EINVAL);
assert(tree == NULL);
r = toku_rt_create(&tree, dummy_cmp, NULL, FALSE);
CKERR2(r, EINVAL);
assert(tree == NULL);
/* Close tests */
r = toku_rt_close(NULL);
CKERR2(r, EINVAL);
/* Insert tests */
r = toku_rt_insert(NULL, &range);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE); CKERR(r);
assert(tree != NULL);
r = toku_rt_insert(tree, NULL); CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Delete tests */
r = toku_rt_delete(NULL, &range);
CKERR2(r, EINVAL);
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE); CKERR(r);
assert(tree != NULL);
r = toku_rt_delete(tree, NULL); CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
/* Find tests */
toku_range* buf = (toku_range*)toku_malloc(2*sizeof(toku_range));
unsigned bufsize = 2;
unsigned found;
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE); CKERR(r);
assert(tree != NULL);
r = toku_rt_find(NULL, &range, 2, &buf, &bufsize, &found);
CKERR2(r, EINVAL);
r = toku_rt_find(tree, NULL, 2, &buf, &bufsize, &found);
CKERR2(r, EINVAL);
r = toku_rt_find(tree, &range, 2, NULL, &bufsize, &found);
CKERR2(r, EINVAL);
r = toku_rt_find(tree, &range, 2, &buf, NULL, &found);
CKERR2(r, EINVAL);
r = toku_rt_find(tree, &range, 2, &buf, &bufsize, NULL);
CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
/* Predecessor tests */
int foo;
BOOL wasfound;
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE); CKERR(r);
assert(tree != NULL);
r = toku_rt_predecessor(NULL, &foo, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_predecessor(tree, NULL, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_predecessor(tree, &foo, NULL, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_predecessor(tree, &foo, &range, NULL);
CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, TRUE); CKERR(r);
assert(tree != NULL);
r = toku_rt_predecessor(tree, &foo, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
/* Successor tests */
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, FALSE); CKERR(r);
assert(tree != NULL);
r = toku_rt_successor(NULL, &foo, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_successor(tree, NULL, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_successor(tree, &foo, NULL, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_successor(tree, &foo, &range, NULL);
CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
r = toku_rt_create(&tree, dummy_cmp, dummy_cmp, TRUE); CKERR(r);
assert(tree != NULL);
r = toku_rt_successor(tree, &foo, &range, &wasfound);
CKERR2(r, EINVAL);
r = toku_rt_close(tree); CKERR(r);
return 0;
}
/* We are going to test whether we can insert and delete. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
toku_range range;
int nums[8] = {0,1,2,3,4,5,6,7};
char letters[2] = {'A','B'};
parse_args(argc, argv);
/* Test overlap case */
/*
1 2 3 4 5 6 7
|-------A-------|
|-------A-------|
|-------A-------|
|-------B-------|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[3];
range.right = &nums[7];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
/* Clean up. */
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
range.left = &nums[3];
range.right = &nums[7];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
/* Done */
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Test no overlap case. */
/* Test overlap case */
/*
1 2 3 4 5 6 7
|---A---|
|---B---|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
/* Clean up. */
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
/* Done */
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
return 0;
}
/* We are going to test whether close can clean up after itself. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
toku_range range;
int nums[8] = {0,1,2,3,4,5,6,7};
char letters[2] = {'A','B'};
parse_args(argc, argv);
/* Test overlap case */
/*
1 2 3 4 5 6 7
|---A-----------|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Test non-overlap case */
/*
1 2 3 4 5 6 7
|---A-----------|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, FALSE);
CKERR(r);
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
return 0;
}
/* We are going to test whether we can insert and delete. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
toku_range range;
toku_range find_range;
int nums[8] = {0,1,2,3,4,5,6,7};
char letters[2] = {'A','B'};
unsigned found;
toku_range* buf = (toku_range*)toku_malloc(2*sizeof(toku_range));
unsigned bufsize = 2;
int i;
parse_args(argc, argv);
find_range.left = &nums[4];
find_range.right = &nums[4];
find_range.data = NULL;
/* Test overlap case */
/*
1 2 3 4 5 6 7
|-------A-------|
|-------A-------|
|-------A-------|
|-------B-------|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize == 2);
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize == 2);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize == 2);
range.left = &nums[3];
range.right = &nums[7];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
/* Now that we find 3, we are testing that realloc works. */
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 3);
assert(bufsize >= 3);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 4);
assert(bufsize >= 4);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 3);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
for (i = 0; i < found; i++) {
assert(*(int*)buf[i].left != 2 ||
*(int*)buf[i].right != 6 ||
*(char*)buf[i].data == letters[1]);
}
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 4);
assert(bufsize >= 4);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 3);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
for (i = 0; i < found; i++) {
assert(*(int*)buf[i].left != 2 ||
*(int*)buf[i].right != 6 ||
*(char*)buf[i].data == letters[0]);
}
/* Clean up. */
range.left = &nums[1];
range.right = &nums[5];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[2];
range.right = &nums[6];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 1 &&
*(int*)buf[0].right == 5 &&
*(char*)buf[0].data == letters[0]);
range.left = &nums[3];
range.right = &nums[7];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
/* Done */
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
/* Test no overlap case. */
/* Test overlap case */
/*
1 2 3 4 5 6 7
|---A---|
|---B---|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 1 &&
*(int*)buf[0].right == 3 &&
*(char*)buf[0].data == letters[0]);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 4 &&
*(int*)buf[0].right == 6 &&
*(char*)buf[0].data == letters[1]);
/* Clean up. */
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
/* Done */
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
return 0;
}
/* We are going to test whether we can insert and delete. */
#include "test.h"
int main(int argc, const char *argv[]) {
int r;
toku_range_tree *tree;
toku_range range;
toku_range find_range;
int nums[8] = {0,1,2,3,4,5,6,7};
char letters[2] = {'A','B'};
unsigned found;
toku_range* buf = (toku_range*)toku_malloc(2*sizeof(toku_range));
unsigned bufsize = 2;
parse_args(argc, argv);
find_range.left = &nums[4];
find_range.right = &nums[4];
find_range.data = NULL;
/* Test no overlap case. */
/* Test overlap case */
/*
1 2 3 4 5 6 7
|---A---|
|---B---|
*/
r = toku_rt_create(&tree, int_cmp, char_cmp, TRUE);
CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 1 &&
*(int*)buf[0].right == 3 &&
*(char*)buf[0].data == letters[0]);
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_insert(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 2);
assert(bufsize >= 4);
range.left = &nums[1];
range.right = &nums[3];
range.data = &letters[0];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 1);
assert(bufsize >= 4);
/* Verify the right one is still there, and the wrong one is not there. */
assert(*(int*)buf[0].left == 4 &&
*(int*)buf[0].right == 6 &&
*(char*)buf[0].data == letters[1]);
/* Clean up. */
range.left = &nums[4];
range.right = &nums[6];
range.data = &letters[1];
r = toku_rt_delete(tree, &range); CKERR(r);
r = toku_rt_find(tree, &find_range, 4, &buf, &bufsize, &found); CKERR(r);
assert(found == 0);
assert(bufsize >= 4);
/* Done */
r = toku_rt_close(tree); CKERR(r);
tree = NULL;
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment