blob: 528fa906fc980fd9e558e1eff195cf06e87b0355 (
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
|
#include <malloc.h>
#include <string.h>
#include <algo.h>
// Hashing and comparing
hash_t id_hash_fun(const void* v) {
return (hash_t)v;
}
hash_t str_hash_fun(const void* v) {
hash_t h = 712;
for (char* s = (char*)v; *s != 0; s++) {
h = h * 101 + *s;
}
return h;
}
bool id_key_eq_fun(const void* a, const void* b) {
return a == b;
}
bool str_key_eq_fun(const void* a, const void* b) {
return strcmp((const char*)a, (const char*)b) == 0;
}
int id_key_cmp_fun(const void* a, const void* b) {
return (a == b ? 0 : (a < b ? -1 : 1));
}
int str_key_cmp_fun(const void* a, const void* b) {
return strcmp((const char*)a, (const char*)b);
}
// Freeing functions
void free_key(void* key, void* val) {
free(key);
}
void free_val(void* key, void* val) {
free(val);
}
void free_key_val(void* key, void* val) {
free(key);
free(val);
}
/* vim: set ts=4 sw=4 tw=0 noet :*/
|