usage() {
puts(
"Usage:\n"
- "tbtreetest -b [-r -c COUNT] | -s [ -c COUNT ]\n"
+ "tbtreetest -b [-r -c COUNT -f] | -s [ -c COUNT ]\n"
);
exit(1);
}
int
main(int argn, char *argv[]) {
int mode=NO_MODE;
- int isrnd=0, count=10,i;
+ int isrnd=0, count=10,i, isfind=0;
opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
symbolslen=strlen(symbols);
- while((i=getopt(argn,argv,"sbrc:")) != EOF) {
+ while((i=getopt(argn,argv,"sbrc:f")) != EOF) {
switch(i) {
+ case 'f':
+ isfind=1;
+ break;
case 'r':
isrnd=1;
break;
if ( mode==MODE_BTREE ) {
int cnt;
- for(i=0;i<count;i++) {
- printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
- cnt=1+random()%512;
- while(cnt-->0)
- fputc( symbols[ random()%symbolslen ], stdout);
- fputc('\n', stdout);
- }
+ if ( isfind )
+ for(i=0;i<count;i++)
+ printf("S\t%d\n", (int)( (isrnd) ? random()%count : i ));
+ else
+ for(i=0;i<count;i++) {
+ printf("I\t%d\t", (int)( (isrnd) ? random()%count : i ));
+ cnt=1+random()%512;
+ while(cnt-->0)
+ fputc( symbols[ random()%symbolslen ], stdout);
+ fputc('\n', stdout);
+ }
} else if ( mode==MODE_SFX ) {
int cnt;
for(i=0;i<count;i++) {
}
- if ( was==0 )
+ if ( was==0 ) {
sizes[page->npointer]=size;
+ }
- for(i=0;i<page->npointer+1;i++) {
+ for(i=0;i<page->npointer+1;i++)
if ( i< start )
lfree-=sizes[i];
else
rfree-=sizes[i];
- }
while( 1 ) {
if ( lfree<0 ) {
+ start--;
lfree+=sizes[start];
rfree-=sizes[start];
- start--;
} else if ( rfree < 0 ) {
lfree-=sizes[start];
rfree+=sizes[start];
packLeafKV(db, &(tmp->page), *ptr, key, value);
else
packInternalKV(db, &(tmp->page), *ptr, key, pagenumber);
-
return TBT_OK;
}
}
if ( size <= page->page.freespace ) {
+ u_int32_t oldsize=page->page.freespace;
packLeafKV(db, &(page->page), ptr, key, value);
+ tassert( oldsize == page->page.freespace + size );
page->issynced=0;
} else {
rc = splitPage(db, page, &newright, &ptr, size, key, value, 0);
usage() {
puts(
"Usage:\n"
- "tbtreetest [ -c CACHESIZE ] [-r] [-k] [-f FILE] [-D | -L | -b | -i KEY -v VALUE [ -S strategynumber ] | -d KEY | -s KEY ] [-V]\n"
+ "tbtreetest [ -c CACHESIZE ] [-r] [-k] [-f FILE] [-D | -L | -b | -i KEY -v VALUE [ -S strategynumber ] | -d KEY | -s KEY ] [-V] [-q]\n"
);
exit(1);
}
int rc=0;
char *file="BTREE";
char *key=NULL, *val=NULL;
- int mode=0, verbose=0;
+ int mode=0, verbose=0, quietout=0;
opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
memset(&db, 0, sizeof(TBTree));
- while((i=getopt(argn,argv,"VbS:Dc:hrkf:i:v:d:s:L")) != EOF) {
+ while((i=getopt(argn,argv,"qVbS:Dc:hrkf:i:v:d:s:L")) != EOF) {
switch(i) {
+ case 'q':
+ quietout=1;
+ break;
case 'V':
verbose=1;
break;
}
if ( *buf == 'D' ) {
rc=TBTDelete(&db, &key);
- } else if ( (rc=TBTFind(&db, &key, &value))==TBT_OK ) {
+ } else if ( (rc=TBTFind(&db, &key, &value))==TBT_OK && quietout==0) {
if ( db.keylen )
printf("%d", *(int*)(key.value));
else