-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn_hash_map.c
41 lines (32 loc) · 855 Bytes
/
n_hash_map.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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "n_hash_int.h"
int n_hash_map(const tn_hash *ht, void (*map_fn) (const char *, void *))
{
register size_t i, n = 0;
register struct hash_bucket *tmp;
for (i = 0; i < ht->size; i++) {
if (ht->table[i] == NULL)
continue;
for (tmp = ht->table[i]; tmp != NULL; tmp = tmp->next) {
map_fn(tmp->key, tmp->data);
n++;
}
}
return n;
}
int n_hash_dump(const tn_hash *ht)
{
register size_t i, n = 0;
register struct hash_bucket *tmp;
for (i = 0; i < ht->size; i++) {
if (ht->table[i] == NULL)
continue;
for (tmp = ht->table[i]; tmp != NULL; tmp = tmp->next) {
printf(" %s: %p\n", tmp->key, tmp->data);
n++;
}
}
return n;
}