SVF
st.h
Go to the documentation of this file.
1 
22 #ifndef ST_INCLUDED
23 #define ST_INCLUDED
24 
25 /*---------------------------------------------------------------------------*/
26 /* Nested includes */
27 /*---------------------------------------------------------------------------*/
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*---------------------------------------------------------------------------*/
34 /* Constant declarations */
35 /*---------------------------------------------------------------------------*/
36 
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
42 
43 /*---------------------------------------------------------------------------*/
44 /* Stucture declarations */
45 /*---------------------------------------------------------------------------*/
46 
47 
48 /*---------------------------------------------------------------------------*/
49 /* Type declarations */
50 /*---------------------------------------------------------------------------*/
51 
54  char *key;
55  char *record;
57 };
58 
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;
67  double grow_factor;
69 };
70 
71 typedef struct st_generator st_generator;
72 struct st_generator {
75  int index;
76 };
77 
79 
80 typedef enum st_retval (*ST_PFSR)(char *, char *, char *);
81 
82 typedef int (*ST_PFICPCP)(const char *, const char *); /* type for comparison function */
83 
84 typedef int (*ST_PFICPI)(char *, int); /* type for hash function */
85 
86 /*---------------------------------------------------------------------------*/
87 /* Variable declarations */
88 /*---------------------------------------------------------------------------*/
89 
90 
91 /*---------------------------------------------------------------------------*/
92 /* Macro declarations */
93 /*---------------------------------------------------------------------------*/
94 
107 #define st_is_member(table,key) st_lookup(table,key,(char **) 0)
108 
109 
121 #define st_count(table) ((table)->num_entries)
122 
123 
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);)
157 
158 
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);)
196 
199 /*---------------------------------------------------------------------------*/
200 /* Function prototypes */
201 /*---------------------------------------------------------------------------*/
202 
203 extern st_table *st_init_table_with_params (ST_PFICPCP, ST_PFICPI, int, int, double, int);
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 *);
225 
228 #ifdef __cplusplus
229 } /* end of extern "C" */
230 #endif
231 
232 #endif /* ST_INCLUDED */
Definition: st.h:78
int num_bins
Definition: st.h:63
int st_lookup(st_table *, void *, void *)
Definition: st.c:286
Definition: st.h:60
Definition: st.h:78
int st_lookup_int(st_table *, void *, int *)
Definition: st.c:322
st_table * st_init_table_with_params(ST_PFICPCP, ST_PFICPI, int, int, double, int)
Definition: st.c:199
void st_free_gen(st_generator *)
Definition: st.c:994
int st_foreach(st_table *, ST_PFSR, char *)
Definition: st.c:725
Definition: st.h:78
void st_free_table(st_table *)
Definition: st.c:252
st_table_entry * next
Definition: st.h:56
int st_gen(st_generator *, void *, void *)
Definition: st.c:908
int(* ST_PFICPI)(char *, int)
Definition: st.h:84
enum st_retval(* ST_PFSR)(char *, char *, char *)
Definition: st.h:80
st_generator * st_init_gen(st_table *)
Definition: st.c:870
int max_density
Definition: st.h:65
int st_gen_int(st_generator *, void *, int *)
Definition: st.c:953
int st_insert(st_table *, void *, void *)
Definition: st.c:358
int num_entries
Definition: st.h:64
st_table * table
Definition: st.h:73
Definition: st.h:53
double grow_factor
Definition: st.h:67
int st_strhash(char *, int)
Definition: st.c:766
int st_find_or_add(st_table *, void *, void *)
Definition: st.c:488
int st_ptrcmp(const char *, const char *)
Definition: st.c:849
st_retval
Definition: st.h:78
st_table * st_init_table(ST_PFICPCP, ST_PFICPI)
Definition: st.c:163
int index
Definition: st.h:75
char * record
Definition: st.h:55
char * key
Definition: st.h:54
int st_add_direct(st_table *, void *, void *)
Definition: st.c:410
int st_delete(st_table *, void *, void *)
Definition: st.c:634
int(* ST_PFICPCP)(const char *, const char *)
Definition: st.h:82
int st_numhash(char *, int)
Definition: st.c:792
st_table_entry ** bins
Definition: st.h:68
int st_delete_int(st_table *, void *, int *)
Definition: st.c:675
int st_ptrhash(char *, int)
Definition: st.c:811
int reorder_flag
Definition: st.h:66
int st_numcmp(const char *, const char *)
Definition: st.c:830
st_table * st_copy(st_table *)
Definition: st.c:571
st_table_entry * entry
Definition: st.h:74
int st_find(st_table *, void *, void *)
Definition: st.c:536