summary refs log tree commit diff
path: root/src/main.c
blob: aa156317e15c97f5fc7d01529ba1fc27d91bc61e (plain) (blame)
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
#include <stdio.h>
#include "hashtable.h"

int main(int argc, char** argv) {
	printf("Testing hashing:\n");

	HashTable ht = hashtable_init();

	char* res = (char*) hashtable_get(ht, "a");

	printf("Result: %s\n", res);

	hashtable_put(ht, "aa", (void*)"x");

	res = hashtable_get(ht, "aa");

	printf("Result: %s\n", res);

	hashtable_put(ht, "b", (void*)"1");

	printf("This should still be x\n");

	res = hashtable_get(ht, "aa");

	printf("Result: %s\n", res);

	res = hashtable_get(ht, "b");

	printf("Result: %s\n", res);

	hashtable_remove(ht, "b");

	res = hashtable_get(ht, "b");

	printf("Result: %s\n", res);
	
	struct test {
		int value;
	};

	struct test example = {
		.value = 7
	};
	
	hashtable_put(ht, "b", (void*)&example);

	struct test* res2 = hashtable_get(ht, "b");

	printf("Result: %d\n", res2->value);

	hashtable_deinit(&ht);

	return 0;
}