-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
33 lines (25 loc) · 824 Bytes
/
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
#include <stdio.h>
#include <stdlib.h>
#include "src/hash_table.h"
int main(int argc, char const* argv[]) {
// new hashtable
ht_hash_table* ht = ht_new();
// insert into hashtable
ht_insert(ht, "foo", "bar");
ht_insert(ht, "name", "ruofeng");
ht_insert(ht, "number", "41524226");
// search from hashtable
printf("%s\n", ht_search(ht, "foo"));
printf("%s\n", ht_search(ht, "name"));
// update test
ht_insert(ht, "foo", "barr");
printf("%s\n", ht_search(ht, "foo"));
// key not exsit test
if (ht_search(ht, "not") == NULL) printf("%s\n", "key(not) doesn't exist");
// delete key test
ht_delete(ht, "foo");
if (ht_search(ht, "foo") == NULL) printf("%s\n", "key(foo) doesn't exist");
// delete hash table
ht_del_hash_table(ht);
return 0;
}