emergency commit
[cl-cudd.git] / distr / st / st.h
blobdbb14bbebd41900cfc6efe9b7cc7ceda19395361
1 /**CHeaderFile*****************************************************************
3 FileName [st.h]
5 PackageName [st]
7 Synopsis [Symbol table package.]
9 Description [The st library provides functions to create, maintain,
10 and query symbol tables.]
12 SeeAlso []
14 Author []
16 Copyright []
18 Revision [$Id: st.h,v 1.10 2004/01/02 07:40:31 fabio Exp fabio $]
20 ******************************************************************************/
22 #ifndef ST_INCLUDED
23 #define ST_INCLUDED
25 /*---------------------------------------------------------------------------*/
26 /* Nested includes */
27 /*---------------------------------------------------------------------------*/
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 /*---------------------------------------------------------------------------*/
34 /* Constant declarations */
35 /*---------------------------------------------------------------------------*/
37 #define ST_DEFAULT_MAX_DENSITY 5
38 #define ST_DEFAULT_INIT_TABLE_SIZE 11
39 #define ST_DEFAULT_GROW_FACTOR 2.0
40 #define ST_DEFAULT_REORDER_FLAG 0
41 #define ST_OUT_OF_MEM -10000
43 /*---------------------------------------------------------------------------*/
44 /* Stucture declarations */
45 /*---------------------------------------------------------------------------*/
48 /*---------------------------------------------------------------------------*/
49 /* Type declarations */
50 /*---------------------------------------------------------------------------*/
52 typedef struct st_table_entry st_table_entry;
53 struct st_table_entry {
54 char *key;
55 char *record;
56 st_table_entry *next;
59 typedef struct st_table st_table;
60 struct st_table {
61 int (*compare)(const char *, const char *);
62 int (*hash)(char *, int);
63 int num_bins;
64 int num_entries;
65 int max_density;
66 int reorder_flag;
67 double grow_factor;
68 st_table_entry **bins;
71 typedef struct st_generator st_generator;
72 struct st_generator {
73 st_table *table;
74 st_table_entry *entry;
75 int index;
78 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
80 typedef enum st_retval (*ST_PFSR)(char *, char *, char *);
82 typedef int (*ST_PFICPCP)(const char *, const char *); /* type for comparison function */
84 typedef int (*ST_PFICPI)(char *, int); /* type for hash function */
86 /*---------------------------------------------------------------------------*/
87 /* Variable declarations */
88 /*---------------------------------------------------------------------------*/
91 /*---------------------------------------------------------------------------*/
92 /* Macro declarations */
93 /*---------------------------------------------------------------------------*/
95 /**Macro***********************************************************************
97 Synopsis [Checks whethere `key' is in `table'.]
99 Description [Returns 1 if there is an entry under `key' in `table', 0
100 otherwise.]
102 SideEffects [None]
104 SeeAlso [st_lookup]
106 ******************************************************************************/
107 #define st_is_member(table,key) st_lookup(table,key,(char **) 0)
110 /**Macro***********************************************************************
112 Synopsis [Returns the number of entries in the table `table'.]
114 Description [Returns the number of entries in the table `table'.]
116 SideEffects [None]
118 SeeAlso []
120 ******************************************************************************/
121 #define st_count(table) ((table)->num_entries)
124 /**Macro***********************************************************************
126 Synopsis [Iteration macro.]
128 Description [An iteration macro which loops over all the entries in
129 `table', setting `key' to point to the key and `value' to the
130 associated value (if it is not nil). `gen' is a generator variable
131 used internally. Sample usage:
132 <pre>
133 char *key, *value;
134 </pre>
135 <pre>
136 st_generator *gen;
137 </pre>
138 <pre>
140 st_foreach_item(table, gen, &key, &value) {
141 </pre>
142 <pre>
143 process_item(value);
144 </pre>
145 <pre>
147 </pre>
150 SideEffects [None]
152 SeeAlso [st_foreach_item_int st_foreach]
154 ******************************************************************************/
155 #define st_foreach_item(table, gen, key, value) \
156 for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);)
159 /**Macro***********************************************************************
161 Synopsis [Iteration macro.]
163 Description [An iteration macro which loops over all the entries in
164 `table', setting `key' to point to the key and `value' to the
165 associated value (if it is not nil). `value' is assumed to be a
166 pointer to an integer. `gen' is a generator variable used
167 internally. Sample usage:
168 <pre>
169 char *key;
170 </pre>
171 <pre>
172 int value;
173 </pre>
174 <pre>
175 st_generator *gen;
176 </pre>
177 <pre>
179 st_foreach_item_int(table, gen, &key, &value) {
180 </pre>
181 <pre>
182 process_item(value);
183 </pre>
184 <pre>
186 </pre>
189 SideEffects [None]
191 SeeAlso [st_foreach_item st_foreach]
193 ******************************************************************************/
194 #define st_foreach_item_int(table, gen, key, value) \
195 for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);)
197 /**AutomaticStart*************************************************************/
199 /*---------------------------------------------------------------------------*/
200 /* Function prototypes */
201 /*---------------------------------------------------------------------------*/
203 extern st_table *st_init_table_with_params (ST_PFICPCP, ST_PFICPI, int, int, double, int);
204 extern st_table *st_init_table (ST_PFICPCP, ST_PFICPI);
205 extern void st_free_table (st_table *);
206 extern int st_lookup (st_table *, void *, void *);
207 extern int st_lookup_int (st_table *, void *, int *);
208 extern int st_insert (st_table *, void *, void *);
209 extern int st_add_direct (st_table *, void *, void *);
210 extern int st_find_or_add (st_table *, void *, void *);
211 extern int st_find (st_table *, void *, void *);
212 extern st_table *st_copy (st_table *);
213 extern int st_delete (st_table *, void *, void *);
214 extern int st_delete_int (st_table *, void *, int *);
215 extern int st_foreach (st_table *, ST_PFSR, char *);
216 extern int st_strhash (char *, int);
217 extern int st_numhash (char *, int);
218 extern int st_ptrhash (char *, int);
219 extern int st_numcmp (const char *, const char *);
220 extern int st_ptrcmp (const char *, const char *);
221 extern st_generator *st_init_gen (st_table *);
222 extern int st_gen (st_generator *, void *, void *);
223 extern int st_gen_int (st_generator *, void *, int *);
224 extern void st_free_gen (st_generator *);
226 /**AutomaticEnd***************************************************************/
228 #ifdef __cplusplus
229 } /* end of extern "C" */
230 #endif
232 #endif /* ST_INCLUDED */