xref: /titanic_44/usr/src/lib/libsip/common/sip_hash.h (revision 2c2c41837e330b002c4220a39638150db504fe0e)
140cb5e5dSvi117747 /*
240cb5e5dSvi117747  * CDDL HEADER START
340cb5e5dSvi117747  *
440cb5e5dSvi117747  * The contents of this file are subject to the terms of the
540cb5e5dSvi117747  * Common Development and Distribution License (the "License").
640cb5e5dSvi117747  * You may not use this file except in compliance with the License.
740cb5e5dSvi117747  *
840cb5e5dSvi117747  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
940cb5e5dSvi117747  * or http://www.opensolaris.org/os/licensing.
1040cb5e5dSvi117747  * See the License for the specific language governing permissions
1140cb5e5dSvi117747  * and limitations under the License.
1240cb5e5dSvi117747  *
1340cb5e5dSvi117747  * When distributing Covered Code, include this CDDL HEADER in each
1440cb5e5dSvi117747  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1540cb5e5dSvi117747  * If applicable, add the following below this CDDL HEADER, with the
1640cb5e5dSvi117747  * fields enclosed by brackets "[]" replaced with your own identifying
1740cb5e5dSvi117747  * information: Portions Copyright [yyyy] [name of copyright owner]
1840cb5e5dSvi117747  *
1940cb5e5dSvi117747  * CDDL HEADER END
2040cb5e5dSvi117747  */
2140cb5e5dSvi117747 
2240cb5e5dSvi117747 /*
23*2c2c4183Svi117747  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
2440cb5e5dSvi117747  * Use is subject to license terms.
2540cb5e5dSvi117747  */
2640cb5e5dSvi117747 
2740cb5e5dSvi117747 #ifndef	_SIP_HASH_H
2840cb5e5dSvi117747 #define	_SIP_HASH_H
2940cb5e5dSvi117747 
3040cb5e5dSvi117747 #pragma ident	"%Z%%M%	%I%	%E% SMI"
3140cb5e5dSvi117747 
3240cb5e5dSvi117747 #ifdef	__cplusplus
3340cb5e5dSvi117747 extern "C" {
3440cb5e5dSvi117747 #endif
3540cb5e5dSvi117747 
3640cb5e5dSvi117747 #include <pthread.h>
3740cb5e5dSvi117747 
3840cb5e5dSvi117747 /* A prime number */
3940cb5e5dSvi117747 #define	SIP_HASH_SZ	6037
4040cb5e5dSvi117747 
4140cb5e5dSvi117747 #define	SIP_DIGEST_TO_HASH(digest)					\
4240cb5e5dSvi117747 	((digest[0] + digest[1] + digest[2] + digest[3] + digest[4] +	\
4340cb5e5dSvi117747 	digest[5] + digest[6] + digest[7]) % SIP_HASH_SZ)
4440cb5e5dSvi117747 
4540cb5e5dSvi117747 /* An entry in the hash table, sip_obj is opaque */
4640cb5e5dSvi117747 typedef struct	sip_hash_obj_s {
4740cb5e5dSvi117747 	void			*sip_obj;
4840cb5e5dSvi117747 	struct sip_hash_obj_s	*next_obj;
4940cb5e5dSvi117747 	struct sip_hash_obj_s	*prev_obj;
5040cb5e5dSvi117747 } sip_hash_obj_t;
5140cb5e5dSvi117747 
5240cb5e5dSvi117747 
5340cb5e5dSvi117747 /* A hash list in the table */
5440cb5e5dSvi117747 typedef struct sip_hash_s {
5540cb5e5dSvi117747 	sip_hash_obj_t	*hash_head;
5640cb5e5dSvi117747 	sip_hash_obj_t	*hash_tail;
5740cb5e5dSvi117747 	int		hash_count;
5840cb5e5dSvi117747 	pthread_mutex_t sip_hash_mutex;
5940cb5e5dSvi117747 }sip_hash_t;
6040cb5e5dSvi117747 
6140cb5e5dSvi117747 int	sip_hash_add(sip_hash_t	*, void *, int);
6240cb5e5dSvi117747 void	*sip_hash_find(sip_hash_t *, void *, int,
6340cb5e5dSvi117747 	    boolean_t (*)(void *, void *));
6440cb5e5dSvi117747 void	sip_walk_hash(sip_hash_t *, void (*)(void *, void *), void *);
6540cb5e5dSvi117747 void	sip_hash_delete(sip_hash_t *, void *, int,
6640cb5e5dSvi117747 	    boolean_t (*)(void *, void *, int *));
6740cb5e5dSvi117747 void	sip_hash_init();
6840cb5e5dSvi117747 
6940cb5e5dSvi117747 #ifdef	__cplusplus
7040cb5e5dSvi117747 }
7140cb5e5dSvi117747 #endif
7240cb5e5dSvi117747 
7340cb5e5dSvi117747 #endif	/* _SIP_HASH_H */
74