aboutsummaryrefslogtreecommitdiff
path: root/src/tests/hashtest2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/hashtest2.cpp')
-rw-r--r--src/tests/hashtest2.cpp70
1 files changed, 6 insertions, 64 deletions
diff --git a/src/tests/hashtest2.cpp b/src/tests/hashtest2.cpp
index 9ac75d5..74700fd 100644
--- a/src/tests/hashtest2.cpp
+++ b/src/tests/hashtest2.cpp
@@ -1,72 +1,14 @@
1#include "hash.h" 1#include "hash.h"
2#include <string.h> 2#include <string.h>
3 3
4typedef struct CC
5{
6 const char *sKey;
7 const char *sData;
8} CC;
9
10char *c(const char *s)
11{
12 int l = strlen(s);
13 char *o = new char[l+1];
14 o[l] = '\0';
15 memcpy(o, s, l);
16
17 return o;
18}
19
20CC *mkCC(const char *k, const char *d)
21{
22 CC *o = new CC;
23 o->sKey = c(k);
24 o->sData = c(d);
25 return o;
26}
27
28void klCC(CC *c)
29{
30 delete[] c->sKey;
31 delete[] c->sData;
32 delete c;
33}
34
35typedef Hash<const char *, CC *> CCHash;
36
37int main() 4int main()
38{ 5{
39 char buf1[200]; 6 char *a, *b;
40 char buf2[200]; 7 a = new char[10];
41 CCHash h; 8 b = new char[10];
42 CC *tmp; 9 strcpy( a, "Hey there");
43 10 strcpy( b, "Hey there");
44 for(int i=0;i<10;i++) 11 printf("Same: %s\n", __cmpHashKeys( a, b )?"yes":"no");
45 {
46 sprintf(buf1, "key_%d", i);
47 sprintf(buf2, "data_%d", i);
48 tmp = mkCC(buf1, buf2);
49 h[tmp->sKey] = tmp;
50 }
51
52 for(int i=0;i<12;i++)
53 {
54 sprintf(buf1, "key_%d", i);
55 if(h.has(buf1))
56 {
57 tmp = h[buf1];
58 printf("GOT %s = %s\n", tmp->sKey, tmp->sData);
59 }
60 else
61 printf("%s is not in the table.\n", buf1);
62 }
63
64 CCHash::iterator it = h.begin();
65 for(;it!=h.end();it++)
66 {
67 tmp = (*it).second;
68 klCC(tmp);
69 }
70 12
71 return 0; 13 return 0;
72} 14}