xref: /illumos-gate/usr/src/lib/libsip/common/sip_hash.h (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SIP_HASH_H
28 #define	_SIP_HASH_H
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <pthread.h>
35 
36 /* A prime number */
37 #define	SIP_HASH_SZ	6037
38 
39 #define	SIP_DIGEST_TO_HASH(digest)					\
40 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
41 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
42 
43 /* An entry in the hash table, sip_obj is opaque */
44 typedef struct	sip_hash_obj_s {
45 	void			*sip_obj;
46 	struct sip_hash_obj_s	*next_obj;
47 	struct sip_hash_obj_s	*prev_obj;
48 } sip_hash_obj_t;
49 
50 
51 /* A hash list in the table */
52 typedef struct sip_hash_s {
53 	sip_hash_obj_t	*hash_head;
54 	sip_hash_obj_t	*hash_tail;
55 	int		hash_count;
56 	pthread_mutex_t sip_hash_mutex;
57 }sip_hash_t;
58 
59 int	sip_hash_add(sip_hash_t	*, void *, int);
60 void	*sip_hash_find(sip_hash_t *, void *, int,
61 	    boolean_t (*)(void *, void *));
62 void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
63 void	sip_hash_delete(sip_hash_t *, void *, int,
64 	    boolean_t (*)(void *, void *, int *));
65 void	sip_hash_init();
66 
67 #ifdef	__cplusplus
68 }
69 #endif
70 
71 #endif	/* _SIP_HASH_H */
72