From beb40fddfb7d6bd4d31f5d7a8ac5f362ed0878d6 Mon Sep 17 00:00:00 2001 From: teodor Date: Wed, 9 Feb 2005 09:43:41 +0000 Subject: [PATCH] New cache subsystem --- gendata.c | 27 +++++++++++++++++---------- tbtree.c | 11 ++++++----- tbtreetest.c | 11 +++++++---- 3 files changed, 30 insertions(+), 19 deletions(-) diff --git a/gendata.c b/gendata.c index c7f6a13..fc7f3c0 100644 --- a/gendata.c +++ b/gendata.c @@ -39,7 +39,7 @@ static void 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); } @@ -57,14 +57,17 @@ static int symbolslen=0; 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; @@ -87,13 +90,17 @@ main(int argn, char *argv[]) { if ( mode==MODE_BTREE ) { int cnt; - for(i=0;i0) - fputc( symbols[ random()%symbolslen ], stdout); - fputc('\n', stdout); - } + if ( isfind ) + for(i=0;i0) + fputc( symbols[ random()%symbolslen ], stdout); + fputc('\n', stdout); + } } else if ( mode==MODE_SFX ) { int cnt; for(i=0;inpointer]=size; + } - for(i=0;inpointer+1;i++) { + for(i=0;inpointer+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]; @@ -778,7 +778,6 @@ splitPage(TBTree *db, TBTMemPage *srcpage, TBTMemPage** newpage, TBTPointer **pt packLeafKV(db, &(tmp->page), *ptr, key, value); else packInternalKV(db, &(tmp->page), *ptr, key, pagenumber); - return TBT_OK; } @@ -825,7 +824,9 @@ layerInsert(TBTree *db, u_int32_t pagenumber, TBTMemPage **left, TBTMemPage **ri } 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); diff --git a/tbtreetest.c b/tbtreetest.c index a6e96db..a3779ca 100644 --- a/tbtreetest.c +++ b/tbtreetest.c @@ -41,7 +41,7 @@ static void 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); } @@ -104,14 +104,17 @@ main(int argn, char *argv[]) { 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; @@ -251,7 +254,7 @@ main(int argn, char *argv[]) { } 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 -- 2.46.1