2 export LD_LIBRARY_PATH=/home/eric/dev/bacula/tcdb/lib/
3 g++ -I/home/eric/dev/bacula/tcdb/include -o tt -L /home/eric/dev/bacula/tcdb/lib/ -ltokyocabinet -lz -lpthread -lm tcdbtest.c
5 ./tt $(wc -l src.txt2) 0
21 #define NITEMS 5000000
30 int64_t get_current_time()
33 if (gettimeofday(&tv, NULL) != 0) {
34 tv.tv_sec = (long)time(NULL); /* fall back to old method */
37 return (int64_t)tv.tv_sec * 1000000 + (int64_t)tv.tv_usec;
40 int main(int argc, char **argv){
49 int64_t ctime, ttime;;
53 fprintf(stderr, "Usage: tt count file cache %i\n");
61 snprintf(result, sizeof(result), "result.%i", getpid());
62 res = fopen(result, "w");
64 /* create the object */
67 if (atoi(argv[3]) > 0) {
68 tchdbsetcache(hdb, atoi(argv[3]));
70 fprintf(res, "cache;%i\n", atoi(argv[3]));
73 * apow : 128 (size of stat hash field)
76 tchdbtune(hdb, atoll(argv[1]), 7, 16, opt);
77 fprintf(res, "bucket;%lli\n", atoll(argv[1]));
78 fprintf(res, "compress;%i\n", opt);
80 /* open the database */
81 if(!tchdbopen(hdb, "casket.hdb", HDBOWRITER | HDBOCREAT)){
82 ecode = tchdbecode(hdb);
83 fprintf(stderr, "open error: %s\n", tchdberrmsg(ecode));
86 ctime = get_current_time();
88 /* fill hash with real data (find / > src.txt) */
89 fp = fopen(argv[2], "r");
91 fprintf(stderr, "open %s file error\n", argv[2]);
94 while (fgets(line, sizeof(line), fp)) {
95 char *data = "A AAA B AZS SDSZ EZEZ SSDFS AEZEZEZ ZEZDSDDQe";
96 if (!tchdbputasync2(hdb, line, data)) {
97 ecode = tchdbecode(hdb);
98 fprintf(stderr, "put error: %s\n", tchdberrmsg(ecode));
101 strcpy(save_key, line);
106 ttime= get_current_time();
107 fprintf(res, "nbelt;%lli\n", i);
109 fprintf(stderr, "loading %i file into hash database in %ims\n",
110 i, (ttime - ctime)/1000);
111 fprintf(res, "load;%i\n", (ttime - ctime)/1000);
114 /* retrieve records */
115 value = tchdbget2(hdb, save_key);
117 //printf("%s:%s\n", save_key, value);
120 ecode = tchdbecode(hdb);
121 fprintf(stderr, "get error: %s\n", tchdberrmsg(ecode));
124 /* retrieve all records and mark them as seen */
126 fp = fopen(argv[2], "r");
128 fprintf(stderr, "open %s file error\n", argv[2]);
131 while (fgets(line, sizeof(line), fp)) {
132 char *data = "A AAA B AZS SDSZ EZEZ SSDFS AEZEZEZ ZEZDSDDQe";
134 value = tchdbget2(hdb, line);
137 if (!tchdbputasync2(hdb, line, value)) {
138 ecode = tchdbecode(hdb);
139 fprintf(stderr, "put error: %s\n", tchdberrmsg(ecode));
143 fprintf(stderr, "can't find %s in hash\n", line);
149 ctime = get_current_time();
150 fprintf(stderr, "marking as seen in %ims\n", (ctime - ttime)/1000);
151 fprintf(res, "seen;%i\n", (ctime - ttime)/1000);
153 /* traverse records */
155 while((key = tchdbiternext2(hdb)) != NULL){
156 value = tchdbget2(hdb, key);
158 //printf("%s:%s\n", key, value);
164 ttime = get_current_time();
165 fprintf(stderr, "checking not seen in %ims\n", (ttime - ctime)/1000);
166 fprintf(res, "walk;%i\n", (ttime - ctime)/1000);
168 /* close the database */
169 if(!tchdbclose(hdb)){
170 ecode = tchdbecode(hdb);
171 fprintf(stderr, "close error: %s\n", tchdberrmsg(ecode));
174 /* delete the object */
177 stat("casket.hdb", &statp);
178 fprintf(res, "size;%lli\n", statp.st_size);
179 unlink("casket.hdb");