uts: make emu10k non-verbose
[unleashed.git] / include / sys / modhash.h
blob68d1c4dedd9dc527e97e10ae96a383e186b74cf5
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_MODHASH_H
27 #define _SYS_MODHASH_H
30 * Generic hash implementation for the kernel.
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
37 #ifdef _KERNEL
39 #include <sys/types.h>
42 * Opaque data types for storing keys and values
44 typedef void *mod_hash_val_t;
45 typedef void *mod_hash_key_t;
48 * Opaque data type for reservation
50 typedef void *mod_hash_hndl_t;
53 * Opaque type for hash itself.
55 struct mod_hash;
56 typedef struct mod_hash mod_hash_t;
59 * String hash table
61 mod_hash_t *mod_hash_create_strhash(char *, size_t, void (*)(mod_hash_val_t));
62 void mod_hash_destroy_strhash(mod_hash_t *);
63 int mod_hash_strkey_cmp(mod_hash_key_t, mod_hash_key_t);
64 void mod_hash_strkey_dtor(mod_hash_key_t);
65 void mod_hash_strval_dtor(mod_hash_val_t);
66 uint_t mod_hash_bystr(void *, mod_hash_key_t);
69 * Pointer hash table
71 mod_hash_t *mod_hash_create_ptrhash(char *, size_t, void (*)(mod_hash_val_t),
72 size_t);
73 void mod_hash_destroy_ptrhash(mod_hash_t *);
74 int mod_hash_ptrkey_cmp(mod_hash_key_t, mod_hash_key_t);
75 uint_t mod_hash_byptr(void *, mod_hash_key_t);
78 * ID hash table
80 mod_hash_t *mod_hash_create_idhash(char *, size_t, void (*)(mod_hash_val_t));
81 void mod_hash_destroy_idhash(mod_hash_t *);
82 int mod_hash_idkey_cmp(mod_hash_key_t, mod_hash_key_t);
83 uint_t mod_hash_byid(void *, mod_hash_key_t);
84 uint_t mod_hash_iddata_gen(size_t);
87 * Hash management functions
89 mod_hash_t *mod_hash_create_extended(char *, size_t, void (*)(mod_hash_key_t),
90 void (*)(mod_hash_val_t), uint_t (*)(void *, mod_hash_key_t), void *,
91 int (*)(mod_hash_key_t, mod_hash_key_t), int);
93 void mod_hash_destroy_hash(mod_hash_t *);
94 void mod_hash_clear(mod_hash_t *);
97 * Null key and value destructors
99 void mod_hash_null_keydtor(mod_hash_key_t);
100 void mod_hash_null_valdtor(mod_hash_val_t);
103 * Basic hash operations
107 * Error codes for insert, remove, find, destroy.
109 #define MH_ERR_NOMEM -1
110 #define MH_ERR_DUPLICATE -2
111 #define MH_ERR_NOTFOUND -3
114 * Return codes for hash walkers
116 #define MH_WALK_CONTINUE 0
117 #define MH_WALK_TERMINATE 1
120 * Basic hash operations
122 int mod_hash_insert(mod_hash_t *, mod_hash_key_t, mod_hash_val_t);
123 int mod_hash_replace(mod_hash_t *, mod_hash_key_t, mod_hash_val_t);
124 int mod_hash_remove(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
125 int mod_hash_destroy(mod_hash_t *, mod_hash_key_t);
126 int mod_hash_find(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
127 int mod_hash_find_cb(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *,
128 void (*)(mod_hash_key_t, mod_hash_val_t));
129 int mod_hash_find_cb_rval(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *,
130 int (*)(mod_hash_key_t, mod_hash_val_t), int *);
131 void mod_hash_walk(mod_hash_t *,
132 uint_t (*)(mod_hash_key_t, mod_hash_val_t *, void *), void *);
135 * Reserving hash operations
137 int mod_hash_reserve(mod_hash_t *, mod_hash_hndl_t *);
138 int mod_hash_reserve_nosleep(mod_hash_t *, mod_hash_hndl_t *);
139 void mod_hash_cancel(mod_hash_t *, mod_hash_hndl_t *);
140 int mod_hash_insert_reserve(mod_hash_t *, mod_hash_key_t, mod_hash_val_t,
141 mod_hash_hndl_t);
143 #endif /* _KERNEL */
145 #ifdef __cplusplus
147 #endif
149 #endif /* _SYS_MODHASH_H */