00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef STMM_INCLUDED
00015 #define STMM_INCLUDED
00016
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020
00021 #include "extra.h"
00022
00023 typedef struct stmm_table_entry stmm_table_entry;
00024 typedef struct stmm_table stmm_table;
00025 typedef struct stmm_generator stmm_generator;
00026
00027 struct stmm_table_entry
00028 {
00029 char *key;
00030 char *record;
00031 stmm_table_entry *next;
00032 };
00033
00034 struct stmm_table
00035 {
00036 int (*compare) ();
00037 int (*hash) ();
00038 int num_bins;
00039 int num_entries;
00040 int max_density;
00041 int reorder_flag;
00042 double grow_factor;
00043 stmm_table_entry **bins;
00044
00045
00046 Extra_MmFixed_t *pMemMan;
00047 };
00048
00049 struct stmm_generator
00050 {
00051 stmm_table *table;
00052 stmm_table_entry *entry;
00053 int index;
00054 };
00055
00056 #define stmm_is_member(table,key) stmm_lookup(table,key,(char **) 0)
00057 #define stmm_count(table) ((table)->num_entries)
00058
00059 enum stmm_retval
00060 { STMM_CONTINUE, STMM_STOP, STMM_DELETE };
00061
00062 typedef enum stmm_retval (*STMM_PFSR) ();
00063 typedef int (*STMM_PFI) ();
00064
00065 EXTERN stmm_table *stmm_init_table_with_params
00066 ARGS ((STMM_PFI, STMM_PFI, int, int, double, int));
00067 EXTERN stmm_table *stmm_init_table ARGS ((STMM_PFI, STMM_PFI));
00068 EXTERN void stmm_free_table ARGS ((stmm_table *));
00069 EXTERN int stmm_lookup ARGS ((stmm_table *, char *, char **));
00070 EXTERN int stmm_lookup_int ARGS ((stmm_table *, char *, int *));
00071 EXTERN int stmm_insert ARGS ((stmm_table *, char *, char *));
00072 EXTERN int stmm_add_direct ARGS ((stmm_table *, char *, char *));
00073 EXTERN int stmm_find_or_add ARGS ((stmm_table *, char *, char ***));
00074 EXTERN int stmm_find ARGS ((stmm_table *, char *, char ***));
00075 EXTERN stmm_table *stmm_copy ARGS ((stmm_table *));
00076 EXTERN int stmm_delete ARGS ((stmm_table *, char **, char **));
00077 EXTERN int stmm_delete_int ARGS ((stmm_table *, long *, char **));
00078 EXTERN int stmm_foreach ARGS ((stmm_table *, STMM_PFSR, char *));
00079 EXTERN int stmm_strhash ARGS ((char *, int));
00080 EXTERN int stmm_numhash ARGS ((char *, int));
00081 EXTERN int stmm_ptrhash ARGS ((char *, int));
00082 EXTERN int stmm_numcmp ARGS ((char *, char *));
00083 EXTERN int stmm_ptrcmp ARGS ((char *, char *));
00084 EXTERN stmm_generator *stmm_init_gen ARGS ((stmm_table *));
00085 EXTERN int stmm_gen ARGS ((stmm_generator *, char **, char **));
00086 EXTERN int stmm_gen_int ARGS ((stmm_generator *, char **, long *));
00087 EXTERN void stmm_free_gen ARGS ((stmm_generator *));
00088
00089 EXTERN void stmm_clean ARGS ((stmm_table *));
00090
00091
00092
00093 #define STMM_DEFAULT_MAX_DENSITY 5
00094 #define STMM_DEFAULT_INIT_TABLE_SIZE 11
00095 #define STMM_DEFAULT_GROW_FACTOR 2.0
00096 #define STMM_DEFAULT_REORDER_FLAG 0
00097
00098
00099 #define stmm_foreach_item2(tb, gen, key, value) \
00100 for(gen.table=(tb), gen.entry=NULL, gen.index=0; \
00101 stmm_gen(&(gen),key,value);)
00102
00103 #define stmm_foreach_item(table, gen, key, value) \
00104 for(gen=stmm_init_gen(table); stmm_gen(gen,key,value) || (stmm_free_gen(gen),0);)
00105
00106 #define stmm_foreach_item_int(table, gen, key, value) \
00107 for(gen=stmm_init_gen(table); stmm_gen_int(gen,key,value) || (stmm_free_gen(gen),0);)
00108
00109 #define STMM_OUT_OF_MEM -10000
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 #ifdef __cplusplus
00124 }
00125 #endif
00126
00127 #endif