1 /* $NetBSD: hash.h,v 1.3 2003/08/07 10:04:37 agc Exp $ */
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * from: @(#)hash.h 8.1 (Berkeley) 6/6/93
38 * Copyright (c) 1988, 1989 by Adam de Boor
39 * Copyright (c) 1989 by Berkeley Softworks
40 * All rights reserved.
42 * This code is derived from software contributed to Berkeley by
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * from: @(#)hash.h 8.1 (Berkeley) 6/6/93
78 * This file contains definitions used by the hash module,
79 * which maintains hash tables.
86 * The following defines one entry in the hash table.
89 typedef struct Hash_Entry
{
90 struct Hash_Entry
*next
; /* Used to link together all the
91 * entries associated with the same
93 void *clientData
; /* Arbitrary piece of data associated
95 unsigned namehash
; /* hash value of key */
96 char name
[1]; /* key string */
99 typedef struct Hash_Table
{
100 struct Hash_Entry
**bucketPtr
;
101 /* Pointers to Hash_Entry, one
102 * for each bucket in the table. */
103 int size
; /* Actual size of array. */
104 int numEntries
; /* Number of entries in the table. */
105 int mask
; /* Used to select bits for hashing. */
109 * The following structure is used by the searching routines
110 * to record where we are in the search.
113 typedef struct Hash_Search
{
114 Hash_Table
*tablePtr
; /* Table being searched. */
115 int nextIndex
; /* Next bucket to check (after
117 Hash_Entry
*hashEntryPtr
; /* Next entry to check in current
126 * void *Hash_GetValue(h)
130 #define Hash_GetValue(h) ((h)->clientData)
133 * Hash_SetValue(h, val);
138 #define Hash_SetValue(h, val) ((h)->clientData = (void *) (val))
145 #define Hash_GetKey(h) ((h)->name)
148 * Hash_Size(n) returns the number of words in an object of n bytes
151 #define Hash_Size(n) (((n) + sizeof (int) - 1) / sizeof (int))
153 void Hash_InitTable(Hash_Table
*, int);
154 void Hash_DeleteTable(Hash_Table
*);
155 Hash_Entry
*Hash_FindEntry(Hash_Table
*, char *);
156 Hash_Entry
*Hash_CreateEntry(Hash_Table
*, char *, int *);
157 void Hash_DeleteEntry(Hash_Table
*, Hash_Entry
*);
158 Hash_Entry
*Hash_EnumFirst(Hash_Table
*, Hash_Search
*);
159 Hash_Entry
*Hash_EnumNext(Hash_Search
*);