1 /* Header file for generic hash table support.
2 Copyright (C) 1993, 94 Free Software Foundation, Inc.
3 Written by Steve Chamberlain <sac@cygnus.com>
5 This file was lifted from BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 /* Add prototype support. */
25 #if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined (__STDC__)
26 #define PROTO(ARGS) ARGS
28 #define PROTO(ARGS) ()
32 #define PARAMS(ARGS) PROTO(ARGS)
49 typedef enum {false, true} boolean
;
51 /* Hash table routines. There is no way to free up a hash table. */
53 /* An element in the hash table. Most uses will actually use a larger
54 structure, and an instance of this will be the first field. */
58 /* Next entry for this hash code. */
59 struct hash_entry
*next
;
60 /* String being hashed. */
62 /* Hash code. This is the full hash code, not the index into the
72 struct hash_entry
**table
;
73 /* The number of slots in the hash table. */
75 /* A function used to create new elements in the hash table. The
76 first entry is itself a pointer to an element. When this
77 function is first invoked, this pointer will be NULL. However,
78 having the pointer permits a hierarchy of method functions to be
79 built each of which calls the function in the superclass. Thus
80 each function should be written to allocate a new block of memory
81 only if the argument is NULL. */
82 struct hash_entry
*(*newfunc
) PARAMS ((struct hash_entry
*,
85 /* An obstack for this hash table. */
86 struct obstack memory
;
89 /* Initialize a hash table. */
90 extern boolean hash_table_init
91 PARAMS ((struct hash_table
*,
92 struct hash_entry
*(*) (struct hash_entry
*,
96 /* Initialize a hash table specifying a size. */
97 extern boolean hash_table_init_n
98 PARAMS ((struct hash_table
*,
99 struct hash_entry
*(*) (struct hash_entry
*,
104 /* Free up a hash table. */
105 extern void hash_table_free
PARAMS ((struct hash_table
*));
107 /* Look up a string in a hash table. If CREATE is true, a new entry
108 will be created for this string if one does not already exist. The
109 COPY argument must be true if this routine should copy the string
110 into newly allocated memory when adding an entry. */
111 extern struct hash_entry
*hash_lookup
112 PARAMS ((struct hash_table
*, const char *, boolean create
,
115 /* Base method for creating a hash table entry. */
116 extern struct hash_entry
*hash_newfunc
117 PARAMS ((struct hash_entry
*, struct hash_table
*,
120 /* Grab some space for a hash table entry. */
121 extern PTR hash_allocate
PARAMS ((struct hash_table
*,
124 /* Traverse a hash table in a random order, calling a function on each
125 element. If the function returns false, the traversal stops. The
126 INFO argument is passed to the function. */
127 extern void hash_traverse
PARAMS ((struct hash_table
*,
128 boolean (*) (struct hash_entry
*,