00001 /* Hash tables. 00002 Copyright (C) 2000, 2001 Free Software Foundation, Inc. 00003 00004 This program is free software; you can redistribute it and/or modify it 00005 under the terms of the GNU General Public License as published by the 00006 Free Software Foundation; either version 2, or (at your option) any 00007 later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 00017 00018 #ifndef GCC_HASHTABLE_H 00019 #define GCC_HASHTABLE_H 00020 00021 #include "obstack.h" 00022 00023 /* This is what each hash table entry points to. It may be embedded 00024 deeply within another object. */ 00025 typedef struct ht_identifier ht_identifier; 00026 struct ht_identifier GTY(()) 00027 { 00028 const unsigned char *str; 00029 unsigned int len; 00030 unsigned int hash_value; 00031 }; 00032 00033 #define HT_LEN(NODE) ((NODE)->len) 00034 #define HT_STR(NODE) ((NODE)->str) 00035 00036 /* We want code outside cpplib, such as the compiler front-ends, to be 00037 able to include this header, and to be able to link with 00038 cpphashtbl.o without pulling in any other parts of cpplib. */ 00039 00040 struct cpp_reader; 00041 typedef struct ht hash_table; 00042 typedef struct ht_identifier *hashnode; 00043 00044 enum ht_lookup_option {HT_NO_INSERT = 0, HT_ALLOC, HT_ALLOCED}; 00045 00046 /* An identifier hash table for cpplib and the front ends. */ 00047 struct ht 00048 { 00049 /* Identifiers are allocated from here. */ 00050 struct obstack stack; 00051 00052 hashnode *entries; 00053 /* Call back. */ 00054 hashnode (*alloc_node) PARAMS ((hash_table *)); 00055 00056 unsigned int nslots; /* Total slots in the entries array. */ 00057 unsigned int nelements; /* Number of live elements. */ 00058 00059 /* Link to reader, if any. For the benefit of cpplib. */ 00060 struct cpp_reader *pfile; 00061 00062 /* Table usage statistics. */ 00063 unsigned int searches; 00064 unsigned int collisions; 00065 }; 00066 00067 extern void gcc_obstack_init PARAMS ((struct obstack *)); 00068 00069 /* Initialize the hashtable with 2 ^ order entries. */ 00070 extern hash_table *ht_create PARAMS ((unsigned int order)); 00071 00072 /* Frees all memory associated with a hash table. */ 00073 extern void ht_destroy PARAMS ((hash_table *)); 00074 00075 extern hashnode ht_lookup PARAMS ((hash_table *, const unsigned char *, 00076 unsigned int, enum ht_lookup_option)); 00077 00078 /* For all nodes in TABLE, make a callback. The callback takes 00079 TABLE->PFILE, the node, and a PTR, and the callback sequence stops 00080 if the callback returns zero. */ 00081 typedef int (*ht_cb) PARAMS ((struct cpp_reader *, hashnode, const void *)); 00082 extern void ht_forall PARAMS ((hash_table *, ht_cb, const void *)); 00083 00084 /* Dump allocation statistics to stderr. */ 00085 extern void ht_dump_statistics PARAMS ((hash_table *)); 00086 00087 /* Approximate positive square root of a host double. This is for 00088 statistical reports, not code generation. */ 00089 extern double approx_sqrt PARAMS ((double)); 00090 00091 #endif /* GCC_HASHTABLE_H */
1.5.6