-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
61 lines (54 loc) · 1.08 KB
/
test.c
File metadata and controls
61 lines (54 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "hash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void showMap(Map *m) {
for (int i = 0; i < m->cap; i++) {
int printed = 0;
for (Bucket* b = &m->buckets[i]; b; b=b->link) {
if (b->key) {
printed = 1;
printf("%s->", (char*)b->key);
}
}
if (printed) {
printf("\n");
}
}
printf("%d\n\n",m->size);
}
int main() {
Map* m = newStrMap(8192);
int x = m->key.hashCode("hello");
printf("%d\n", x);
mPut(m,"hello", "hi");
mPut(m,"bye", "byzies");
mPut(m, "a", "w");
mPut(m, "b", "x");
mPut(m, "c", "y");
mPut(m, "d", "z");
mPut(m, "d", "dead");
printf("%s\n", (char*)mGet(m,"hello"));
printf("%s\n", (char*)mGet(m,"bye"));
showMap(m);
mDel(m,"hello");
showMap(m);
mDel(m,"b");
showMap(m);
void* vals[m->size];
mGetKeys(m, vals);
for (int x = 0; x < m->size; x++) {
printf("%s is mapped to %s.\n", (char*) vals[x], (char*) mGet(m, vals[x]));
}
destroyMap(m);
return 0;
mDel(m,"d");
showMap(m);
mDel(m,"c");
showMap(m);
mDel(m,"a");
showMap(m);
mDel(m,"bye");
showMap(m);
printf("%zd\n", (size_t)mGet(m,"hello"));
}