distclean : clean
## cd example && make clean
- cd bros && make clean
rm -rf Makefile tcejdb.pc config.cache config.log config.status autom4te.cache
+++ /dev/null
-# Makefile for writing tests of DBM brothers
-
-
-
-#================================================================
-# Setting variables
-#================================================================
-
-
-# Generic settings
-SHELL = /bin/sh
-
-# Targets
-MYBINS = tctest qdbmtest ndbmtest sdbmtest gdbmtest tdbtest cdbtest bdbtest \
- maptest sqltest cmpsqltctest
-
-
-
-#================================================================
-# Suffix rules
-#================================================================
-
-
-.SUFFIXES :
-
-
-
-#================================================================
-# Actions
-#================================================================
-
-
-mesg :
- @echo "Here are writing tests of DBM brothers." 1>&2
- @echo "select a target of {all clean $(MYBINS)}." 1>&2
-
-
-all : $(MYBINS)
-
-
-clean :
- rm -rf $(MYBINS) *.o *.exe a.out casket* *~
-
-
-distclean : clean
-
-
-
-#================================================================
-# Building binaries
-#================================================================
-
-
-tctest : tctest.c
- LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.:.." ; PATH="$(PATH):.:.." ; \
- export LD_LIBRARY_PATH PATH ; ldflags=`tcucodec conf -l` ; \
- [ -z "$$ldflags" ] && \
- ldflags="-L/usr/local/lib -ltokyocabinet -lz -lpthread -lm -lc" ; \
- gcc -I.. -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ tctest.c \
- -static -L. -L.. $$ldflags
-
-
-qdbmtest : qdbmtest.c
- gcc -I.. -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ qdbmtest.c \
- -static -L.. -L/usr/local/lib -lqdbm -lz -lc
-
-
-ndbmtest : ndbmtest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ ndbmtest.c \
- -static -L/usr/local/lib -lndbm -lc
-
-
-sdbmtest : sdbmtest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ sdbmtest.c \
- -static -L/usr/local/lib -lsdbm -lc
-
-
-gdbmtest : gdbmtest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ gdbmtest.c \
- -static -L/usr/local/lib -lgdbm -lc
-
-
-tdbtest : tdbtest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ tdbtest.c \
- -static -L/usr/local/lib -ltdb -lc
-
-
-cdbtest : cdbtest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ cdbtest.c \
- -static -L/usr/local/lib -lcdb -lc
-
-
-bdbtest : bdbtest.c
- gcc -I/usr/local/bdb/include -D_GNU_SOURCE=1 \
- -Wall -O3 -o $@ bdbtest.c \
- -static -L/usr/local/bdb/lib -ldb -lpthread -lc
-
-
-maptest : maptest.cc
- LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.:.." ; PATH="$(PATH):.:.." ; \
- export LD_LIBRARY_PATH PATH ; ldflags=`tcucodec conf -l` ; \
- [ -z "$$ldflags" ] && \
- ldflags="-L/usr/local/lib -ltokyocabinet -lz -lpthread -lm -lc" ; \
- g++ -I.. -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -ansi -pedantic -O3 -o $@ maptest.cc \
- -static -L. -L.. -lstdc++ $$ldflags
-
-
-sqltest : sqltest.c
- gcc -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -O3 -o $@ sqltest.c \
- -static -L/usr/local/lib -lsqlite3 -lpthread -ldl -lc
-
-
-cmpsqltctest : cmpsqltctest.c
- LD_LIBRARY_PATH="$(LD_LIBRARY_PATH):.:.." ; PATH="$(PATH):.:.." ; \
- export LD_LIBRARY_PATH PATH ; ldflags=`tcucodec conf -l` ; \
- [ -z "$$ldflags" ] && \
- ldflags="-L/usr/local/lib -ltokyocabinet -lz -lpthread -lm -lc" ; \
- gcc -std=c99 -I.. -I/usr/local/include -D_GNU_SOURCE=1 \
- -Wall -pedantic -O3 -o $@ cmpsqltctest.c \
- -static -L. -L.. -lsqlite3 -lpthread -ldl $$ldflags
-
-
-
-# END OF FILE
+++ /dev/null
-/*************************************************************************************************
- * Writing test of Berkeley DB
- *************************************************************************************************/
-
-
-#include <db.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-#define SMALL_PAGESIZE 512 /* small page size */
-#define BIG_PAGESIZE 65536 /* maximum page size */
-#define BIG_CACHESIZE (rnum * 2 * 15) /* maximum cache size < avail mem. */
-#define SMALL_CACHESIZE (5 * 1048576) /* should be Btree fanout */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int runbtwrite(int argc, char **argv);
-int runbtread(int argc, char **argv);
-int myrand(void);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-int dobtwrite(char *name, int rnum, int rnd);
-int dobtread(char *name, int rnum, int rnd);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- srand48(1978);
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "btwrite")){
- rv = runbtwrite(argc, argv);
- } else if(!strcmp(argv[1], "btread")){
- rv = runbtread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Berkeley DB\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, " %s btwrite [-rnd] name rnum\n", progname);
- fprintf(stderr, " %s btread [-rnd] name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of btwrite command */
-int runbtwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtwrite(name, rnum, rnd);
- return rv;
-}
-
-
-/* parse arguments of btread command */
-int runbtread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtread(name, rnum, rnd);
- return rv;
-}
-
-
-/* pseudo random number generator */
-int myrand(void){
- static int cnt = 0;
- return (lrand48() + cnt++) & 0x7FFFFFFF;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- DB *dbp;
- DBT key, data;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(db_create(&dbp, NULL, 0) != 0){
- fprintf(stderr, "db_create failed\n");
- return 1;
- }
- if(dbp->set_pagesize(dbp, SMALL_PAGESIZE) != 0){
- fprintf(stderr, "DB->set_pagesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->set_cachesize(dbp, 0, BIG_CACHESIZE, 0) != 0){
- fprintf(stderr, "DB->set_cachesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->open(dbp, NULL, name, NULL, DB_HASH, DB_CREATE | DB_TRUNCATE, 00644) != 0){
- fprintf(stderr, "DB->open failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- err = FALSE;
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- key.data = buf;
- key.size = len;
- data.data = buf;
- data.size = len;
- if(dbp->put(dbp, NULL, &key, &data, 0) != 0){
- fprintf(stderr, "DB->put failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(dbp->close(dbp, 0) != 0){
- fprintf(stderr, "DB->close failed\n");
- err = TRUE;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- DB *dbp;
- DBT key, data;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(db_create(&dbp, NULL, 0) != 0){
- fprintf(stderr, "db_create failed\n");
- return 1;
- }
- if(dbp->set_cachesize(dbp, 0, BIG_CACHESIZE, 0) != 0){
- fprintf(stderr, "DB->set_cachesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->open(dbp, NULL, name, NULL, DB_HASH, DB_RDONLY, 00644) != 0){
- fprintf(stderr, "DB->open failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- err = FALSE;
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- key.data = buf;
- key.size = len;
- if(dbp->get(dbp, NULL, &key, &data, 0) != 0){
- fprintf(stderr, "DB->get failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(dbp->close(dbp, 0) != 0){
- fprintf(stderr, "DB->close failed\n");
- err = TRUE;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btwrite command */
-int dobtwrite(char *name, int rnum, int rnd){
- DB *dbp;
- DBT key, data;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(db_create(&dbp, NULL, 0) != 0){
- fprintf(stderr, "db_create failed\n");
- return 1;
- }
- if(dbp->set_pagesize(dbp, BIG_PAGESIZE) != 0){
- fprintf(stderr, "DB->set_pagesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->set_cachesize(dbp, 0, rnd ? BIG_CACHESIZE : SMALL_CACHESIZE, 0) != 0){
- fprintf(stderr, "DB->set_cachesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->open(dbp, NULL, name, NULL, DB_BTREE, DB_CREATE | DB_TRUNCATE, 00644) != 0){
- fprintf(stderr, "DB->open failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- err = FALSE;
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- key.data = data.data = buf;
- key.size = data.size = len;
- if(dbp->put(dbp, NULL, &key, &data, 0) != 0){
- fprintf(stderr, "DB->put failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(dbp->close(dbp, 0) != 0){
- fprintf(stderr, "DB->close failed\n");
- err = TRUE;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btread command */
-int dobtread(char *name, int rnum, int rnd){
- DB *dbp;
- DBT key, data;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(db_create(&dbp, NULL, 0) != 0){
- fprintf(stderr, "db_create failed\n");
- return 1;
- }
- if(dbp->set_cachesize(dbp, 0, rnd ? BIG_CACHESIZE : SMALL_CACHESIZE, 0) != 0){
- fprintf(stderr, "DB->set_cachesize failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- if(dbp->open(dbp, NULL, name, NULL, DB_BTREE, DB_RDONLY, 00644) != 0){
- fprintf(stderr, "DB->open failed\n");
- dbp->close(dbp, 0);
- return 1;
- }
- err = FALSE;
- memset(&key, 0, sizeof(key));
- memset(&data, 0, sizeof(data));
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- key.data = buf;
- key.size = len;
- if(dbp->get(dbp, NULL, &key, &data, 0) != 0){
- fprintf(stderr, "DB->get failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(dbp->close(dbp, 0) != 0){
- fprintf(stderr, "DB->close failed\n");
- err = TRUE;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <cdb.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Constant Database\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- struct cdb_make cdb;
- int i, fd, err, len;
- char buf[32];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if((fd = open(name, O_RDWR | O_CREAT | O_TRUNC, 0644)) == -1){
- perror("open");
- return 1;
- }
- if(cdb_make_start(&cdb, fd) == -1){
- perror("cdb_make_start");
- close(fd);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(cdb_make_add(&cdb, buf, len, buf, len) == -1){
- perror("cdb_add");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(cdb_make_finish(&cdb) == -1){
- perror("cdb_make_finish");
- close(fd);
- return 1;
- }
- if(close(fd) == -1){
- perror("close");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- struct cdb cdb;
- int i, fd, err, len;
- char buf[RECBUFSIZ], *val;
- if(showprgr) printf("<Reading Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if((fd = open(name, O_RDONLY, 0644)) == -1){
- perror("open");
- return 1;
- }
- cdb_init(&cdb, fd);
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* retrieve a record */
- len = sprintf(buf, "%08d", i);
- if(cdb_find(&cdb, buf, len) == 0){
- perror("cdb_find");
- err = TRUE;
- break;
- }
- len = cdb_datalen(&cdb);
- if(!(val = malloc(len + 1))){
- perror("malloc");
- err = TRUE;
- break;
- }
- cdb_read(&cdb, val, len, cdb_datapos(&cdb));
- free(val);
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- cdb_free(&cdb);
- if(close(fd) == -1){
- perror("close");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-/*************************************************************************************************
- * Comparison test of SQLite and Tokyo Cabinet
- *************************************************************************************************/
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/time.h>
-#include <assert.h>
-#include <sqlite3.h>
-#include <tctdb.h>
-
-#define SQLFILE "casket.sql"
-#define TCTFILE "casket.tct"
-#define SQLBUFSIZ 1024
-#define SAMPLENUM 10
-#define RECORDNUM 1000000
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-static void test_sqlite(void);
-static void test_tctdb(void);
-static int myrand(void);
-static int callback(void *opq, int argc, char **argv, char **colname);
-
-
-/* main routine */
-int main(int argc, char **argv){
- test_sqlite();
- test_tctdb();
- return 0;
-}
-
-
-/* perform SQLite test */
-static void test_sqlite(void){
- double sum = 0.0;
- for(int i = 1; i <= SAMPLENUM; i++){
- unlink(SQLFILE);
- sync(); sync();
- printf("SQLite write sample:%d ... ", i);
- fflush(stdout);
- double stime = tctime();
- sqlite3 *db;
- if(sqlite3_open(SQLFILE, &db) != 0) assert(!__LINE__);
- char sql[SQLBUFSIZ], *errmsg;
- sprintf(sql, "CREATE TABLE tbl ( k TEXT PRIMARY KEY, a TEXT, b INTEGER,"
- " c TEXT, d INTEGER );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- sprintf(sql, "CREATE INDEX tbl_s ON tbl ( a );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- sprintf(sql, "CREATE INDEX tbl_n ON tbl ( b );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- sprintf(sql, "PRAGMA cache_size = %d;", RECORDNUM);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- sprintf(sql, "BEGIN TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- for(int j = 1; j <= RECORDNUM; j++){
- sprintf(sql, "INSERT INTO tbl VALUES ( '%08d', '%08d', %d, '%08d', %d );",
- j, j, myrand() % RECORDNUM, myrand() % RECORDNUM, j);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- }
- sprintf(sql, "END TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- sqlite3_close(db);
- double etime = tctime() - stime;
- printf("%.6f\n", etime);
- sum += etime;
- }
- printf("SQLite write average: %.6f\n", sum / SAMPLENUM);
- sum = 0.0;
- for(int i = 1; i <= SAMPLENUM; i++){
- sync(); sync();
- printf("SQLite read sample:%d ... ", i);
- fflush(stdout);
- double stime = tctime();
- sqlite3 *db;
- if(sqlite3_open(SQLFILE, &db) != 0) assert(!__LINE__);
- char sql[SQLBUFSIZ], *errmsg;
- sprintf(sql, "PRAGMA cache_size = %d;", RECORDNUM);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- for(int j = 1; j <= RECORDNUM; j++){
- sprintf(sql, "SELECT * FROM tbl WHERE a = '%08d';", myrand() % RECORDNUM + 1);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK) assert(!__LINE__);
- }
- sqlite3_close(db);
- double etime = tctime() - stime;
- printf("%.6f\n", etime);
- sum += etime;
- }
- printf("SQLite read average: %.6f\n", sum / SAMPLENUM);
-}
-
-
-/* perform TCHDB test */
-static void test_tctdb(void){
- double sum = 0.0;
- for(int i = 1; i <= SAMPLENUM; i++){
- unlink(TCTFILE);
- sync(); sync();
- printf("TCTDB write sample:%d ... ", i);
- fflush(stdout);
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!tctdbtune(tdb, RECORDNUM * 2, -1, -1, 0)) assert(!__LINE__);
- if(!tctdbsetcache(tdb, 0, RECORDNUM, RECORDNUM)) assert(!__LINE__);
- if(!tctdbopen(tdb, TCTFILE, TDBOWRITER | TDBOCREAT | TDBOTRUNC)) assert(!__LINE__);
- if(!tctdbsetindex(tdb, "a", TDBITLEXICAL)) assert(!__LINE__);
- if(!tctdbsetindex(tdb, "b", TDBITDECIMAL)) assert(!__LINE__);
- if(!tctdbtranbegin(tdb)) assert(!__LINE__);
- char buf[SQLBUFSIZ];
- int size;
- for(int j = 1; j <= RECORDNUM; j++){
- TCMAP *cols = tcmapnew2(7);
- size = sprintf(buf, "%08d", j);
- tcmapput(cols, "a", 1, buf, size);
- size = sprintf(buf, "%d", myrand() % RECORDNUM);
- tcmapput(cols, "b", 1, buf, size);
- size = sprintf(buf, "%08d", myrand() % RECORDNUM);
- tcmapput(cols, "c", 1, buf, size);
- size = sprintf(buf, "%d", j);
- tcmapput(cols, "d", 1, buf, size);
- size = sprintf(buf, "%08d", j);
- if(!tctdbput(tdb, buf, size, cols)) assert(!__LINE__);
- tcmapdel(cols);
- }
- if(!tctdbtrancommit(tdb)) assert(!__LINE__);
- if(!tctdbclose(tdb)) assert(!__LINE__);
- tctdbdel(tdb);
- double etime = tctime() - stime;
- printf("%.6f\n", etime);
- sum += etime;
- }
- printf("TCTDB write average: %.6f\n", sum / SAMPLENUM);
- sum = 0.0;
- for(int i = 1; i <= SAMPLENUM; i++){
- sync(); sync();
- printf("TCTDB read sample:%d ... ", i);
- fflush(stdout);
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!tctdbsetcache(tdb, 0, RECORDNUM, RECORDNUM)) assert(!__LINE__);
- if(!tctdbopen(tdb, TCTFILE, TDBOREADER)) assert(!__LINE__);
- char buf[SQLBUFSIZ];
- for(int j = 1; j <= RECORDNUM; j++){
- TDBQRY *qry = tctdbqrynew(tdb);
- sprintf(buf, "%08d", myrand() % RECORDNUM + 1);
- tctdbqryaddcond(qry, "a", TDBQCSTREQ, buf);
- TCLIST *res = tctdbqrysearch(qry);
- for(int k = 0; k < tclistnum(res); k++){
- int ksiz;
- const char *kbuf = tclistval(res, k, &ksiz);
- TCMAP *cols = tctdbget(tdb, kbuf, ksiz);
- if(!cols) assert(!__LINE__);
- tcmapdel(cols);
- }
- tclistdel(res);
- tctdbqrydel(qry);
- }
- if(!tctdbclose(tdb)) assert(!__LINE__);
- double etime = tctime() - stime;
- printf("%.6f\n", etime);
- sum += etime;
- }
- printf("TCTDB read average: %.6f\n", sum / SAMPLENUM);
-}
-
-
-/* generate a random number */
-static int myrand(void){
- static int cnt = 0;
- return (lrand48() + cnt++) & 0x7FFFFFFF;
-}
-
-
-/* iterator of SQLite */
-static int callback(void *opq, int argc, char **argv, char **colname){
- return 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-/*************************************************************************************************
- * Writing test of GNU Database Manager
- *************************************************************************************************/
-
-
-#include <gdbm.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-#define CACHESIZE 16 /* cache size */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for GNU Database Manager\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- GDBM_FILE dbf;
- datum key, content;
- int i, err, optval, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(dbf = gdbm_open(name, 0, GDBM_NEWDB, 00644, NULL))){
- fprintf(stderr, "gdbm_open failed\n");
- return 1;
- }
- optval = CACHESIZE;
- if(gdbm_setopt(dbf, GDBM_CACHESIZE, &optval, sizeof(int)) != 0){
- fprintf(stderr, "gdbm_setopt failed\n");
- gdbm_close(dbf);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- content.dptr = buf;
- content.dsize = len;
- /* store a record */
- if(gdbm_store(dbf, key, content, GDBM_REPLACE) != 0){
- fprintf(stderr, "gdbm_store failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- gdbm_close(dbf);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- GDBM_FILE dbf;
- datum key, content;
- int i, err, optval, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(dbf = gdbm_open(name, 0, GDBM_READER, 00644, NULL))){
- fprintf(stderr, "gdbm_open failed\n");
- return 1;
- }
- optval = CACHESIZE;
- if(gdbm_setopt(dbf, GDBM_CACHESIZE, &optval, sizeof(int)) != 0){
- fprintf(stderr, "gdbm_setopt failed\n");
- gdbm_close(dbf);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* retrieve a record */
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- content = gdbm_fetch(dbf, key);
- if(!content.dptr){
- fprintf(stderr, "gdbm_fetch failed\n");
- err = TRUE;
- break;
- }
- free(content.dptr);
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- gdbm_close(dbf);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-#! /usr/bin/perl
-
-#================================================================
-# mapreporter
-# Measure elapsed time of map utilities
-#================================================================
-
-use strict;
-use warnings;
-use Time::HiRes qw(gettimeofday);
-
-use constant {
- RECNUM => 1000000,
- TESTCOUNT => 20,
- REMOVETOP => 2,
- REMOVEBOTTOM => 8,
-};
-
-my @commands = (
- "./maptest tcmap " . RECNUM,
- "./maptest tctree " . RECNUM,
- "./maptest stlmap " . RECNUM,
- "./maptest stlmmap " . RECNUM,
- "./maptest stlset " . RECNUM,
- "./maptest gnuhash " . RECNUM,
- "./maptest ggldh " . RECNUM,
- "./maptest gglsh " . RECNUM,
- "./maptest tcmap -rd " . RECNUM,
- "./maptest tctree -rd " . RECNUM,
- "./maptest stlmap -rd " . RECNUM,
- "./maptest stlmmap -rd " . RECNUM,
- "./maptest stlset -rd " . RECNUM,
- "./maptest gnuhash -rd " . RECNUM,
- "./maptest ggldh -rd " . RECNUM,
- "./maptest gglsh -rd " . RECNUM,
- );
-
-my @table;
-foreach my $command (@commands){
- system("sync ; sync");
- my @result;
- for(my $i = 0; $i < TESTCOUNT; $i++){
- my $stime = gettimeofday();
- system("$command >/dev/null 2>&1");
- $stime = gettimeofday() - $stime;
- printf("%s\t%d\t%0.5f\n", $command, $i + 1, $stime);
- push(@result, $stime);
- }
- @result = sort { $a <=> $b } @result;
- for(my $i = 0; $i < REMOVETOP; $i++){
- shift(@result);
- }
- for(my $i = 0; $i < REMOVEBOTTOM; $i++){
- pop(@result);
- }
- my $sum = 0;
- foreach my $result (@result){
- $sum += $result;
- }
- my $avg = $sum / scalar(@result);
- push(@table, [$command, $avg]);
-}
-
-printf("\n\nRESULT\n");
-foreach my $row (@table){
- printf("%s\t%0.5f\n", $$row[0], $$row[1]);
-}
-printf("\n");
-
-
-
-# END OF FILE
+++ /dev/null
-/*************************************************************************************************
- * Writing test of map utilities
- *************************************************************************************************/
-
-
-#include <cstdio>
-#include <cstring>
-#include <cstdlib>
-#include <cstdarg>
-#include <tcutil.h>
-#include <map>
-#include <set>
-#include <tr1/unordered_map>
-#include <google/sparse_hash_map>
-#include <google/dense_hash_map>
-
-#define RECBUFSIZ 32 // buffer for records
-
-using namespace std;
-
-struct stringhash { // hash function for string
- size_t operator()(const string& str) const {
- const char *ptr = str.data();
- int size = str.size();
- size_t idx = 19780211;
- while(size--){
- idx = idx * 37 + *(uint8_t *)ptr++;
- }
- return idx;
- }
-};
-
-
-// aliases of template instances
-typedef map<string, string> stlmap;
-typedef multimap<string, string> stlmmap;
-typedef set<string> stlset;
-typedef tr1::unordered_map<string, string, stringhash> trhash;
-typedef google::dense_hash_map<string, string, stringhash> ggldh;
-typedef google::sparse_hash_map<string, string, stringhash> gglsh;
-
-
-// global variables
-const char *g_progname; // program name
-
-
-// function prototypes
-int main(int argc, char **argv);
-static void usage(void);
-static void iprintf(const char *format, ...);
-static int runtcmap(int argc, char **argv);
-static int runtctree(int argc, char **argv);
-static int runstlmap(int argc, char **argv);
-static int runstlmmap(int argc, char **argv);
-static int runstlset(int argc, char **argv);
-static int runtrhash(int argc, char **argv);
-static int runggldh(int argc, char **argv);
-static int rungglsh(int argc, char **argv);
-static int proctcmap(int rnum, bool rd);
-static int proctctree(int rnum, bool rd);
-static int procstlmap(int rnum, bool rd);
-static int procstlmmap(int rnum, bool rd);
-static int procstlset(int rnum, bool rd);
-static int proctrhash(int rnum, bool rd);
-static int procggldh(int rnum, bool rd);
-static int procgglsh(int rnum, bool rd);
-
-
-// main routine
-int main(int argc, char **argv){
- g_progname = argv[0];
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "tcmap")){
- rv = runtcmap(argc, argv);
- } else if(!strcmp(argv[1], "tctree")){
- rv = runtctree(argc, argv);
- } else if(!strcmp(argv[1], "stlmap")){
- rv = runstlmap(argc, argv);
- } else if(!strcmp(argv[1], "stlmmap")){
- rv = runstlmmap(argc, argv);
- } else if(!strcmp(argv[1], "stlset")){
- rv = runstlset(argc, argv);
- } else if(!strcmp(argv[1], "trhash")){
- rv = runtrhash(argc, argv);
- } else if(!strcmp(argv[1], "ggldh")){
- rv = runggldh(argc, argv);
- } else if(!strcmp(argv[1], "gglsh")){
- rv = rungglsh(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-// print the usage and exit
-static void usage(void){
- fprintf(stderr, "%s: speed checker of map utilities\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s tcmap [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s tctree [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s stlmap [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s stlmmap [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s stlset [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s trhash [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s ggldh [-rd] rnum\n", g_progname);
- fprintf(stderr, " %s gglsh [-rd] rnum\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-// print formatted information string and flush the buffer
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
-}
-
-
-// parse arguments of tcmap command
-static int runtcmap(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = proctcmap(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of tctree command
-static int runtctree(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = proctctree(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of stlmap command
-static int runstlmap(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = procstlmap(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of stlmmap command
-static int runstlmmap(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = procstlmmap(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of stlset command
-static int runstlset(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = procstlset(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of trhash command
-static int runtrhash(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = proctrhash(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of ggldh command
-static int runggldh(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = procggldh(rnum, rd);
- return rv;
-}
-
-
-// parse arguments of gglsh command
-static int rungglsh(int argc, char **argv){
- char *rstr = NULL;
- bool rd = false;
- for(int i = 2; i < argc; i++){
- if(!rstr && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rd")){
- rd = true;
- } else {
- usage();
- }
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!rstr) usage();
- int rnum = tcatoi(rstr);
- if(rnum < 1) usage();
- int rv = procgglsh(rnum, rd);
- return rv;
-}
-
-
-// perform tcmap command
-static int proctcmap(int rnum, bool rd){
- iprintf("<Tokyo Cabinet Map Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- TCMAP *mymap = tcmapnew2(rnum + 1);
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- tcmapput(mymap, buf, len, buf, len);
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- int vsiz;
- const void *vbuf = tcmapget(mymap, buf, len, &vsiz);
- if(!vbuf){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", tcmaprnum(mymap));
- tcmapdel(mymap);
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform tctree command
-static int proctctree(int rnum, bool rd){
- iprintf("<Tokyo Cabinet Tree Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- TCTREE *mytree = tctreenew();
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- tctreeput(mytree, buf, len, buf, len);
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- int vsiz;
- const void *vbuf = tctreeget(mytree, buf, len, &vsiz);
- if(!vbuf){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", tctreernum(mytree));
- tctreedel(mytree);
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform stlmap command
-static int procstlmap(int rnum, bool rd){
- iprintf("<STL Map Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- stlmap mymap;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(stlmap::value_type(buf, buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- stlmap::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform multimap command
-static int procstlmmap(int rnum, bool rd){
- iprintf("<STL Multi Map Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- stlmmap mymap;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(stlmmap::value_type(buf, buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- stlmmap::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform stlset command
-static int procstlset(int rnum, bool rd){
- iprintf("<STL Set Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- stlset mymap;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(stlset::value_type(buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- stlset::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform trhash command
-static int proctrhash(int rnum, bool rd){
- iprintf("<TR1 Hash Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- trhash mymap;
- mymap.rehash(rnum + 1);
- mymap.max_load_factor(1.0);
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(trhash::value_type(buf, buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- trhash::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform ggldh command
-static int procggldh(int rnum, bool rd){
- iprintf("<Google Dense Hash Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- ggldh mymap;
- mymap.set_empty_key("");
- mymap.resize(rnum + 1);
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(ggldh::value_type(buf, buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- ggldh::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-// perform gglsh command
-static int procgglsh(int rnum, bool rd){
- iprintf("<Google Sparse Hash Writing Test>\n rnum=%d rd=%d\n\n", rnum, rd);
- double stime = tctime();
- {
- gglsh mymap;
- mymap.resize(rnum + 1);
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- mymap.insert(gglsh::value_type(buf, buf));
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rd){
- double itime = tctime();
- iprintf("time: %.3f\n", itime - stime);
- stime = itime;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- sprintf(buf, "%08d", i);
- gglsh::const_iterator it = mymap.find(buf);
- if(it == mymap.end()){
- iprintf("not found\n");
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- iprintf("record number: %d\n", mymap.size());
- }
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("ok\n\n");
- return 0;
-}
-
-
-
-// END OF FILE
+++ /dev/null
-/*************************************************************************************************
- * Writing test of New Database Manager
- *************************************************************************************************/
-
-
-#include <ndbm.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for New Database Manager\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- DBM *db;
- datum key, content;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(db = dbm_open(name, O_RDWR | O_CREAT | O_TRUNC, 00644))){
- fprintf(stderr, "dbm_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- content.dptr = buf;
- content.dsize = len;
- /* store a record */
- if(dbm_store(db, key, content, DBM_REPLACE) < 0){
- fprintf(stderr, "dbm_store failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- dbm_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- DBM *db;
- datum key, content;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(db = dbm_open(name, O_RDONLY, 00644))){
- fprintf(stderr, "dbm_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* retrieve a record */
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- content = dbm_fetch(db, key);
- if(!content.dptr){
- fprintf(stderr, "dbm_fetch failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- dbm_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-/*************************************************************************************************
- * Writing test of Quick Database Manager
- *************************************************************************************************/
-
-
-#include <depot.h>
-#include <cabin.h>
-#include <villa.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int runbtwrite(int argc, char **argv);
-int runbtread(int argc, char **argv);
-int myrand(void);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-int dobtwrite(char *name, int rnum, int rnd);
-int dobtread(char *name, int rnum, int rnd);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- srand48(1978);
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "btwrite")){
- rv = runbtwrite(argc, argv);
- } else if(!strcmp(argv[1], "btread")){
- rv = runbtread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Quick Database Manager\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, " %s btwrite [-rnd] name rnum\n", progname);
- fprintf(stderr, " %s btread [-rnd] name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of btwrite command */
-int runbtwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtwrite(name, rnum, rnd);
- return rv;
-}
-
-
-/* parse arguments of btread command */
-int runbtread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtread(name, rnum, rnd);
- return rv;
-}
-
-
-/* pseudo random number generator */
-int myrand(void){
- static int cnt = 0;
- return (lrand48() + cnt++) & 0x7FFFFFFF;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- DEPOT *depot;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(depot = dpopen(name, DP_OWRITER | DP_OCREAT | DP_OTRUNC, rnum * 3))){
- fprintf(stderr, "dpopen failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(!dpput(depot, buf, len, buf, len, DP_DOVER)){
- fprintf(stderr, "dpput failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!dpclose(depot)){
- fprintf(stderr, "dpclose failed\n");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- DEPOT *depot;
- int i, err, len;
- char buf[RECBUFSIZ], vbuf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(depot = dpopen(name, DP_OREADER, -1))){
- fprintf(stderr, "dpopen failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(dpgetwb(depot, buf, len, 0, RECBUFSIZ, vbuf) == -1){
- fprintf(stderr, "dpget failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!dpclose(depot)){
- fprintf(stderr, "dpclose failed\n");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btwrite command */
-int dobtwrite(char *name, int rnum, int rnd){
- VILLA *villa;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(villa = vlopen(name, VL_OWRITER | VL_OCREAT | VL_OTRUNC, VL_CMPLEX))){
- fprintf(stderr, "vlopen failed\n");
- return 1;
- }
- if(rnd){
- vlsettuning(villa, 77, 256, rnum / 77, -1);
- } else {
- vlsettuning(villa, 101, 256, 16, 16);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- if(!vlput(villa, buf, len, buf, len, VL_DOVER)){
- fprintf(stderr, "vlput failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!vlclose(villa)){
- fprintf(stderr, "vlclose failed\n");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btread command */
-int dobtread(char *name, int rnum, int rnd){
- VILLA *villa;
- int i, err, len;
- const char *val;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(villa = vlopen(name, VL_OREADER, VL_CMPLEX))){
- fprintf(stderr, "vlopen failed\n");
- return 1;
- }
- if(rnd){
- vlsettuning(villa, 37, 200, rnum / 45, 512);
- } else {
- vlsettuning(villa, 101, 256, 16, 16);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- if(!(val = vlgetcache(villa, buf, len, NULL))){
- fprintf(stderr, "vlget failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!vlclose(villa)){
- fprintf(stderr, "vlclose failed\n");
- return 1;
- }
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-#! /usr/bin/perl
-
-#================================================================
-# reporter
-# Measure elapsed time and database size of DBM brothers
-#================================================================
-
-use strict;
-use warnings;
-use Time::HiRes qw(gettimeofday);
-
-use constant {
- RECNUM => 1000000,
- TESTCOUNT => 20,
- REMOVETOP => 2,
- REMOVEBOTTOM => 8,
-};
-
-my @commands = (
- './tctest write casket.tch ' . RECNUM,
- './tctest read casket.tch ' . RECNUM,
- './qdbmtest write casket.qdbh ' . RECNUM,
- './qdbmtest read casket.qdbh ' . RECNUM,
- './ndbmtest write casket.ndbh ' . RECNUM,
- './ndbmtest read casket.ndbh ' . RECNUM,
- './sdbmtest write casket.sdbh ' . RECNUM,
- './sdbmtest read casket.sdbh ' . RECNUM,
- './gdbmtest write casket.gdbh ' . RECNUM,
- './gdbmtest read casket.gdbh ' . RECNUM,
- './tdbtest write casket.tdbh ' . RECNUM,
- './tdbtest read casket.tdbh ' . RECNUM,
- './cdbtest write casket.cdbh ' . RECNUM,
- './cdbtest read casket.cdbh ' . RECNUM,
- './bdbtest write casket.bdbh ' . RECNUM,
- './bdbtest read casket.bdbh ' . RECNUM,
- './tctest btwrite casket.tcb ' . RECNUM,
- './tctest btread casket.tcb ' . RECNUM,
- './tctest btwrite -rnd casket.tcb_r ' . RECNUM,
- './tctest btread -rnd casket.tcb_r ' . RECNUM,
- './qdbmtest btwrite casket.qdbb ' . RECNUM,
- './qdbmtest btread casket.qdbb ' . RECNUM,
- './qdbmtest btwrite -rnd casket.qdbb_r ' . RECNUM,
- './qdbmtest btread -rnd casket.qdbb_r ' . RECNUM,
- './bdbtest btwrite casket.bdbb ' . RECNUM,
- './bdbtest btread casket.bdbb ' . RECNUM,
- './bdbtest btwrite -rnd casket.bdbb_r ' . RECNUM,
- './bdbtest btread -rnd casket.bdbb_r ' . RECNUM,
- './tctest flwrite casket.tcf ' . RECNUM,
- './tctest flread casket.tcf ' . RECNUM,
- );
-
-my @names = (
- 'casket.tch',
- 'casket.qdbh',
- 'casket.ndbh',
- 'casket.sdbh',
- 'casket.gdbh',
- 'casket.tdbh',
- 'casket.cdbh',
- 'casket.bdbh',
- 'casket.tcb',
- 'casket.tcb_r',
- 'casket.qdbb',
- 'casket.qdbb_r',
- 'casket.bdbb',
- 'casket.bdbb_r',
- 'casket.tcf',
- );
-
-foreach my $name (@names){
- my @paths = glob("$name*");
- foreach my $path (@paths){
- unlink($path);
- }
-}
-
-my @table;
-foreach my $command (@commands){
- system('sync ; sync');
- $ENV{'HIDEPRGR'} = 1;
- my @result;
- for(my $i = 0; $i < TESTCOUNT; $i++){
- my $stime = gettimeofday();
- system("$command >/dev/null 2>&1");
- $stime = gettimeofday() - $stime;
- printf("%s\t%d\t%0.5f\n", $command, $i + 1, $stime);
- push(@result, $stime);
- }
- @result = sort { $a <=> $b } @result;
- for(my $i = 0; $i < REMOVETOP; $i++){
- shift(@result);
- }
- for(my $i = 0; $i < REMOVEBOTTOM; $i++){
- pop(@result);
- }
- my $sum = 0;
- foreach my $result (@result){
- $sum += $result;
- }
- my $avg = $sum / scalar(@result);
- push(@table, [$command, $avg]);
-}
-
-printf("\n\nRESULT\n\n");
-foreach my $row (@table){
- printf("%s\t%0.5f\n", $$row[0], $$row[1]);
-}
-printf("\n");
-
-my @sizes;
-foreach my $name (@names){
- my @paths = glob("$name*");
- my $sum = 0;
- foreach my $path (@paths){
- my @sbuf = stat($path);
- $sum += $sbuf[7];
- }
- printf("%s\t%s\n", $name, $sum);
- push(@sizes, $sum);
-}
-printf("\n");
-
-printf("%s,%.5f,%.5f,%d\n", "TC", $table[0][1], $table[1][1], $sizes[0]);
-printf("%s,%.5f,%.5f,%d\n", "QDBM", $table[2][1], $table[3][1], $sizes[1]);
-printf("%s,%.5f,%.5f,%d\n", "NDBM", $table[4][1], $table[5][1], $sizes[2]);
-printf("%s,%.5f,%.5f,%d\n", "SDBM", $table[6][1], $table[7][1], $sizes[3]);
-printf("%s,%.5f,%.5f,%d\n", "GDBM", $table[8][1], $table[9][1], $sizes[4]);
-printf("%s,%.5f,%.5f,%d\n", "TDB", $table[10][1], $table[11][1], $sizes[5]);
-printf("%s,%.5f,%.5f,%d\n", "CDB", $table[12][1], $table[13][1], $sizes[6]);
-printf("%s,%.5f,%.5f,%d\n", "BDB", $table[14][1], $table[15][1], $sizes[7]);
-printf("%s,%.5f,%.5f,%d\n", "TC-BT-ASC", $table[16][1], $table[17][1], $sizes[8]);
-printf("%s,%.5f,%.5f,%d\n", "TC-BT-RND", $table[18][1], $table[19][1], $sizes[9]);
-printf("%s,%.5f,%.5f,%d\n", "QDBM-BT-ASC", $table[20][1], $table[21][1], $sizes[10]);
-printf("%s,%.5f,%.5f,%d\n", "QDBM-BT-RND", $table[22][1], $table[23][1], $sizes[11]);
-printf("%s,%.5f,%.5f,%d\n", "BDB-BT-ASC", $table[24][1], $table[25][1], $sizes[12]);
-printf("%s,%.5f,%.5f,%d\n", "BDB-BT-RND", $table[26][1], $table[27][1], $sizes[13]);
-printf("%s,%.5f,%.5f,%d\n", "TC-FIXED", $table[28][1], $table[29][1], $sizes[14]);
-
-
-
-# END OF FILE
+++ /dev/null
-/*************************************************************************************************
- * Writing test of Substitute Database Manager
- *************************************************************************************************/
-
-
-#include <sdbm.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Substitute Database Manager\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- DBM *db;
- datum key, val;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(db = dbm_open(name, O_RDWR | O_CREAT | O_TRUNC, 00644))){
- fprintf(stderr, "dbm_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- val.dptr = buf;
- val.dsize = len;
- /* store a record */
- if(dbm_store(db, key, val, DBM_REPLACE) < 0){
- fprintf(stderr, "dbm_store failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- dbm_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- DBM *db;
- datum key, val;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(db = dbm_open(name, O_RDONLY, 00644))){
- fprintf(stderr, "dbm_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* retrieve a record */
- len = sprintf(buf, "%08d", i);
- key.dptr = buf;
- key.dsize = len;
- val = dbm_fetch(db, key);
- if(!val.dptr){
- fprintf(stderr, "dbm_fetch failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- dbm_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sqlite3.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 256 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int runtblwrite(int argc, char **argv);
-int runtblread(int argc, char **argv);
-int myrand(void);
-int callback(void *opq, int argc, char **argv, char **colname);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-int dotblwrite(char *name, int rnum);
-int dotblread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "tblwrite")){
- rv = runtblwrite(argc, argv);
- } else if(!strcmp(argv[1], "tblread")){
- rv = runtblread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for SQLite\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, " %s tblwrite name rnum\n", progname);
- fprintf(stderr, " %s tblread name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of tblwrite command */
-int runtblwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dotblwrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of tblread command */
-int runtblread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dotblread(name, rnum);
- return rv;
-}
-
-
-/* pseudo random number generator */
-int myrand(void){
- static int cnt = 0;
- return (lrand48() + cnt++) & 0x7FFFFFFF;
-}
-
-
-/* call back function for select statement */
-int callback(void *opq, int argc, char **argv, char **colname){
- return 0;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- sqlite3 *db;
- char sql[RECBUFSIZ], *errmsg;
- int i, err;
- if(showprgr) printf("<Writing Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- unlink(name);
- if(sqlite3_open(name, &db) != 0){
- fprintf(stderr, "sqlite3_open failed\n");
- return 1;
- }
- sprintf(sql, "CREATE TABLE tbl ( key TEXT PRIMARY KEY, val TEXT );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "PRAGMA cache_size = %d;", rnum);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "BEGIN TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- sprintf(sql, "INSERT INTO tbl VALUES ( '%08d', '%08d' );", i, i);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- err = TRUE;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- sprintf(sql, "END TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sqlite3_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- sqlite3 *db;
- char sql[RECBUFSIZ], *errmsg;
- int i, err;
- if(showprgr) printf("<Reading Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(sqlite3_open(name, &db) != 0){
- fprintf(stderr, "sqlite3_open failed\n");
- return 1;
- }
- sprintf(sql, "PRAGMA cache_size = %d;", rnum);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- sprintf(sql, "SELECT * FROM tbl WHERE key = '%08d';", i);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- err = TRUE;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- sqlite3_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform tblwrite command */
-int dotblwrite(char *name, int rnum){
- sqlite3 *db;
- char sql[RECBUFSIZ], *errmsg;
- int i, err;
- if(showprgr) printf("<Writing Test of Table>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- unlink(name);
- if(sqlite3_open(name, &db) != 0){
- fprintf(stderr, "sqlite3_open failed\n");
- return 1;
- }
- sprintf(sql, "CREATE TABLE tbl ( key INTEGER PRIMARY KEY, s TEXT, n INTEGER,"
- " t TEXT, f TEXT );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "CREATE INDEX tbl_s ON tbl ( s );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "CREATE INDEX tbl_n ON tbl ( n );");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "PRAGMA cache_size = %d;", rnum);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sprintf(sql, "BEGIN TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- sprintf(sql, "INSERT INTO tbl VALUES ( %d, '%08d', %d, '%08d', '%08d' );",
- i, i, myrand() % i, i, myrand() % rnum);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- sprintf(sql, "END TRANSACTION;");
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- sqlite3_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform tblread command */
-int dotblread(char *name, int rnum){
- sqlite3 *db;
- char sql[RECBUFSIZ], *errmsg;
- int i, err;
- if(showprgr) printf("<Reading Test of Table>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(sqlite3_open(name, &db) != 0){
- fprintf(stderr, "sqlite3_open failed\n");
- return 1;
- }
- sprintf(sql, "PRAGMA cache_size = %d;", rnum);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- sprintf(sql, "SELECT * FROM tbl WHERE key = '%08d';", i);
- if(sqlite3_exec(db, sql, callback, 0, &errmsg) != SQLITE_OK){
- fprintf(stderr, "sqlite3_exec failed: %s\n", errmsg);
- sqlite3_free(errmsg);
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- sqlite3_close(db);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-/*************************************************************************************************
- * Writing test of Tokyo Cabinet
- *************************************************************************************************/
-
-
-#include <tcutil.h>
-#include <tchdb.h>
-#include <tcbdb.h>
-#include <tcfdb.h>
-#include <tctdb.h>
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <string.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int runbtwrite(int argc, char **argv);
-int runbtread(int argc, char **argv);
-int runflwrite(int argc, char **argv);
-int runflread(int argc, char **argv);
-int runtblwrite(int argc, char **argv);
-int runtblread(int argc, char **argv);
-int myrand(void);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-int dobtwrite(char *name, int rnum, int rnd);
-int dobtread(char *name, int rnum, int rnd);
-int doflwrite(char *name, int rnum);
-int doflread(char *name, int rnum);
-int dotblwrite(char *name, int rnum);
-int dotblread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- srand48(1978);
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "btwrite")){
- rv = runbtwrite(argc, argv);
- } else if(!strcmp(argv[1], "btread")){
- rv = runbtread(argc, argv);
- } else if(!strcmp(argv[1], "flwrite")){
- rv = runflwrite(argc, argv);
- } else if(!strcmp(argv[1], "flread")){
- rv = runflread(argc, argv);
- } else if(!strcmp(argv[1], "tblwrite")){
- rv = runtblwrite(argc, argv);
- } else if(!strcmp(argv[1], "tblread")){
- rv = runtblread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Tokyo Cabinet\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, " %s btwrite [-rnd] name rnum\n", progname);
- fprintf(stderr, " %s btread [-rnd] name rnum\n", progname);
- fprintf(stderr, " %s flwrite name rnum\n", progname);
- fprintf(stderr, " %s flread name rnum\n", progname);
- fprintf(stderr, " %s tblwrite name rnum\n", progname);
- fprintf(stderr, " %s tblread name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of btwrite command */
-int runbtwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtwrite(name, rnum, rnd);
- return rv;
-}
-
-
-/* parse arguments of btread command */
-int runbtread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- if(!name && !strcmp(argv[i], "-rnd")){
- rnd = TRUE;
- } else {
- usage();
- }
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dobtread(name, rnum, rnd);
- return rv;
-}
-
-
-/* parse arguments of flwrite command */
-int runflwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doflwrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runflread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doflread(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of tblwrite command */
-int runtblwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dotblwrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of tblread command */
-int runtblread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rnd, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- rnd = FALSE;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dotblread(name, rnum);
- return rv;
-}
-
-
-/* pseudo random number generator */
-int myrand(void){
- static int cnt = 0;
- return (lrand48() + cnt++) & 0x7FFFFFFF;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- TCHDB *hdb;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- hdb = tchdbnew();
- tchdbtune(hdb, rnum * 3, 0, 0, 0);
- tchdbsetxmsiz(hdb, rnum * 48);
- if(!tchdbopen(hdb, name, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){
- fprintf(stderr, "tchdbopen failed\n");
- tchdbdel(hdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- fprintf(stderr, "tchdbputasync failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tchdbclose(hdb)){
- fprintf(stderr, "tchdbclose failed\n");
- tchdbdel(hdb);
- return 1;
- }
- tchdbdel(hdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- TCHDB *hdb;
- int i, err, len;
- char buf[RECBUFSIZ], vbuf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of Hash>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- hdb = tchdbnew();
- tchdbsetxmsiz(hdb, rnum * 48);
- if(!tchdbopen(hdb, name, HDBOREADER)){
- fprintf(stderr, "tchdbopen failed\n");
- tchdbdel(hdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(tchdbget3(hdb, buf, len, vbuf, RECBUFSIZ) == -1){
- fprintf(stderr, "tchdbget3 failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tchdbclose(hdb)){
- fprintf(stderr, "tchdbclose failed\n");
- tchdbdel(hdb);
- return 1;
- }
- tchdbdel(hdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btwrite command */
-int dobtwrite(char *name, int rnum, int rnd){
- TCBDB *bdb;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- bdb = tcbdbnew();
- if(rnd){
- tcbdbtune(bdb, 77, 256, -1, 0, 0, 0);
- tcbdbsetcache(bdb, rnum / 77, -1);
- } else {
- tcbdbtune(bdb, 101, 256, -1, 0, 0, 0);
- tcbdbsetcache(bdb, 256, 256);
- }
- tcbdbsetxmsiz(bdb, rnum * 32);
- if(!tcbdbopen(bdb, name, BDBOWRITER | BDBOCREAT | BDBOTRUNC)){
- fprintf(stderr, "tcbdbopen failed\n");
- tcbdbdel(bdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- if(!tcbdbput(bdb, buf, len, buf, len)){
- fprintf(stderr, "tcbdbput failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tcbdbclose(bdb)){
- fprintf(stderr, "tcbdbclose failed\n");
- tcbdbdel(bdb);
- return 1;
- }
- tcbdbdel(bdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform btread command */
-int dobtread(char *name, int rnum, int rnd){
- TCBDB *bdb;
- int i, err, len, vlen;
- const char *val;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of B+ Tree>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- bdb = tcbdbnew();
- if(rnd){
- tcbdbsetcache(bdb, rnum / 77 + 1, -1);
- } else {
- tcbdbsetcache(bdb, 256, 256);
- }
- tcbdbsetxmsiz(bdb, rnum * 32);
- if(!tcbdbopen(bdb, name, BDBOREADER)){
- fprintf(stderr, "tcbdbopen failed\n");
- tcbdbdel(bdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
- if(!(val = tcbdbget3(bdb, buf, len, &vlen))){
- fprintf(stderr, "tdbdbget3 failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tcbdbclose(bdb)){
- fprintf(stderr, "tcbdbclose failed\n");
- tcbdbdel(bdb);
- return 1;
- }
- tcbdbdel(bdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform flwrite command */
-int doflwrite(char *name, int rnum){
- TCFDB *fdb;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test of Fixed-Length>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- fdb = tcfdbnew();
- tcfdbtune(fdb, 8, 1024 + rnum * 9);
- if(!tcfdbopen(fdb, name, FDBOWRITER | FDBOCREAT | FDBOTRUNC)){
- fprintf(stderr, "tcfdbopen failed\n");
- tcfdbdel(fdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- len = sprintf(buf, "%08d", i);
- if(!tcfdbput(fdb, i, buf, len)){
- fprintf(stderr, "tcfdbput failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tcfdbclose(fdb)){
- fprintf(stderr, "tcfdbclose failed\n");
- tcfdbdel(fdb);
- return 1;
- }
- tcfdbdel(fdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform flread command */
-int doflread(char *name, int rnum){
- TCFDB *fdb;
- int i, err;
- char vbuf[RECBUFSIZ];
- if(showprgr) printf("<Reading Test of Fixed-length>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- fdb = tcfdbnew();
- if(!tcfdbopen(fdb, name, FDBOREADER)){
- fprintf(stderr, "tcfdbopen failed\n");
- tcfdbdel(fdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- if(tcfdbget4(fdb, i, vbuf, RECBUFSIZ) == -1){
- fprintf(stderr, "tcfdbget4 failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tcfdbclose(fdb)){
- fprintf(stderr, "tcfdbclose failed\n");
- tcfdbdel(fdb);
- return 1;
- }
- tcfdbdel(fdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform tblwrite command */
-int dotblwrite(char *name, int rnum){
- TCTDB *tdb;
- int i, err, pksiz, vsiz;
- char pkbuf[RECBUFSIZ], vbuf[RECBUFSIZ];
- TCMAP *cols;
- if(showprgr) printf("<Writing Test of Table>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- tdb = tctdbnew();
- tctdbtune(tdb, rnum * 3, 0, 0, 0);
- tctdbsetxmsiz(tdb, rnum * 80);
- tctdbsetcache(tdb, -1, rnum / 100, -1);
- if(!tctdbopen(tdb, name, TDBOWRITER | TDBOCREAT | TDBOTRUNC)){
- fprintf(stderr, "tctdbopen failed\n");
- tctdbdel(tdb);
- return 1;
- }
- if(!tctdbsetindex(tdb, "s", TDBITLEXICAL)){
- fprintf(stderr, "tctdbsetindex failed\n");
- tctdbdel(tdb);
- return 1;
- }
- if(!tctdbsetindex(tdb, "n", TDBITDECIMAL)){
- fprintf(stderr, "tctdbsetindex failed\n");
- tctdbdel(tdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* store a record */
- pksiz = sprintf(pkbuf, "%d", i);
- cols = tcmapnew2(7);
- vsiz = sprintf(vbuf, "%08d", i);
- tcmapput(cols, "s", 1, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%08d", myrand() % i);
- tcmapput(cols, "n", 1, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%08d", i);
- tcmapput(cols, "t", 1, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%08d", myrand() % rnum);
- tcmapput(cols, "f", 1, vbuf, vsiz);
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- fprintf(stderr, "tctdbput failed\n");
- err = TRUE;
- break;
- }
- tcmapdel(cols);
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tctdbclose(tdb)){
- fprintf(stderr, "tctdbclose failed\n");
- tctdbdel(tdb);
- return 1;
- }
- tctdbdel(tdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform tblread command */
-int dotblread(char *name, int rnum){
- TCTDB *tdb;
- int i, j, err, pksiz, rsiz;
- char pkbuf[RECBUFSIZ];
- const char *rbuf;
- TCMAP *cols;
- TDBQRY *qry;
- TCLIST *res;
- if(showprgr) printf("<Reading Test of Table>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- tdb = tctdbnew();
- tctdbsetxmsiz(tdb, rnum * 80);
- tctdbsetcache(tdb, -1, rnum / 100, -1);
- if(!tctdbopen(tdb, name, TDBOREADER)){
- fprintf(stderr, "tctdbopen failed\n");
- tctdbdel(tdb);
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- /* search for a record */
- pksiz = sprintf(pkbuf, "%08d", i);
- qry = tctdbqrynew(tdb);
- tctdbqryaddcond(qry, "s", TDBQCSTREQ, pkbuf);
- res = tctdbqrysearch(qry);
- for(j = 0; j < tclistnum(res); j++){
- rbuf = tclistval(res, j, &rsiz);
- cols = tctdbget(tdb, rbuf, rsiz);
- if(cols){
- tcmapdel(cols);
- } else {
- fprintf(stderr, "tctdbget failed\n");
- err = TRUE;
- break;
- }
- }
- tclistdel(res);
- tctdbqrydel(qry);
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- if(!tctdbclose(tdb)){
- fprintf(stderr, "tctdbclose failed\n");
- tctdbdel(tdb);
- return 1;
- }
- tctdbdel(tdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */
+++ /dev/null
-/*************************************************************************************************
- * Writing test of Trivial Database
- *************************************************************************************************/
-
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <tdb.h>
-
-#undef TRUE
-#define TRUE 1 /* boolean true */
-#undef FALSE
-#define FALSE 0 /* boolean false */
-
-#define RECBUFSIZ 32 /* buffer for records */
-
-
-/* global variables */
-const char *progname; /* program name */
-int showprgr; /* whether to show progression */
-
-
-/* function prototypes */
-int main(int argc, char **argv);
-void usage(void);
-int runwrite(int argc, char **argv);
-int runread(int argc, char **argv);
-int dowrite(char *name, int rnum);
-int doread(char *name, int rnum);
-
-
-/* main routine */
-int main(int argc, char **argv){
- int rv;
- progname = argv[0];
- showprgr = TRUE;
- if(getenv("HIDEPRGR")) showprgr = FALSE;
- if(argc < 2) usage();
- rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else {
- usage();
- }
- return rv;
-}
-
-
-/* print the usage and exit */
-void usage(void){
- fprintf(stderr, "%s: test cases for Trivial Database\n", progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write name rnum\n", progname);
- fprintf(stderr, " %s read name rnum\n", progname);
- fprintf(stderr, "\n");
- exit(1);
-}
-
-
-/* parse arguments of write command */
-int runwrite(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = dowrite(name, rnum);
- return rv;
-}
-
-
-/* parse arguments of read command */
-int runread(int argc, char **argv){
- char *name, *rstr;
- int i, rnum, rv;
- name = NULL;
- rstr = NULL;
- rnum = 0;
- for(i = 2; i < argc; i++){
- if(!name && argv[i][0] == '-'){
- usage();
- } else if(!name){
- name = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!name || !rstr) usage();
- rnum = atoi(rstr);
- if(rnum < 1) usage();
- rv = doread(name, rnum);
- return rv;
-}
-
-
-/* perform write command */
-int dowrite(char *name, int rnum){
- TDB_CONTEXT *tdb;
- TDB_DATA key, record;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(tdb = tdb_open(name, rnum * 2, 0, O_RDWR | O_CREAT | O_TRUNC, 00644))){
- fprintf(stderr, "tdb_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- len = sprintf(buf, "%08d", i);
- key.dptr = (unsigned char *)buf;
- key.dsize = len;
- record.dptr = (unsigned char *)buf;
- record.dsize = len;
- /* store a record */
- if(tdb_store(tdb, key, record, TDB_REPLACE) != 0){
- fprintf(stderr, "tdb_store failed\n");
- err = TRUE;
- break;
- }
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- tdb_close(tdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-/* perform read command */
-int doread(char *name, int rnum){
- TDB_CONTEXT *tdb;
- TDB_DATA key, record;
- int i, err, len;
- char buf[RECBUFSIZ];
- if(showprgr) printf("<Writing Test>\n name=%s rnum=%d\n\n", name, rnum);
- /* open a database */
- if(!(tdb = tdb_open(name, rnum * 2, 0, O_RDONLY, 00644))){
- fprintf(stderr, "tdb_open failed\n");
- return 1;
- }
- err = FALSE;
- /* loop for each record */
- for(i = 1; i <= rnum; i++){
- len = sprintf(buf, "%08d", i);
- key.dptr = (unsigned char *)buf;
- key.dsize = len;
- /* retrieve a record */
- record = tdb_fetch(tdb, key);
- if(!record.dptr){
- fprintf(stderr, "tdb_fetch failed\n");
- err = TRUE;
- break;
- }
- free(record.dptr);
- /* print progression */
- if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
- putchar('.');
- fflush(stdout);
- if(i == rnum || i % (rnum / 10) == 0){
- printf(" (%08d)\n", i);
- fflush(stdout);
- }
- }
- }
- /* close the database */
- tdb_close(tdb);
- if(showprgr && !err) printf("ok\n\n");
- return err ? 1 : 0;
-}
-
-
-
-/* END OF FILE */