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