-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn_hash_stats.c
63 lines (53 loc) · 1.5 KB
/
n_hash_stats.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "n_hash_int.h"
#include <stdio.h>
int n_hash_stats(const tn_hash *ht)
{
register size_t i, n = 0;
register struct hash_bucket *tmp;
int ncolls = 0;
int nempts = 0;
int maxdeep = 0;
int deepsum = 0;
int empty_len_sum = 0;
int empty_len_n = 0;
int empty_len = 0;
for (i = 0; i < ht->size; i++) {
int deep;
if (ht->table[i] == NULL) {
nempts++;
empty_len++;
continue;
}
if (empty_len > 6) {
empty_len_n++;
empty_len_sum += empty_len;
empty_len = 0;
}
deep = 1;
//if (ht->table[i]->next)
// printf("coll %s, ", ht->table[i]->key);
for (tmp = ht->table[i]->next; tmp != NULL; tmp = tmp->next) {
//printf("%s, ", tmp->key);
deep++;
}
//if (ht->table[i]->next)
// printf("\n");
if (deep > 1) {
ncolls++;
deepsum += deep;
}
if (deep > maxdeep)
maxdeep = deep;
}
printf("ht(%p): %lu slots (%d empty, avg empty len %d), %lu items, "
"%d collisions (avgdeep %.2lf, maxdep %d)\n",
ht, ht->size, nempts, empty_len_sum ? empty_len_sum / empty_len_n : 0,
ht->items, ncolls,
ncolls > 0 && deepsum > 0 ? deepsum/(ncolls * 1.0) : 0,
maxdeep);
// n_assert(0);
return n;
}