OSDN Git Service

* gansidecl.h: Prepend a "G" to the macro wrapping this file
[pf3gnuchains/gcc-fork.git] / gcc / hash.h
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>
4
5 This file was lifted from BFD, the Binary File Descriptor library.
6
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.
11
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.
16
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.  */
20
21 #ifndef IN_GCC
22 #include <ansidecl.h>
23 #endif /* ! IN_GCC */
24
25 #include "obstack.h"
26
27 typedef enum {false, true} boolean;
28
29 /* Hash table routines.  There is no way to free up a hash table.  */
30
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.  */
33
34 struct hash_entry
35 {
36   /* Next entry for this hash code.  */
37   struct hash_entry *next;
38   /* String being hashed.  */
39   const char *string;
40   /* Hash code.  This is the full hash code, not the index into the
41      table.  */
42   unsigned long hash;
43 };
44
45 /* A hash table.  */
46
47 struct hash_table
48 {
49   /* The hash array.  */
50   struct hash_entry **table;
51   /* The number of slots in the hash table.  */
52   unsigned int size;
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 *,
61                                          struct hash_table *,
62                                          const char *));
63   /* An obstack for this hash table.  */
64   struct obstack memory;
65 };
66
67 /* Initialize a hash table.  */
68 extern boolean hash_table_init
69   PARAMS ((struct hash_table *,
70            struct hash_entry *(*) (struct hash_entry *,
71                                    struct hash_table *,
72                                    const char *)));
73
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 *,
78                                    struct hash_table *,
79                                    const char *),
80            unsigned int size));
81
82 /* Free up a hash table.  */
83 extern void hash_table_free PARAMS ((struct hash_table *));
84
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,
91            boolean copy));
92
93 /* Base method for creating a hash table entry.  */
94 extern struct hash_entry *hash_newfunc
95   PARAMS ((struct hash_entry *, struct hash_table *,
96            const char *));
97
98 /* Grab some space for a hash table entry.  */
99 extern PTR hash_allocate PARAMS ((struct hash_table *,
100                                   unsigned int));
101
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 *,
107                                                 PTR),
108                                    PTR info));