-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.c
39 lines (29 loc) · 1.01 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
#include <stdio.h>
#include <stdlib.h>
#include "ez_hash.h"
int usage(char* exename) {
printf("usage: %s bits(2-32) key value [key value]...\n", exename);
return(0);
};
int main(int argc, char *argv[]) {
ez_hash_table *my_hash;
char *key, *value;
int bits;
if (argc < 4) {usage(argv[0]); return 1;};
if ((argc % 2) !=0) {usage(argv[0]); return 1;};
bits = atoi(argv[1]);
if ((bits < 2) || (bits > 32)) {usage(argv[0]); return 1;};
if(!(my_hash = ez_hash_init(bits))) return 1;
printf("Hash table inited with %d bits\n\n", bits);
for (int i = 2; i <= (argc - 1); i += 2) {
key = argv[i];
value = argv[i + 1];
printf("setting %s %s. retval is %u\n", key, value, ez_hash_set(my_hash, key, value));
printf("Looking up %s returns %s\n", key, ez_hash_get(my_hash, key));
printf("Deleting %s returns %d\n", key, ez_hash_del(my_hash, key));
printf("Deleting %s again returns %d\n\n", key, ez_hash_del(my_hash, key));
}
printf("Freeing the hash table\n");
ez_hash_free(my_hash);
return 0;
}