From 3efda80a2ab84db53c1c0595492a03a94374cf56 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 18 Dec 2006 18:11:23 +0000 Subject: A second test for the new hash system. --- src/tests/hashtest2.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/tests/hashtest2.cpp (limited to 'src/tests/hashtest2.cpp') diff --git a/src/tests/hashtest2.cpp b/src/tests/hashtest2.cpp new file mode 100644 index 0000000..9ac75d5 --- /dev/null +++ b/src/tests/hashtest2.cpp @@ -0,0 +1,73 @@ +#include "hash.h" +#include + +typedef struct CC +{ + const char *sKey; + const char *sData; +} CC; + +char *c(const char *s) +{ + int l = strlen(s); + char *o = new char[l+1]; + o[l] = '\0'; + memcpy(o, s, l); + + return o; +} + +CC *mkCC(const char *k, const char *d) +{ + CC *o = new CC; + o->sKey = c(k); + o->sData = c(d); + return o; +} + +void klCC(CC *c) +{ + delete[] c->sKey; + delete[] c->sData; + delete c; +} + +typedef Hash CCHash; + +int main() +{ + char buf1[200]; + char buf2[200]; + CCHash h; + CC *tmp; + + for(int i=0;i<10;i++) + { + sprintf(buf1, "key_%d", i); + sprintf(buf2, "data_%d", i); + tmp = mkCC(buf1, buf2); + h[tmp->sKey] = tmp; + } + + for(int i=0;i<12;i++) + { + sprintf(buf1, "key_%d", i); + if(h.has(buf1)) + { + tmp = h[buf1]; + printf("GOT %s = %s\n", tmp->sKey, tmp->sData); + } + else + printf("%s is not in the table.\n", buf1); + } + + CCHash::iterator it = h.begin(); + for(;it!=h.end();it++) + { + tmp = (*it).second; + klCC(tmp); + } + + return 0; +} + -- cgit v1.2.3