2 Copyright (C) 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18 #ifndef LIBCPP_SYMTAB_H
19 #define LIBCPP_SYMTAB_H
21 #if defined(__APPLE__) && defined(__MACH__)
22 #include "libiberty/obstack.h"
26 #define GTY(x) /* nothing */
28 /* This is what each hash table entry points to. It may be embedded
29 deeply within another object. */
30 typedef struct ht_identifier ht_identifier;
31 struct ht_identifier GTY(())
33 const unsigned char *str;
35 unsigned int hash_value;
38 #define HT_LEN(NODE) ((NODE)->len)
39 #define HT_STR(NODE) ((NODE)->str)
41 typedef struct ht hash_table;
42 typedef struct ht_identifier *hashnode;
44 enum ht_lookup_option {HT_NO_INSERT = 0, HT_ALLOC, HT_ALLOCED};
46 /* An identifier hash table for cpplib and the front ends. */
49 /* Identifiers are allocated from here. */
53 /* Call back, allocate a node. */
54 hashnode (*alloc_node) (hash_table *);
55 /* Call back, allocate something that hangs off a node like a cpp_macro.
56 NULL means use the usual allocator. */
57 void * (*alloc_subobject) (size_t);
59 unsigned int nslots; /* Total slots in the entries array. */
60 unsigned int nelements; /* Number of live elements. */
62 /* Link to reader, if any. For the benefit of cpplib. */
63 struct cpp_reader *pfile;
65 /* Table usage statistics. */
66 unsigned int searches;
67 unsigned int collisions;
69 /* Should 'entries' be freed when it is no longer needed? */
73 /* Initialize the hashtable with 2 ^ order entries. */
74 extern hash_table *ht_create (unsigned int order);
76 /* Frees all memory associated with a hash table. */
77 extern void ht_destroy (hash_table *);
79 extern hashnode ht_lookup (hash_table *, const unsigned char *,
80 size_t, enum ht_lookup_option);
81 extern hashnode ht_lookup_with_hash (hash_table *, const unsigned char *,
83 enum ht_lookup_option);
84 #define HT_HASHSTEP(r, c) ((r) * 67 + ((c) - 113));
85 #define HT_HASHFINISH(r, len) ((r) + (len))
87 /* For all nodes in TABLE, make a callback. The callback takes
88 TABLE->PFILE, the node, and a PTR, and the callback sequence stops
89 if the callback returns zero. */
90 typedef int (*ht_cb) (struct cpp_reader *, hashnode, const void *);
91 extern void ht_forall (hash_table *, ht_cb, const void *);
93 /* Restore the hash table. */
94 extern void ht_load (hash_table *ht, hashnode *entries,
95 unsigned int nslots, unsigned int nelements, bool own);
97 /* Dump allocation statistics to stderr. */
98 extern void ht_dump_statistics (hash_table *);
100 #endif /* LIBCPP_SYMTAB_H */