Hash_PrintStats.c
2.44 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Hash_PrintStats.c --
*
* Source code for the Hash_PrintStats library procedure.
*
* Copyright 1988 Regents of the University of California
* Permission to use, copy, modify, and distribute this
* software and its documentation for any purpose and without
* fee is hereby granted, provided that the above copyright
* notice appear in all copies. The University of California
* makes no representations about the suitability of this
* software for any purpose. It is provided "as is" without
* express or implied warranty.
*/
#ifndef lint
static char rcsid[] = "$Header: /root/leakn64/depot/rf/sw/bbplayer/simos/apps/unix/ethersim/sun/Hash_PrintStats.c,v 1.1.1.1 2002/05/29 01:09:09 blythe Exp $ SPRITE (Berkeley)";
#endif not lint
#include <hash.h>
#include <list.h>
#include <stdio.h>
/*
*---------------------------------------------------------
*
* Hash_PrintStats --
*
* This routine calls a caller-supplied procedure to print
* statistics about the current bucket situation.
*
* Results:
* None.
*
* Side Effects:
* Proc gets called (potentially many times) to output information
* about the hash table. It must have the following calling sequence:
*
* void
* proc(clientData, string)
* ClientData clientData;
* char *string;
* {
* }
*
* In each call, clientData is the same as the clientData argument
* to this procedure, and string is a null-terminated string of
* characters to output.
*
*---------------------------------------------------------
*/
void
Hash_PrintStats(tablePtr, proc, clientData)
Hash_Table *tablePtr; /* Table for which to print info. */
void (*proc)(); /* Procedure to call to do actual
* I/O. */
{
int count[10], overflow, i, j;
char msg[100];
Hash_Entry *hashEntryPtr;
List_Links *hashList;
for (i=0; i<10; i++) {
count[i] = 0;
}
overflow = 0;
for (i = 0; i < tablePtr->size; i++) {
j = 0;
hashList = &(tablePtr->bucketPtr[i]);
LIST_FORALL(hashList, (List_Links *) hashEntryPtr) {
j++;
}
if (j < 10) {
count[j]++;
} else {
overflow++;
}
}
sprintf(msg, "Entries in table %d number of buckets %d\n",
tablePtr->numEntries, tablePtr->size);
(*proc)(clientData, msg);
for (i = 0; i < 10; i++) {
sprintf(msg, "Number of buckets with %d entries: %d.\n",
i, count[i]);
(*proc)(clientData, msg);
}
sprintf(msg, "Number of buckets with > 9 entries: %d.\n",
overflow);
(*proc)(clientData, msg);
}