diff --git a/src/apps/Makefile.am b/src/apps/Makefile.am index 206dbf2..06c6009 100644 --- a/src/apps/Makefile.am +++ b/src/apps/Makefile.am @@ -1 +1 @@ -SUBDIRS = cht #cyrus +SUBDIRS = cht readOnlyHash #cyrus diff --git a/src/apps/readOnlyHash/Makefile.am b/src/apps/readOnlyHash/Makefile.am new file mode 100644 index 0000000..55aa198 --- /dev/null +++ b/src/apps/readOnlyHash/Makefile.am @@ -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 diff --git a/src/apps/readOnlyHash/buildTable.c b/src/apps/readOnlyHash/buildTable.c new file mode 100644 index 0000000..c79c9f2 --- /dev/null +++ b/src/apps/readOnlyHash/buildTable.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include +#include + +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; +} diff --git a/src/apps/readOnlyHash/queryTable.c b/src/apps/readOnlyHash/queryTable.c new file mode 100644 index 0000000..ea3afb4 --- /dev/null +++ b/src/apps/readOnlyHash/queryTable.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include + +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; +}