Repositories » libk0
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

hstats() added to print some statistics for a hash table.

Changeset 11b21ecde58b

Parent 4c21d1817329

by Rup Palchowdhury

Changes to one file · Browse files at 11b21ecde58b Showing diff from parent 4c21d1817329 Diff from another changeset...

Change 1 of 1 Show Entire File khash.c Stacked
 
32
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -32,3 +32,28 @@
  }   return NULL;  } + +void hstats(Node *htab[], unsigned size) +{ + float fill, avglen; + int c, maxlen, sumlen, chainlen; + Node *np; + c = maxlen = sumlen = 0; + for (int i = 0; i < size; i++) { + if (htab[i] != NULL) { + c++; + chainlen = 0; + for (np = htab[i]; np != NULL; np = np->next) + chainlen++; + sumlen += chainlen; + if (chainlen > maxlen) maxlen = chainlen; + } + } + + fill = (float)c / (float)size * 100; + avglen = (float)sumlen / (float)c; + fprintf(stderr, "Fill: %5.2f%% (%d/%d)\n", fill, c, size); + fprintf(stderr, "Avg chain length: %5.2f\n", avglen); + fprintf(stderr, "Max chain length: %d\n", maxlen); + fprintf(stderr, "Node count: %d\n", sumlen); +}