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