xref: /onnv-gate/usr/src/cmd/lvm/rpc.metamedd/med_hash.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1994, 2000 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*0Sstevel@tonic-gate 
29*0Sstevel@tonic-gate #include <string.h>
30*0Sstevel@tonic-gate #include <stdlib.h>
31*0Sstevel@tonic-gate #include <stdio.h>
32*0Sstevel@tonic-gate #include "med_hash.h"
33*0Sstevel@tonic-gate #include "med_local.h"
34*0Sstevel@tonic-gate 
35*0Sstevel@tonic-gate #ifdef _KERNEL
36*0Sstevel@tonic-gate #define	memmove(a, b, c)		bcopy(b, a, c)
37*0Sstevel@tonic-gate #define	memcmp				bcmp
38*0Sstevel@tonic-gate #define	memset(a, '\0', c)		bzero(a, c)
39*0Sstevel@tonic-gate #define	Malloc				bkmem_alloc
40*0Sstevel@tonic-gate #endif	/* _KERNEL */
41*0Sstevel@tonic-gate 
42*0Sstevel@tonic-gate #define	VERIFY_HASH_REALLOC
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate static int
BCMP(void * str1,void * str2,int len)45*0Sstevel@tonic-gate BCMP(void *str1, void *str2, int len)
46*0Sstevel@tonic-gate {
47*0Sstevel@tonic-gate 	return (memcmp((char *)str1, (char *)str2, len));
48*0Sstevel@tonic-gate }
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate static int
HASH(void * datap,int datalen,int hsz)51*0Sstevel@tonic-gate HASH(void *datap, int datalen, int hsz)
52*0Sstevel@tonic-gate {
53*0Sstevel@tonic-gate 	char		*cp;
54*0Sstevel@tonic-gate 	int		hv = 0;
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate 	for (cp = (char *)datap; cp != ((char *)datap + datalen); hv += *cp++)
57*0Sstevel@tonic-gate 		;
58*0Sstevel@tonic-gate 	return (hv % hsz);
59*0Sstevel@tonic-gate }
60*0Sstevel@tonic-gate 
61*0Sstevel@tonic-gate int
init_cache(Cache ** cp,int hsz,int bsz,int (* hfunc)(void *,int,int),int (* cfunc)(void *,void *,int),void (* kffunc)(void *),void (* dffunc)(void *))62*0Sstevel@tonic-gate init_cache(
63*0Sstevel@tonic-gate 	Cache	**cp,
64*0Sstevel@tonic-gate 	int	hsz,
65*0Sstevel@tonic-gate 	int	bsz,
66*0Sstevel@tonic-gate 	int	(*hfunc)(void *, int, int),
67*0Sstevel@tonic-gate 	int	(*cfunc)(void *, void *, int),
68*0Sstevel@tonic-gate 	void	(*kffunc)(void *),
69*0Sstevel@tonic-gate 	void	(*dffunc)(void *)
70*0Sstevel@tonic-gate )
71*0Sstevel@tonic-gate {
72*0Sstevel@tonic-gate 	int			i;
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate 	if ((*cp = (Cache *) Malloc(sizeof (**cp))) == NULL) {
75*0Sstevel@tonic-gate 		(void) fprintf(stderr, "Malloc(Cache **cp)");
76*0Sstevel@tonic-gate 		return (-1);
77*0Sstevel@tonic-gate 	}
78*0Sstevel@tonic-gate 	(*cp)->bp = (Bucket *) Malloc(sizeof (*(*cp)->bp) * hsz);
79*0Sstevel@tonic-gate 	if ((*cp)->bp == NULL) {
80*0Sstevel@tonic-gate 		(void) fprintf(stderr, "Malloc(Bucket cp->bp)");
81*0Sstevel@tonic-gate 		return (-1);
82*0Sstevel@tonic-gate 	}
83*0Sstevel@tonic-gate 	(*cp)->hsz = hsz;
84*0Sstevel@tonic-gate 	(*cp)->bsz = bsz;
85*0Sstevel@tonic-gate 	for (i = 0; i < (*cp)->hsz; i++) {
86*0Sstevel@tonic-gate 		(*cp)->bp[i].nent = 0;
87*0Sstevel@tonic-gate 		(*cp)->bp[i].nalloc = 0;
88*0Sstevel@tonic-gate 		(*cp)->bp[i].itempp = NULL;
89*0Sstevel@tonic-gate 	}
90*0Sstevel@tonic-gate 	/* Hash function */
91*0Sstevel@tonic-gate 	if (hfunc != (int (*)()) NULL)
92*0Sstevel@tonic-gate 		(*cp)->hfunc = hfunc;
93*0Sstevel@tonic-gate 	else
94*0Sstevel@tonic-gate 		(*cp)->hfunc = HASH;
95*0Sstevel@tonic-gate 
96*0Sstevel@tonic-gate 	/* Compare function */
97*0Sstevel@tonic-gate 	if (cfunc != (int (*)()) NULL)
98*0Sstevel@tonic-gate 		(*cp)->cfunc = cfunc;
99*0Sstevel@tonic-gate 	else
100*0Sstevel@tonic-gate 		(*cp)->cfunc = BCMP;
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	/* Key free function */
103*0Sstevel@tonic-gate 	if (kffunc != (void (*)()) NULL)
104*0Sstevel@tonic-gate 		(*cp)->kffunc = kffunc;
105*0Sstevel@tonic-gate 	else
106*0Sstevel@tonic-gate 		(*cp)->kffunc = Free;
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	/* Data free function */
109*0Sstevel@tonic-gate 	if (dffunc != (void (*)()) NULL)
110*0Sstevel@tonic-gate 		(*cp)->dffunc = dffunc;
111*0Sstevel@tonic-gate 	else
112*0Sstevel@tonic-gate 		(*cp)->dffunc = Free;
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate 	return (0);
115*0Sstevel@tonic-gate }
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate int
add_cache(Cache * cp,Item * itemp)118*0Sstevel@tonic-gate add_cache(Cache *cp, Item *itemp)
119*0Sstevel@tonic-gate {
120*0Sstevel@tonic-gate 	Bucket			*bp;
121*0Sstevel@tonic-gate 	Item			**titempp;
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 	if (cp == NULL) {
124*0Sstevel@tonic-gate 		(void) fprintf(stderr,
125*0Sstevel@tonic-gate 		    "add_cache(): init_cache() not called.\n");
126*0Sstevel@tonic-gate 		return (-1);
127*0Sstevel@tonic-gate 	}
128*0Sstevel@tonic-gate 
129*0Sstevel@tonic-gate 	bp = &cp->bp[(*cp->hfunc)(itemp->key, itemp->keyl, cp->hsz)];
130*0Sstevel@tonic-gate 	if (bp->nent >= bp->nalloc) {
131*0Sstevel@tonic-gate 		if (bp->nalloc == 0) {
132*0Sstevel@tonic-gate 			bp->itempp =
133*0Sstevel@tonic-gate 			    (Item **) Malloc(sizeof (*bp->itempp) * cp->bsz);
134*0Sstevel@tonic-gate 		} else {
135*0Sstevel@tonic-gate #ifdef	VERIFY_HASH_REALLOC
136*0Sstevel@tonic-gate 			(void) fprintf(stderr,
137*0Sstevel@tonic-gate 			    "realloc(%d) bucket=%d\n", bp->nalloc + cp->bsz,
138*0Sstevel@tonic-gate 			    (*cp->hfunc)(itemp->key, itemp->keyl, cp->hsz));
139*0Sstevel@tonic-gate #endif	/* VERIFY_HASH_REALLOC */
140*0Sstevel@tonic-gate 			titempp =
141*0Sstevel@tonic-gate 			    (Item **) Malloc(sizeof (*bp->itempp) *
142*0Sstevel@tonic-gate 			    (bp->nalloc + cp->bsz));
143*0Sstevel@tonic-gate 			if (titempp != NULL) {
144*0Sstevel@tonic-gate 				(void) memmove((char *)titempp,
145*0Sstevel@tonic-gate 				    (char *)bp->itempp,
146*0Sstevel@tonic-gate 				    (sizeof (*bp->itempp) * bp->nalloc));
147*0Sstevel@tonic-gate #ifdef _KERNEL
148*0Sstevel@tonic-gate 				bkmem_free(bp->itempp,
149*0Sstevel@tonic-gate 				    (sizeof (*bp->itempp) * bp->nalloc));
150*0Sstevel@tonic-gate #else	/* !_KERNEL */
151*0Sstevel@tonic-gate 				Free(bp->itempp);
152*0Sstevel@tonic-gate #endif	/* _KERNEL */
153*0Sstevel@tonic-gate 				bp->itempp = titempp;
154*0Sstevel@tonic-gate 			} else
155*0Sstevel@tonic-gate 				bp->itempp = NULL;
156*0Sstevel@tonic-gate 		}
157*0Sstevel@tonic-gate 		if (bp->itempp == NULL) {
158*0Sstevel@tonic-gate 			(void) fprintf(stderr,
159*0Sstevel@tonic-gate 			    "add_cache(): out of memory\n");
160*0Sstevel@tonic-gate 			return (-1);
161*0Sstevel@tonic-gate 		}
162*0Sstevel@tonic-gate 		bp->nalloc += cp->bsz;
163*0Sstevel@tonic-gate 	}
164*0Sstevel@tonic-gate 	bp->itempp[bp->nent] = itemp;
165*0Sstevel@tonic-gate 	bp->nent++;
166*0Sstevel@tonic-gate 	return (0);
167*0Sstevel@tonic-gate }
168*0Sstevel@tonic-gate 
169*0Sstevel@tonic-gate Item *
lookup_cache(Cache * cp,void * datap,int datalen)170*0Sstevel@tonic-gate lookup_cache(Cache *cp, void *datap, int datalen)
171*0Sstevel@tonic-gate {
172*0Sstevel@tonic-gate 	int			i;
173*0Sstevel@tonic-gate 	Bucket			*bp;
174*0Sstevel@tonic-gate 
175*0Sstevel@tonic-gate 	if (cp == NULL) {
176*0Sstevel@tonic-gate 		(void) fprintf(stderr,
177*0Sstevel@tonic-gate 		    "lookup_cache(): init_cache() not called.\n");
178*0Sstevel@tonic-gate 		return (Null_Item);
179*0Sstevel@tonic-gate 	}
180*0Sstevel@tonic-gate 
181*0Sstevel@tonic-gate 	bp = &cp->bp[(*cp->hfunc)(datap, datalen, cp->hsz)];
182*0Sstevel@tonic-gate 	for (i = 0; i < bp->nent; i++)
183*0Sstevel@tonic-gate 		if (!(*cp->cfunc)((void *)bp->itempp[i]->key, datap, datalen))
184*0Sstevel@tonic-gate 			    return (bp->itempp[i]);
185*0Sstevel@tonic-gate 	return (Null_Item);
186*0Sstevel@tonic-gate }
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate Item *
first_item(Cache * cp,int * bidx,int * iidx)189*0Sstevel@tonic-gate first_item(Cache *cp, int *bidx, int *iidx)
190*0Sstevel@tonic-gate {
191*0Sstevel@tonic-gate 	Item			*itemp = Null_Item;
192*0Sstevel@tonic-gate 
193*0Sstevel@tonic-gate 	if (cp == NULL) {
194*0Sstevel@tonic-gate 		(void) fprintf(stderr,
195*0Sstevel@tonic-gate 		    "first_item(): init_cache() not called.\n");
196*0Sstevel@tonic-gate 		return (Null_Item);
197*0Sstevel@tonic-gate 	}
198*0Sstevel@tonic-gate 
199*0Sstevel@tonic-gate 	for (*bidx = 0; *bidx < cp->hsz && (cp->bp[*bidx].nalloc == 0 ||
200*0Sstevel@tonic-gate 	    cp->bp[*bidx].nent == 0); (*bidx)++)
201*0Sstevel@tonic-gate 		/* void */;
202*0Sstevel@tonic-gate 
203*0Sstevel@tonic-gate 	if (*bidx < cp->hsz && cp->bp[*bidx].nent > 0) {
204*0Sstevel@tonic-gate 		itemp = cp->bp[*bidx].itempp[0];
205*0Sstevel@tonic-gate 		*iidx = 0;
206*0Sstevel@tonic-gate 	} else {
207*0Sstevel@tonic-gate 		*bidx = -1;
208*0Sstevel@tonic-gate 		*iidx = -1;
209*0Sstevel@tonic-gate 	}
210*0Sstevel@tonic-gate 	return (itemp);
211*0Sstevel@tonic-gate }
212*0Sstevel@tonic-gate 
213*0Sstevel@tonic-gate Item *
next_item(Cache * cp,int * bidx,int * iidx)214*0Sstevel@tonic-gate next_item(Cache *cp, int *bidx, int *iidx)
215*0Sstevel@tonic-gate {
216*0Sstevel@tonic-gate 	Item			*itemp = Null_Item;
217*0Sstevel@tonic-gate 
218*0Sstevel@tonic-gate 	if (cp == NULL) {
219*0Sstevel@tonic-gate 		(void) fprintf(stderr,
220*0Sstevel@tonic-gate 		    "next_item(): init_cache() not called.\n");
221*0Sstevel@tonic-gate 		return (Null_Item);
222*0Sstevel@tonic-gate 	}
223*0Sstevel@tonic-gate 
224*0Sstevel@tonic-gate 	if (*bidx < cp->hsz && *bidx >= 0) {
225*0Sstevel@tonic-gate 		if ((*iidx + 1) < cp->bp[*bidx].nent) {
226*0Sstevel@tonic-gate 			itemp = cp->bp[*bidx].itempp[++(*iidx)];
227*0Sstevel@tonic-gate 		} else {
228*0Sstevel@tonic-gate 			for (++(*bidx);
229*0Sstevel@tonic-gate 			    *bidx < cp->hsz && (cp->bp[*bidx].nalloc == 0 ||
230*0Sstevel@tonic-gate 			    cp->bp[*bidx].nent == 0);
231*0Sstevel@tonic-gate 			    (*bidx)++)
232*0Sstevel@tonic-gate 				/* void */;
233*0Sstevel@tonic-gate 			if (*bidx < cp->hsz && cp->bp[*bidx].nent > 0) {
234*0Sstevel@tonic-gate 				*iidx = 0;
235*0Sstevel@tonic-gate 				itemp = cp->bp[*bidx].itempp[(*iidx)++];
236*0Sstevel@tonic-gate 			} else {
237*0Sstevel@tonic-gate 				*bidx = -1;
238*0Sstevel@tonic-gate 				*iidx = -1;
239*0Sstevel@tonic-gate 			}
240*0Sstevel@tonic-gate 		}
241*0Sstevel@tonic-gate 	} else {
242*0Sstevel@tonic-gate 		*bidx = -1;
243*0Sstevel@tonic-gate 		*iidx = -1;
244*0Sstevel@tonic-gate 	}
245*0Sstevel@tonic-gate 	return (itemp);
246*0Sstevel@tonic-gate }
247*0Sstevel@tonic-gate 
248*0Sstevel@tonic-gate void
des_cache(Cache ** cpp)249*0Sstevel@tonic-gate des_cache(Cache **cpp)
250*0Sstevel@tonic-gate {
251*0Sstevel@tonic-gate 	Cache			*cp = *cpp;
252*0Sstevel@tonic-gate 	Bucket			*bp;
253*0Sstevel@tonic-gate 	Item			*itemp;
254*0Sstevel@tonic-gate 	int			i;
255*0Sstevel@tonic-gate 	int			j;
256*0Sstevel@tonic-gate 
257*0Sstevel@tonic-gate 	if (cp == NULL) {
258*0Sstevel@tonic-gate 		(void) fprintf(stderr,
259*0Sstevel@tonic-gate 		    "des_cache(): init_cache() not called.\n");
260*0Sstevel@tonic-gate 		return;
261*0Sstevel@tonic-gate 	}
262*0Sstevel@tonic-gate 
263*0Sstevel@tonic-gate 	for (i = 0; i < cp->hsz; i++) {
264*0Sstevel@tonic-gate 		bp = &cp->bp[i];
265*0Sstevel@tonic-gate 		if (bp->nalloc > 0) {
266*0Sstevel@tonic-gate 			for (j = 0; j < bp->nent; j++) {
267*0Sstevel@tonic-gate 				itemp = bp->itempp[j];
268*0Sstevel@tonic-gate 				if (itemp->key)
269*0Sstevel@tonic-gate 					(void) (*cp->kffunc)(itemp->key);
270*0Sstevel@tonic-gate 				if (itemp->data)
271*0Sstevel@tonic-gate 					(void) (*cp->dffunc)(itemp->data);
272*0Sstevel@tonic-gate 			}
273*0Sstevel@tonic-gate 		}
274*0Sstevel@tonic-gate 		(void) Free(bp->itempp);
275*0Sstevel@tonic-gate 	}
276*0Sstevel@tonic-gate 	(void) Free(cp->bp);
277*0Sstevel@tonic-gate 	(void) Free(cp);
278*0Sstevel@tonic-gate 	*cpp = NULL;
279*0Sstevel@tonic-gate }
280*0Sstevel@tonic-gate 
281*0Sstevel@tonic-gate int
del_cache(Cache * cp,Item * itemp)282*0Sstevel@tonic-gate del_cache(Cache *cp, Item *itemp)
283*0Sstevel@tonic-gate {
284*0Sstevel@tonic-gate 	Bucket			*bp;
285*0Sstevel@tonic-gate 	int			bidx;
286*0Sstevel@tonic-gate 	int			iidx;
287*0Sstevel@tonic-gate 	int			tidx;
288*0Sstevel@tonic-gate 	int			retval = 0;
289*0Sstevel@tonic-gate 	void			*datap = itemp->key;
290*0Sstevel@tonic-gate 	int			datalen = itemp->keyl;
291*0Sstevel@tonic-gate 	Item			*titemp;
292*0Sstevel@tonic-gate 
293*0Sstevel@tonic-gate 	if (cp == NULL) {
294*0Sstevel@tonic-gate 		(void) fprintf(stderr,
295*0Sstevel@tonic-gate 		    "del_cache(): init_cache() not called.\n");
296*0Sstevel@tonic-gate 		return (-1);
297*0Sstevel@tonic-gate 	}
298*0Sstevel@tonic-gate 
299*0Sstevel@tonic-gate 	bidx = (*cp->hfunc)(datap, datalen, cp->hsz);
300*0Sstevel@tonic-gate 	bp = &cp->bp[bidx];
301*0Sstevel@tonic-gate 
302*0Sstevel@tonic-gate 	for (iidx = 0; iidx < bp->nent; iidx++)
303*0Sstevel@tonic-gate 		if (!(*cp->cfunc)((void *)bp->itempp[iidx]->key, datap,
304*0Sstevel@tonic-gate 		    datalen)) {
305*0Sstevel@tonic-gate 			titemp = bp->itempp[iidx];
306*0Sstevel@tonic-gate 			break;
307*0Sstevel@tonic-gate 		}
308*0Sstevel@tonic-gate 	if (iidx < bp->nent) {
309*0Sstevel@tonic-gate 		if (titemp->key)
310*0Sstevel@tonic-gate 			(void) (*cp->kffunc)(titemp->key);
311*0Sstevel@tonic-gate 		if (titemp->data)
312*0Sstevel@tonic-gate 			(void) (*cp->dffunc)(titemp->data);
313*0Sstevel@tonic-gate 		titemp->keyl = 0;
314*0Sstevel@tonic-gate 		titemp->datal = 0;
315*0Sstevel@tonic-gate 		bp->nent--;
316*0Sstevel@tonic-gate 		if (bp->nent == 0) {
317*0Sstevel@tonic-gate 			(void) Free(bp->itempp);
318*0Sstevel@tonic-gate 			bp->itempp = NULL;
319*0Sstevel@tonic-gate 			bp->nalloc = 0;
320*0Sstevel@tonic-gate 		} else {
321*0Sstevel@tonic-gate 			for (tidx = iidx + 1; tidx < (bp->nent + 1); tidx++) {
322*0Sstevel@tonic-gate 				bp->itempp[iidx] = bp->itempp[tidx];
323*0Sstevel@tonic-gate 				iidx = tidx;
324*0Sstevel@tonic-gate 			}
325*0Sstevel@tonic-gate 		}
326*0Sstevel@tonic-gate 	} else {
327*0Sstevel@tonic-gate 		(void) fprintf(stderr,
328*0Sstevel@tonic-gate 		    "del_cache(): item not found.\n");
329*0Sstevel@tonic-gate 		retval = -1;
330*0Sstevel@tonic-gate 	}
331*0Sstevel@tonic-gate 	return (retval);
332*0Sstevel@tonic-gate }
333*0Sstevel@tonic-gate 
334*0Sstevel@tonic-gate #ifdef DEBUG
335*0Sstevel@tonic-gate void
cache_stat(Cache * cp,char * tag)336*0Sstevel@tonic-gate cache_stat(Cache *cp, char *tag)
337*0Sstevel@tonic-gate {
338*0Sstevel@tonic-gate 	Bucket			*bp;
339*0Sstevel@tonic-gate 	int			bidx;
340*0Sstevel@tonic-gate 
341*0Sstevel@tonic-gate 	if (cp == NULL) {
342*0Sstevel@tonic-gate 		(void) fprintf(stderr,
343*0Sstevel@tonic-gate 		    "cache_stat(): init_cache() not called.\n");
344*0Sstevel@tonic-gate 		return;
345*0Sstevel@tonic-gate 	}
346*0Sstevel@tonic-gate 
347*0Sstevel@tonic-gate 	if (tag && *tag)
348*0Sstevel@tonic-gate 		(void) printf("%s", tag);
349*0Sstevel@tonic-gate 
350*0Sstevel@tonic-gate 	for (bidx = 0; bidx < cp->hsz; bidx++) {
351*0Sstevel@tonic-gate 		bp = &cp->bp[bidx];
352*0Sstevel@tonic-gate 		if (bp->nalloc > 0) {
353*0Sstevel@tonic-gate 			(void) printf("Bucket #%d Alloc %d", bidx, bp->nalloc);
354*0Sstevel@tonic-gate 			if (bp->nent > 0) {
355*0Sstevel@tonic-gate 				(void) printf(
356*0Sstevel@tonic-gate 				    " Entries %d Reallocs %d", bp->nent,
357*0Sstevel@tonic-gate 				    (bp->nalloc / cp->hsz));
358*0Sstevel@tonic-gate 				(void) printf(
359*0Sstevel@tonic-gate 				    " Utilization %d%%",
360*0Sstevel@tonic-gate 				    ((bp->nent * 100)/bp->nalloc));
361*0Sstevel@tonic-gate 			}
362*0Sstevel@tonic-gate 			(void) printf("\n");
363*0Sstevel@tonic-gate 			(void) fflush(stdout);
364*0Sstevel@tonic-gate 		}
365*0Sstevel@tonic-gate 	}
366*0Sstevel@tonic-gate }
367*0Sstevel@tonic-gate 
368*0Sstevel@tonic-gate void
pr_cache(Cache * cp,char * tag,void (* pfunc)(void *,int,void *,int))369*0Sstevel@tonic-gate pr_cache(Cache *cp, char *tag, void (*pfunc)(void *, int, void *, int))
370*0Sstevel@tonic-gate {
371*0Sstevel@tonic-gate 	int			bidx;
372*0Sstevel@tonic-gate 	int			iidx;
373*0Sstevel@tonic-gate 	Bucket			*bp;
374*0Sstevel@tonic-gate 	Item			*itemp;
375*0Sstevel@tonic-gate 
376*0Sstevel@tonic-gate 	if (cp == NULL) {
377*0Sstevel@tonic-gate 		(void) fprintf(stderr,
378*0Sstevel@tonic-gate 		    "pr_cache(): init_cache() not called.\n");
379*0Sstevel@tonic-gate 		return;
380*0Sstevel@tonic-gate 	}
381*0Sstevel@tonic-gate 
382*0Sstevel@tonic-gate 	if (tag && *tag)
383*0Sstevel@tonic-gate 		(void) printf("%s", tag);
384*0Sstevel@tonic-gate 
385*0Sstevel@tonic-gate 	for (bidx = 0; bidx < cp->hsz; bidx++) {
386*0Sstevel@tonic-gate 		bp = &cp->bp[bidx];
387*0Sstevel@tonic-gate 		if (bp->nent > 0)
388*0Sstevel@tonic-gate 			for (iidx = 0; iidx < bp->nent; iidx++) {
389*0Sstevel@tonic-gate 				itemp = bp->itempp[iidx];
390*0Sstevel@tonic-gate 				(*pfunc)(itemp->key, itemp->keyl,
391*0Sstevel@tonic-gate 				    itemp->data, itemp->datal);
392*0Sstevel@tonic-gate 			}
393*0Sstevel@tonic-gate 	}
394*0Sstevel@tonic-gate }
395*0Sstevel@tonic-gate #endif	/* DEBUG */
396