Sync usage with man page.
[netbsd-mini2440.git] / sbin / rcorder / hash.h
blob23b17984210001f1d7860696012ef83dcafe4234
1 /* $NetBSD: hash.h,v 1.2 2002/06/30 14:17:45 lukem Exp $ */
3 /*
4 * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
5 * All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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
32 * SUCH DAMAGE.
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
43 * Adam de Boor.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
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
71 * SUCH DAMAGE.
73 * from: @(#)hash.h 8.1 (Berkeley) 6/6/93
76 /* hash.h --
78 * This file contains definitions used by the hash module,
79 * which maintains hash tables.
82 #ifndef _HASH
83 #define _HASH
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
92 * bucket. */
93 void *clientData; /* Arbitrary piece of data associated
94 * with key. */
95 unsigned namehash; /* hash value of key */
96 char name[1]; /* key string */
97 } Hash_Entry;
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. */
106 } Hash_Table;
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
116 * current). */
117 Hash_Entry *hashEntryPtr; /* Next entry to check in current
118 * bucket. */
119 } Hash_Search;
122 * Macros.
126 * void *Hash_GetValue(h)
127 * Hash_Entry *h;
130 #define Hash_GetValue(h) ((h)->clientData)
133 * Hash_SetValue(h, val);
134 * Hash_Entry *h;
135 * char *val;
138 #define Hash_SetValue(h, val) ((h)->clientData = (void *) (val))
141 * Hash_GetKey(h);
142 * Hash_Entry *h;
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 *);
161 #endif /* _HASH */