forked from ankurs/Hash-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
48 lines (46 loc) · 1.05 KB
/
main.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
#include<stdio.h>
#include "hashtable.h"
int main()
{
hash_table_t *table = hash_table_new(MODE_COPY);
int i = 1;
int val = 100;
int val2 = 200;
int j = 2;
int x =0;
for (x=0;x<3000;x++)
{
// use the macro
HT_ADD(table, &j, &val);
// or use the function
//hash_table_add(table, &j, i, (void *) &val, sizeof(int));
val++;
j++;
}
hash_table_add(table, &j, i, (void *) &val2, 1);
j--; j--;
hash_table_remove(table, &j, i);
HT_REMOVE(table, &j);
if (hash_table_has_key(table, &j, i))
{
printf("Key found %d\n", j);
}
else
{
printf("Key NOT found %d\n", j);
}
val = -100;
val2 = -200;
j--;
int *value = NULL;
value = (int* ) HT_LOOKUP(table, &j);
void** keys = NULL;
size_t num = hash_table_get_keys(table, keys);
printf("found %d keys\n", (int)num);
printf("j -> %d \n", j);
if (value)
printf("value is %d\n", *value);
else
printf("*value is %p\n", value);
return 0;
}