xref: /onnv-gate/usr/src/lib/libsip/common/sip_hash.h (revision 3439:0302bfe973fe)
12882Svi117747 /*
22882Svi117747  * CDDL HEADER START
32882Svi117747  *
42882Svi117747  * The contents of this file are subject to the terms of the
52882Svi117747  * Common Development and Distribution License (the "License").
62882Svi117747  * You may not use this file except in compliance with the License.
72882Svi117747  *
82882Svi117747  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92882Svi117747  * or http://www.opensolaris.org/os/licensing.
102882Svi117747  * See the License for the specific language governing permissions
112882Svi117747  * and limitations under the License.
122882Svi117747  *
132882Svi117747  * When distributing Covered Code, include this CDDL HEADER in each
142882Svi117747  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152882Svi117747  * If applicable, add the following below this CDDL HEADER, with the
162882Svi117747  * fields enclosed by brackets "[]" replaced with your own identifying
172882Svi117747  * information: Portions Copyright [yyyy] [name of copyright owner]
182882Svi117747  *
192882Svi117747  * CDDL HEADER END
202882Svi117747  */
212882Svi117747 
222882Svi117747 /*
23*3439Svi117747  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
242882Svi117747  * Use is subject to license terms.
252882Svi117747  */
262882Svi117747 
272882Svi117747 #ifndef	_SIP_HASH_H
282882Svi117747 #define	_SIP_HASH_H
292882Svi117747 
302882Svi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
312882Svi117747 
322882Svi117747 #ifdef	__cplusplus
332882Svi117747 extern "C" {
342882Svi117747 #endif
352882Svi117747 
362882Svi117747 #include <pthread.h>
372882Svi117747 
382882Svi117747 /* A prime number */
392882Svi117747 #define	SIP_HASH_SZ	6037
402882Svi117747 
412882Svi117747 #define	SIP_DIGEST_TO_HASH(digest)					\
422882Svi117747 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
432882Svi117747 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
442882Svi117747 
452882Svi117747 /* An entry in the hash table, sip_obj is opaque */
462882Svi117747 typedef struct	sip_hash_obj_s {
472882Svi117747 	void			*sip_obj;
482882Svi117747 	struct sip_hash_obj_s	*next_obj;
492882Svi117747 	struct sip_hash_obj_s	*prev_obj;
502882Svi117747 } sip_hash_obj_t;
512882Svi117747 
522882Svi117747 
532882Svi117747 /* A hash list in the table */
542882Svi117747 typedef struct sip_hash_s {
552882Svi117747 	sip_hash_obj_t	*hash_head;
562882Svi117747 	sip_hash_obj_t	*hash_tail;
572882Svi117747 	int		hash_count;
582882Svi117747 	pthread_mutex_t sip_hash_mutex;
592882Svi117747 }sip_hash_t;
602882Svi117747 
612882Svi117747 int	sip_hash_add(sip_hash_t	*, void *, int);
622882Svi117747 void	*sip_hash_find(sip_hash_t *, void *, int,
632882Svi117747 	    boolean_t (*)(void *, void *));
642882Svi117747 void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
652882Svi117747 void	sip_hash_delete(sip_hash_t *, void *, int,
662882Svi117747 	    boolean_t (*)(void *, void *, int *));
672882Svi117747 void	sip_hash_init();
682882Svi117747 
692882Svi117747 #ifdef	__cplusplus
702882Svi117747 }
712882Svi117747 #endif
722882Svi117747 
732882Svi117747 #endif	/* _SIP_HASH_H */
74