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. */
27 typedef enum {false, true} boolean
;
29 /* Hash table routines. There is no way to free up a hash table. */
31 /* An element in the hash table. Most uses will actually use a larger
32 structure, and an instance of this will be the first field. */
36 /* Next entry for this hash code. */
37 struct hash_entry
*next
;
38 /* String being hashed. */
40 /* Hash code. This is the full hash code, not the index into the
50 struct hash_entry
**table
;
51 /* The number of slots in the hash table. */
53 /* A function used to create new elements in the hash table. The
54 first entry is itself a pointer to an element. When this
55 function is first invoked, this pointer will be NULL. However,
56 having the pointer permits a hierarchy of method functions to be
57 built each of which calls the function in the superclass. Thus
58 each function should be written to allocate a new block of memory
59 only if the argument is NULL. */
60 struct hash_entry
*(*newfunc
) PARAMS ((struct hash_entry
*,
63 /* An obstack for this hash table. */
64 struct obstack memory
;
67 /* Initialize a hash table. */
68 extern boolean hash_table_init
69 PARAMS ((struct hash_table
*,
70 struct hash_entry
*(*) (struct hash_entry
*,
74 /* Initialize a hash table specifying a size. */
75 extern boolean hash_table_init_n
76 PARAMS ((struct hash_table
*,
77 struct hash_entry
*(*) (struct hash_entry
*,
82 /* Free up a hash table. */
83 extern void hash_table_free
PARAMS ((struct hash_table
*));
85 /* Look up a string in a hash table. If CREATE is true, a new entry
86 will be created for this string if one does not already exist. The
87 COPY argument must be true if this routine should copy the string
88 into newly allocated memory when adding an entry. */
89 extern struct hash_entry
*hash_lookup
90 PARAMS ((struct hash_table
*, const char *, boolean create
,
93 /* Base method for creating a hash table entry. */
94 extern struct hash_entry
*hash_newfunc
95 PARAMS ((struct hash_entry
*, struct hash_table
*,
98 /* Grab some space for a hash table entry. */
99 extern PTR hash_allocate
PARAMS ((struct hash_table
*,
102 /* Traverse a hash table in a random order, calling a function on each
103 element. If the function returns false, the traversal stops. The
104 INFO argument is passed to the function. */
105 extern void hash_traverse
PARAMS ((struct hash_table
*,
106 boolean (*) (struct hash_entry
*,