xref: /illumos-gate/usr/src/lib/libsip/common/sip_hash.h (revision 2c2c41837e330b002c4220a39638150db504fe0e)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <pthread.h>
37 
38 /* A prime number */
39 #define	SIP_HASH_SZ	6037
40 
41 #define	SIP_DIGEST_TO_HASH(digest)					\
42 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
43 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
44 
45 /* An entry in the hash table, sip_obj is opaque */
46 typedef struct	sip_hash_obj_s {
47 	void			*sip_obj;
48 	struct sip_hash_obj_s	*next_obj;
49 	struct sip_hash_obj_s	*prev_obj;
50 } sip_hash_obj_t;
51 
52 
53 /* A hash list in the table */
54 typedef struct sip_hash_s {
55 	sip_hash_obj_t	*hash_head;
56 	sip_hash_obj_t	*hash_tail;
57 	int		hash_count;
58 	pthread_mutex_t sip_hash_mutex;
59 }sip_hash_t;
60 
61 int	sip_hash_add(sip_hash_t	*, void *, int);
62 void	*sip_hash_find(sip_hash_t *, void *, int,
63 	    boolean_t (*)(void *, void *));
64 void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
65 void	sip_hash_delete(sip_hash_t *, void *, int,
66 	    boolean_t (*)(void *, void *, int *));
67 void	sip_hash_init();
68 
69 #ifdef	__cplusplus
70 }
71 #endif
72 
73 #endif	/* _SIP_HASH_H */
74