xref: /openbsd/usr.sbin/npppd/common/hash.h (revision a6445c1d)
1 /*-
2  * Copyright (c) 2009 Internet Initiative Japan Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 /* $Id: hash.h,v 1.1 2010/01/11 04:20:57 yasuoka Exp $ */
27 #ifndef HASH_H
28 #define HASH_H
29 
30 #ifndef	HASH_SIZE
31 #define	HASH_SIZE	127
32 #endif
33 
34 typedef struct HASH_LINK {
35 	const void *key;
36 	struct HASH_LINK *next;
37 	void *item;
38 } hash_link;
39 
40 typedef struct {
41 	int (*cmp) (const void *, const void *);
42 	uint32_t (*hash) (const void *, int);
43 	hash_link **bucket;
44 	size_t size;
45 	int cur;
46 	hash_link *bucket_cur;
47 } hash_table;
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 hash_table  *hash_create(int (*)(const void *, const void *), uint32_t (*) (const void *, int), int);
53 hash_link   *hash_first __P((hash_table *));
54 hash_link   *hash_next __P((hash_table *));
55 hash_link   *hash_lookup __P((hash_table *, const void *));
56 int         hash_insert __P((hash_table *, const void *, void *));
57 int         hash_delete __P((hash_table *, const void *, int));
58 void        hash_delete_all __P((hash_table *, int));
59 void        hash_free __P((hash_table *));
60 
61 #ifdef __cplusplus
62 }
63 #endif
64 
65 #endif /* HASH_H */
66