shuttler/nessDB — pull request #21 by ooXavier (2011-12-16 22:34:33+00:00)
Title: Add 2 functions : db_get_all and db_drop

db_get_all can return all the key/values stored
db_drop remove all the files of the db

A combinaison of those two functions allow you to clean up the files to maintain a stable db size.

Example :
int main(int argc,char** argv)
{
int i, keys = 0;
const char *basedir = "/data/nessDB";
nessDB *db = db_init(DB_BUFFER, basedir);
dbLine *myDb = db_get_all(db, &keys);
db_destroy(db);
db_drop(basedir);
//printf("keys = %d\n", keys);

db = db_init(DB_BUFFER, basedir);
for(i=0; i < keys; i++) {
db_add(db, myDb[i].key, myDb[i].val);
//printf("%d - key=%s - value=%s\n", (int) i, myDb[i].key, myDb[i].val );
}
db_destroy(db);
free(myDb);
myDb = NULL;
return 0;
}

ooXavier