1 /**CHeaderFile*****************************************************************
7 Synopsis [Symbol table package.]
9 Description [The st library provides functions to create, maintain,
10 and query symbol tables.]
18 Revision [$Id: st.h,v 1.10 2004/01/02 07:40:31 fabio Exp fabio $]
20 ******************************************************************************/
25 /*---------------------------------------------------------------------------*/
27 /*---------------------------------------------------------------------------*/
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
{
59 typedef struct st_table st_table
;
61 int (*compare
)(const char *, const char *);
62 int (*hash
)(char *, int);
68 st_table_entry
**bins
;
71 typedef struct st_generator st_generator
;
74 st_table_entry
*entry
;
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
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'.]
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:
140 st_foreach_item(table, gen, &key, &value) {
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:
179 st_foreach_item_int(table, gen, &key, &value) {
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***************************************************************/
229 } /* end of extern "C" */
232 #endif /* ST_INCLUDED */