xref: /onnv-gate/usr/src/lib/libsip/common/sip_hash.h (revision 2882:5f4abbf1f03e)
1*2882Svi117747 /*
2*2882Svi117747  * CDDL HEADER START
3*2882Svi117747  *
4*2882Svi117747  * The contents of this file are subject to the terms of the
5*2882Svi117747  * Common Development and Distribution License (the "License").
6*2882Svi117747  * You may not use this file except in compliance with the License.
7*2882Svi117747  *
8*2882Svi117747  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2882Svi117747  * or http://www.opensolaris.org/os/licensing.
10*2882Svi117747  * See the License for the specific language governing permissions
11*2882Svi117747  * and limitations under the License.
12*2882Svi117747  *
13*2882Svi117747  * When distributing Covered Code, include this CDDL HEADER in each
14*2882Svi117747  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2882Svi117747  * If applicable, add the following below this CDDL HEADER, with the
16*2882Svi117747  * fields enclosed by brackets "[]" replaced with your own identifying
17*2882Svi117747  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2882Svi117747  *
19*2882Svi117747  * CDDL HEADER END
20*2882Svi117747  */
21*2882Svi117747 
22*2882Svi117747 /*
23*2882Svi117747  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*2882Svi117747  * Use is subject to license terms.
25*2882Svi117747  */
26*2882Svi117747 
27*2882Svi117747 #ifndef	_SIP_HASH_H
28*2882Svi117747 #define	_SIP_HASH_H
29*2882Svi117747 
30*2882Svi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*2882Svi117747 
32*2882Svi117747 #ifdef	__cplusplus
33*2882Svi117747 extern "C" {
34*2882Svi117747 #endif
35*2882Svi117747 
36*2882Svi117747 #include <stdlib.h>
37*2882Svi117747 #include <pthread.h>
38*2882Svi117747 #include <sip.h>
39*2882Svi117747 
40*2882Svi117747 /* A prime number */
41*2882Svi117747 #define	SIP_HASH_SZ	6037
42*2882Svi117747 
43*2882Svi117747 #define	SIP_DIGEST_TO_HASH(digest)					\
44*2882Svi117747 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
45*2882Svi117747 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
46*2882Svi117747 
47*2882Svi117747 /* An entry in the hash table, sip_obj is opaque */
48*2882Svi117747 typedef struct	sip_hash_obj_s {
49*2882Svi117747 	void			*sip_obj;
50*2882Svi117747 	struct sip_hash_obj_s	*next_obj;
51*2882Svi117747 	struct sip_hash_obj_s	*prev_obj;
52*2882Svi117747 } sip_hash_obj_t;
53*2882Svi117747 
54*2882Svi117747 
55*2882Svi117747 /* A hash list in the table */
56*2882Svi117747 typedef struct sip_hash_s {
57*2882Svi117747 	sip_hash_obj_t	*hash_head;
58*2882Svi117747 	sip_hash_obj_t	*hash_tail;
59*2882Svi117747 	int		hash_count;
60*2882Svi117747 	pthread_mutex_t sip_hash_mutex;
61*2882Svi117747 }sip_hash_t;
62*2882Svi117747 
63*2882Svi117747 int	sip_hash_add(sip_hash_t	*, void *, int);
64*2882Svi117747 void	*sip_hash_find(sip_hash_t *, void *, int,
65*2882Svi117747 	    boolean_t (*)(void *, void *));
66*2882Svi117747 void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
67*2882Svi117747 void	sip_hash_delete(sip_hash_t *, void *, int,
68*2882Svi117747 	    boolean_t (*)(void *, void *, int *));
69*2882Svi117747 void	sip_hash_init();
70*2882Svi117747 
71*2882Svi117747 #ifdef	__cplusplus
72*2882Svi117747 }
73*2882Svi117747 #endif
74*2882Svi117747 
75*2882Svi117747 #endif	/* _SIP_HASH_H */
76