-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.c
61 lines (40 loc) · 1.26 KB
/
example.c
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
59
60
61
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "hashmap.h"
char *makestring(int size, int range) {
char *query = malloc(sizeof(char) * (size + 1));
for (int i = 0; i < size; i++) {
query[i] = (char) ((rand() % (range + 1)) + 48);
}
query[size] = '\0';
return query;
}
void printObjectPayload(void *str) {
printf ("\t\tTest %s\n", (char *)str);
}
void destroyObject(void *str) {
free((char *)str);
}
int main() {
hashmap *mymap = make__hashmap(1, printObjectPayload, destroyObject);
srand(time(NULL));
char *someKeys = "123";
char *someRandomAllocatedValue = malloc(sizeof(char) * 5);
strcpy(someRandomAllocatedValue, "fun!");
insert__hashmap(mymap, someKeys, someRandomAllocatedValue);
char *someOtherRandomAllocatedValue = malloc(sizeof(char) * 5);
strcpy(someOtherRandomAllocatedValue, "test");
insert__hashmap(mymap, someKeys, someOtherRandomAllocatedValue);
char *aDifferentKey = "456";
char *aNewRandomAllocatedValue = malloc(sizeof(char) * 5);
strcpy(aNewRandomAllocatedValue, "play");
insert__hashmap(mymap, aDifferentKey, aNewRandomAllocatedValue);
print__hashmap(mymap);
delete__hashmap(mymap, someKeys);
printf("AFTER DELETION\n");
print__hashmap(mymap);
deepdestroy__hashmap(mymap);
return 0;
}