Two programs to create and quickly query a read-only on disk hash table

This commit is contained in:
Sears Russell 2006-06-15 22:28:39 +00:00
parent 50515ffd23
commit 245db32c23
4 changed files with 77 additions and 1 deletions

View file

@ -1 +1 @@
SUBDIRS = cht #cyrus
SUBDIRS = cht readOnlyHash #cyrus

View file

@ -0,0 +1,3 @@
LDADD=$(top_builddir)/src/lladd/liblladd.a $(top_builddir)/src/libdfa/librw.a
bin_PROGRAMS=queryTable buildTable
AM_CFLAGS=-g -Wall -pedantic -std=gnu99

View file

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <lladd/transactional.h>
#include <lladd/truncation.h>
int main(int argc, char** argv) {
Tinit();
char * key;
char * value;
int ret;
int xid = Tbegin();
recordid hash = ThashCreate(xid, VARIABLE_LENGTH, VARIABLE_LENGTH);
// printf("rid = %d, %d, %lld\n", hash.page, hash.slot, hash.size);
assert(hash.page == 1 && hash.slot == 0 && hash.size == 48);
struct timeval start;
struct timeval now;
gettimeofday(&start,0);
int count = 0;
while(EOF != (ret=scanf("%as\t%as\n", &key, &value))) {
if(!ret) {
printf("Could not parse input!\n");
Tabort(xid);
Tdeinit();
}
//printf("->%s<-\t->%s<-\n", key, value);
ThashInsert(xid, hash, (byte*)key, strlen(key), (byte*)value, strlen(value));
errno = 0;
assert(errno == 0);
free(key);
free(value);
count ++;
if(!(count % 10000)) {
gettimeofday(&now,0);
double rate = ((double)count)/((double)(now.tv_sec-start.tv_sec));
printf("%d tuples inserted (%f per sec)\n", count, rate);
}
}
Tcommit(xid);
truncateNow();
Tdeinit();
return 0;
}

View file

@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <assert.h>
#include <string.h>
#include <lladd/transactional.h>
int main(int argc, char** argv) {
Tinit();
recordid hash = {1, 0, 48};
char * val;
if(-1 != ThashLookup(-1, hash, (byte*)argv[1], strlen(argv[1]), (byte**)&val)) {
printf("%s\n", val);
free(val);
}
Tdeinit();
return 0;
}