nhash.h revision 9781:ccf49524d5dc
1292932Sdim/*
2292932Sdim * CDDL HEADER START
3292932Sdim *
4292932Sdim * The contents of this file are subject to the terms of the
5292932Sdim * Common Development and Distribution License (the "License").
6292932Sdim * You may not use this file except in compliance with the License.
7292932Sdim *
8292932Sdim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9292932Sdim * or http://www.opensolaris.org/os/licensing.
10292932Sdim * See the License for the specific language governing permissions
11292932Sdim * and limitations under the License.
12292932Sdim *
13292932Sdim * When distributing Covered Code, include this CDDL HEADER in each
14292932Sdim * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15292932Sdim * If applicable, add the following below this CDDL HEADER, with the
16292932Sdim * fields enclosed by brackets "[]" replaced with your own identifying
17292932Sdim * information: Portions Copyright [yyyy] [name of copyright owner]
18292932Sdim *
19292932Sdim * CDDL HEADER END
20292932Sdim */
21292932Sdim
22292932Sdim/*
23292932Sdim * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24292932Sdim * Use is subject to license terms.
25292932Sdim */
26292932Sdim
27292932Sdim#ifndef _NHASH_H
28292932Sdim#define	_NHASH_H
29292932Sdim
30292932Sdim
31292932Sdim#ifdef __cplusplus
32292932Sdimextern "C" {
33292932Sdim#endif
34292932Sdim
35292932Sdim#ifndef NULL
36292932Sdim#define	NULL	0
37292932Sdim#endif	/* NULL */
38292932Sdim
39292932Sdimtypedef struct item_t {
40292932Sdim    void *key;
41292932Sdim    int	  keyl;
42292932Sdim    void *data;
43292932Sdim    int	  datal;
44292932Sdim} Item;
45292932Sdim
46292932Sdim#define	Null_Item ((Item *) NULL)
47292932Sdim
48292932Sdimtypedef struct bucket_t {
49292932Sdim	int nent;
50292932Sdim	int nalloc;
51292932Sdim	Item **itempp;
52292932Sdim} Bucket;
53292932Sdim
54292932Sdimtypedef struct cache_t {
55292932Sdim	int	hsz;
56292932Sdim	int	bsz;
57292932Sdim	Bucket *bp;
58292932Sdim	int (*hfunc)(void *, int, int);
59292932Sdim	int (*cfunc)(void *, void *, int);
60292932Sdim} Cache;
61292932Sdim
62292932Sdim#ifdef _KERNEL
63292932Sdim#define	malloc	bkmem_alloc
64292932Sdim#endif	/* _KERNEL */
65292932Sdim
66292932Sdimextern int init_cache(Cache **cp, int hsz, int bsz,
67292932Sdim	    int (*hfunc)(void *, int, int), int (*cfunc)(void *, void *, int));
68292932Sdimextern int add_cache(Cache *cp, Item *itemp);
69292932Sdimextern Item *lookup_cache(Cache *cp, void *datap, int datalen);
70292932Sdim
71292932Sdim#ifdef __cplusplus
72292932Sdim}
73292932Sdim#endif
74292932Sdim
75292932Sdim#endif /* _NHASH_H */
76292932Sdim