00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef ST_INCLUDED
00015 #define ST_INCLUDED
00016
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020
00021 typedef struct st_table_entry st_table_entry;
00022 struct st_table_entry {
00023 char *key;
00024 char *record;
00025 st_table_entry *next;
00026 };
00027
00028 typedef struct st_table st_table;
00029 struct st_table {
00030 int (*compare)();
00031 int (*hash)();
00032 int num_bins;
00033 int num_entries;
00034 int max_density;
00035 int reorder_flag;
00036 double grow_factor;
00037 st_table_entry **bins;
00038 };
00039
00040 typedef struct st_generator st_generator;
00041 struct st_generator {
00042 st_table *table;
00043 st_table_entry *entry;
00044 int index;
00045 };
00046
00047 #define st_is_member(table,key) st_lookup(table,key,(char **) 0)
00048 #define st_count(table) ((table)->num_entries)
00049
00050 enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
00051
00052 typedef enum st_retval (*ST_PFSR)();
00053 typedef int (*ST_PFI)();
00054
00055 extern st_table *st_init_table_with_params (ST_PFI, ST_PFI, int, int, double, int);
00056 extern st_table *st_init_table (ST_PFI, ST_PFI);
00057 extern void st_free_table (st_table *);
00058 extern int st_lookup (st_table *, char *, char **);
00059 extern int st_lookup_int (st_table *, char *, int *);
00060 extern int st_insert (st_table *, char *, char *);
00061 extern int st_add_direct (st_table *, char *, char *);
00062 extern int st_find_or_add (st_table *, char *, char ***);
00063 extern int st_find (st_table *, char *, char ***);
00064 extern st_table *st_copy (st_table *);
00065 extern int st_delete (st_table *, char **, char **);
00066 extern int st_delete_int (st_table *, long *, char **);
00067 extern int st_foreach (st_table *, ST_PFSR, char *);
00068 extern int st_strhash (char *, int);
00069 extern int st_numhash (char *, int);
00070 extern int st_ptrhash (char *, int);
00071 extern int st_numcmp (char *, char *);
00072 extern int st_ptrcmp (char *, char *);
00073 extern st_generator *st_init_gen (st_table *);
00074 extern int st_gen (st_generator *, char **, char **);
00075 extern int st_gen_int (st_generator *, char **, long *);
00076 extern void st_free_gen (st_generator *);
00077
00078
00079 #define ST_DEFAULT_MAX_DENSITY 5
00080 #define ST_DEFAULT_INIT_TABLE_SIZE 11
00081 #define ST_DEFAULT_GROW_FACTOR 2.0
00082 #define ST_DEFAULT_REORDER_FLAG 0
00083
00084 #define st_foreach_item(table, gen, key, value) \
00085 for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);)
00086
00087 #define st_foreach_item_int(table, gen, key, value) \
00088 for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);)
00089
00090 #define ST_OUT_OF_MEM -10000
00091
00092 #ifdef __cplusplus
00093 }
00094 #endif
00095
00096 #endif