xref: /titanic_51/usr/src/uts/common/sys/modhash.h (revision da14cebe459d3275048785f25bd869cb09b5307f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6*da14cebeSEric Cheng  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*da14cebeSEric Cheng  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_MODHASH_H
277c478bd9Sstevel@tonic-gate #define	_SYS_MODHASH_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Generic hash implementation for the kernel.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifdef __cplusplus
347c478bd9Sstevel@tonic-gate extern "C" {
357c478bd9Sstevel@tonic-gate #endif
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #ifdef _KERNEL
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <sys/types.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * Opaque data types for storing keys and values
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate typedef void *mod_hash_val_t;
457c478bd9Sstevel@tonic-gate typedef void *mod_hash_key_t;
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * Opaque data type for reservation
497c478bd9Sstevel@tonic-gate  */
507c478bd9Sstevel@tonic-gate typedef void *mod_hash_hndl_t;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Opaque type for hash itself.
547c478bd9Sstevel@tonic-gate  */
557c478bd9Sstevel@tonic-gate struct mod_hash;
567c478bd9Sstevel@tonic-gate typedef struct mod_hash mod_hash_t;
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate  * String hash table
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate mod_hash_t *mod_hash_create_strhash(char *, size_t, void (*)(mod_hash_val_t));
627c478bd9Sstevel@tonic-gate void mod_hash_destroy_strhash(mod_hash_t *);
637c478bd9Sstevel@tonic-gate int mod_hash_strkey_cmp(mod_hash_key_t, mod_hash_key_t);
647c478bd9Sstevel@tonic-gate void mod_hash_strkey_dtor(mod_hash_key_t);
657c478bd9Sstevel@tonic-gate void mod_hash_strval_dtor(mod_hash_val_t);
667c478bd9Sstevel@tonic-gate uint_t mod_hash_bystr(void *, mod_hash_key_t);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Pointer hash table
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate mod_hash_t *mod_hash_create_ptrhash(char *, size_t, void (*)(mod_hash_val_t),
727c478bd9Sstevel@tonic-gate     size_t);
737c478bd9Sstevel@tonic-gate void mod_hash_destroy_ptrhash(mod_hash_t *);
747c478bd9Sstevel@tonic-gate int mod_hash_ptrkey_cmp(mod_hash_key_t, mod_hash_key_t);
757c478bd9Sstevel@tonic-gate uint_t mod_hash_byptr(void *, mod_hash_key_t);
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * ID hash table
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate mod_hash_t *mod_hash_create_idhash(char *, size_t, void (*)(mod_hash_val_t));
817c478bd9Sstevel@tonic-gate void mod_hash_destroy_idhash(mod_hash_t *);
827c478bd9Sstevel@tonic-gate int mod_hash_idkey_cmp(mod_hash_key_t, mod_hash_key_t);
837c478bd9Sstevel@tonic-gate uint_t mod_hash_byid(void *, mod_hash_key_t);
847c478bd9Sstevel@tonic-gate uint_t mod_hash_iddata_gen(size_t);
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * Hash management functions
887c478bd9Sstevel@tonic-gate  */
897c478bd9Sstevel@tonic-gate mod_hash_t *mod_hash_create_extended(char *, size_t, void (*)(mod_hash_key_t),
907c478bd9Sstevel@tonic-gate     void (*)(mod_hash_val_t), uint_t (*)(void *, mod_hash_key_t), void *,
917c478bd9Sstevel@tonic-gate     int (*)(mod_hash_key_t, mod_hash_key_t), int);
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate void mod_hash_destroy_hash(mod_hash_t *);
947c478bd9Sstevel@tonic-gate void mod_hash_clear(mod_hash_t *);
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Null key and value destructors
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate void mod_hash_null_keydtor(mod_hash_key_t);
1007c478bd9Sstevel@tonic-gate void mod_hash_null_valdtor(mod_hash_val_t);
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * Basic hash operations
1047c478bd9Sstevel@tonic-gate  */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * Error codes for insert, remove, find, destroy.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate #define	MH_ERR_NOMEM -1
1107c478bd9Sstevel@tonic-gate #define	MH_ERR_DUPLICATE -2
1117c478bd9Sstevel@tonic-gate #define	MH_ERR_NOTFOUND -3
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate /*
1147c478bd9Sstevel@tonic-gate  * Return codes for hash walkers
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate #define	MH_WALK_CONTINUE 0
1177c478bd9Sstevel@tonic-gate #define	MH_WALK_TERMINATE 1
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * Basic hash operations
1217c478bd9Sstevel@tonic-gate  */
1227c478bd9Sstevel@tonic-gate int mod_hash_insert(mod_hash_t *, mod_hash_key_t, mod_hash_val_t);
1237c478bd9Sstevel@tonic-gate int mod_hash_replace(mod_hash_t *, mod_hash_key_t, mod_hash_val_t);
1247c478bd9Sstevel@tonic-gate int mod_hash_remove(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
1257c478bd9Sstevel@tonic-gate int mod_hash_destroy(mod_hash_t *, mod_hash_key_t);
1267c478bd9Sstevel@tonic-gate int mod_hash_find(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *);
1277c478bd9Sstevel@tonic-gate int mod_hash_find_cb(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *,
1287c478bd9Sstevel@tonic-gate     void (*)(mod_hash_key_t, mod_hash_val_t));
129*da14cebeSEric Cheng int mod_hash_find_cb_rval(mod_hash_t *, mod_hash_key_t, mod_hash_val_t *,
130*da14cebeSEric Cheng     int (*)(mod_hash_key_t, mod_hash_val_t), int *);
1317c478bd9Sstevel@tonic-gate void mod_hash_walk(mod_hash_t *,
1327c478bd9Sstevel@tonic-gate     uint_t (*)(mod_hash_key_t, mod_hash_val_t *, void *), void *);
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate /*
1357c478bd9Sstevel@tonic-gate  * Reserving hash operations
1367c478bd9Sstevel@tonic-gate  */
1377c478bd9Sstevel@tonic-gate int mod_hash_reserve(mod_hash_t *, mod_hash_hndl_t *);
1387c478bd9Sstevel@tonic-gate int mod_hash_reserve_nosleep(mod_hash_t *, mod_hash_hndl_t *);
1397c478bd9Sstevel@tonic-gate void mod_hash_cancel(mod_hash_t *, mod_hash_hndl_t *);
1407c478bd9Sstevel@tonic-gate int mod_hash_insert_reserve(mod_hash_t *, mod_hash_key_t, mod_hash_val_t,
1417c478bd9Sstevel@tonic-gate     mod_hash_hndl_t);
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #ifdef __cplusplus
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #endif /* _SYS_MODHASH_H */
150