4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_MODHASH_IMPL_H
27 #define _SYS_MODHASH_IMPL_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 * Internal details for the kernel's generic hash implementation.
41 #include <sys/ksynch.h>
42 #include <sys/modhash.h>
44 struct mod_hash_entry
{
45 mod_hash_key_t mhe_key
; /* stored hash key */
46 mod_hash_val_t mhe_val
; /* stored hash value */
47 struct mod_hash_entry
*mhe_next
; /* next item in chain */
50 struct mod_hash_stat
{
51 ulong_t mhs_hit
; /* tried a 'find' and it succeeded */
52 ulong_t mhs_miss
; /* tried a 'find' but it failed */
53 ulong_t mhs_coll
; /* occur when insert fails because of dup's */
54 ulong_t mhs_nelems
; /* total number of stored key/value pairs */
55 ulong_t mhs_nomem
; /* number of times kmem_alloc failed */
59 krwlock_t mh_contents
; /* lock protecting contents */
60 char *mh_name
; /* hash name */
61 int mh_sleep
; /* kmem_alloc flag */
62 size_t mh_nchains
; /* # of elements in mh_entries */
64 /* key and val destructor */
65 void (*mh_kdtor
)(mod_hash_key_t
);
66 void (*mh_vdtor
)(mod_hash_val_t
);
69 int (*mh_keycmp
)(mod_hash_key_t
, mod_hash_key_t
);
71 /* hash algorithm, and algorithm-private data */
72 uint_t (*mh_hashalg
)(void *, mod_hash_key_t
);
73 void *mh_hashalg_data
;
75 struct mod_hash
*mh_next
; /* next hash in list */
77 struct mod_hash_stat mh_stat
;
79 struct mod_hash_entry
*mh_entries
[1];
84 * Compute the size of a mod_hash_t, in bytes, given the number of
85 * elements it contains.
88 (sizeof (mod_hash_t) + ((n) - 1) * (sizeof (struct mod_hash_entry *)))
91 * Module initialization; called once.
93 void mod_hash_init(void);
96 * Internal routines. Use directly with care.
98 uint_t
i_mod_hash(mod_hash_t
*, mod_hash_key_t
);
99 int i_mod_hash_insert_nosync(mod_hash_t
*, mod_hash_key_t
, mod_hash_val_t
,
101 int i_mod_hash_remove_nosync(mod_hash_t
*, mod_hash_key_t
, mod_hash_val_t
*);
102 int i_mod_hash_find_nosync(mod_hash_t
*, mod_hash_key_t
, mod_hash_val_t
*);
103 void i_mod_hash_walk_nosync(mod_hash_t
*, uint_t (*)(mod_hash_key_t
,
104 mod_hash_val_t
*, void *), void *);
105 void i_mod_hash_clear_nosync(mod_hash_t
*hash
);
113 #endif /* _SYS_MODHASH_IMPL_H */