abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stmm.h
Go to the documentation of this file.
1 /*
2  * Revision Control Information
3  *
4  * /projects/hsis/CVS/utilities/st/st.h,v
5  * serdar
6  * 1.1
7  * 1993/07/29 01:00:21
8  *
9  */
10 /* LINTLIBRARY */
11 
12 /* /projects/hsis/CVS/utilities/st/st.h,v 1.1 1993/07/29 01:00:21 serdar Exp */
13 
14 #ifndef ABC__misc__st__stmm_h
15 #define ABC__misc__st__stmm_h
16 
17 #include "misc/util/abc_global.h"
18 
20 
21 
22 /* These are potential duplicates. */
23 #ifndef EXTERN
24 # ifdef __cplusplus
25 # ifdef ABC_NAMESPACE
26 # define EXTERN extern
27 # else
28 # define EXTERN extern "C"
29 # endif
30 # else
31 # define EXTERN extern
32 # endif
33 #endif
34 
35 #ifndef ARGS
36 #define ARGS(protos) protos
37 #endif
38 
39 typedef int (*stmm_compare_func_type)(const char*, const char*);
40 typedef int (*stmm_hash_func_type)(const char*, int);
41 
43 typedef struct stmm_table stmm_table;
45 
47 {
48  char *key;
49  char *record;
51 };
52 
53 struct stmm_table
54 {
57  int num_bins;
61  double grow_factor;
63  // memory manager to improve runtime and prevent memory fragmentation
64  // added by alanmi - January 16, 2003
65  void * pMemMan;
66 };
67 
69 {
72  int index;
73 };
74 
75 #define stmm_is_member(table,key) stmm_lookup(table,key,(char **) 0)
76 #define stmm_count(table) ((table)->num_entries)
77 
80 
81 typedef enum stmm_retval (*STMM_PFSR) (char *, char *, char *);
82 
84 ARGS ((stmm_compare_func_type compare, stmm_hash_func_type hash, int size, int density, double grow_factor, int reorder_flag));
87 EXTERN int stmm_lookup ARGS ((stmm_table *, char *, char **));
88 EXTERN int stmm_lookup_int ARGS ((stmm_table *, char *, int *));
89 EXTERN int stmm_insert ARGS ((stmm_table *, char *, char *));
90 EXTERN int stmm_add_direct ARGS ((stmm_table *, char *, char *));
91 EXTERN int stmm_find_or_add ARGS ((stmm_table *, char *, char ***));
92 EXTERN int stmm_find ARGS ((stmm_table *, char *, char ***));
94 EXTERN int stmm_delete ARGS ((stmm_table *, char **, char **));
95 EXTERN int stmm_delete_int ARGS ((stmm_table *, long *, char **));
96 EXTERN int stmm_foreach ARGS ((stmm_table *, STMM_PFSR, char *));
97 EXTERN int stmm_strhash ARGS ((const char *, int));
98 EXTERN int stmm_numhash ARGS ((const char *, int));
99 EXTERN int stmm_ptrhash ARGS ((const char *, int));
100 EXTERN int stmm_numcmp ARGS ((const char *, const char *));
101 EXTERN int stmm_ptrcmp ARGS ((const char *, const char *));
103 EXTERN int stmm_gen ARGS ((stmm_generator *, char **, char **));
104 EXTERN int stmm_gen_int ARGS ((stmm_generator *, char **, long *));
106 // additional functions
107 EXTERN void stmm_clean ARGS ((stmm_table *));
108 
109 
110 
111 #define STMM_DEFAULT_MAX_DENSITY 5
112 #define STMM_DEFAULT_INIT_TABLE_SIZE 11
113 #define STMM_DEFAULT_GROW_FACTOR 2.0
114 #define STMM_DEFAULT_REORDER_FLAG 0
115 
116 // added by Zhihong: no need for memory allocation
117 #define stmm_foreach_item2(tb, /* stmm_generator */gen, key, value) \
118  for(gen.table=(tb), gen.entry=NULL, gen.index=0; \
119  stmm_gen(&(gen),key,value);)
120 
121 #define stmm_foreach_item(table, gen, key, value) \
122  for(gen=stmm_init_gen(table); stmm_gen(gen,key,value) || (stmm_free_gen(gen),0);)
123 
124 #define stmm_foreach_item_int(table, gen, key, value) \
125  for(gen=stmm_init_gen(table); stmm_gen_int(gen,key,value) || (stmm_free_gen(gen),0);)
126 
127 #define STMM_OUT_OF_MEM -10000
128 
129 /*
130 
131 // consider adding these other other similar definitions
132 #define st__table stmm_table
133 #define st__insert stmm_insert
134 #define st__delete stmm_delete
135 #define st__lookup stmm_lookup
136 #define st__init_table stmm_init_table
137 #define st__free_table stmm_free_table
138 
139 */
140 
141 
142 
144 
145 
146 
147 #endif /* STMM_INCLUDED */
char * key
Definition: stmm.h:48
int stmm_foreach(stmm_table *table, enum stmm_retval(*func)(char *, char *, char *), char *arg)
Definition: stmm.c:482
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition: stmm.c:69
Definition: stmm.h:79
stmm_compare_func_type compare
Definition: stmm.h:55
stmm_retval
Definition: stmm.h:78
int num_bins
Definition: stmm.h:57
int(* stmm_hash_func_type)(const char *, int)
Definition: stmm.h:40
int stmm_insert(stmm_table *table, char *key, char *value)
Definition: stmm.c:200
int stmm_lookup_int(stmm_table *table, char *key, int *value)
Definition: stmm.c:156
stmm_table_entry ** bins
Definition: stmm.h:62
int reorder_flag
Definition: stmm.h:60
stmm_table * stmm_init_table_with_params(stmm_compare_func_type compare, stmm_hash_func_type hash, int size, int density, double grow_factor, int reorder_flag)
Definition: stmm.c:35
int stmm_gen_int(stmm_generator *gen, char **key_p, long *value_p)
Definition: stmm.c:594
int stmm_numcmp(const char *x, const char *y)
Definition: stmm.c:539
int index
Definition: stmm.h:72
void stmm_clean(stmm_table *table)
Definition: stmm.c:105
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition: stmm.c:134
int stmm_ptrhash(const char *x, int size)
Definition: stmm.c:533
void stmm_free_gen(stmm_generator *gen)
Definition: stmm.c:622
char * record
Definition: stmm.h:49
static uint32_t hash(uint32_t x)
Definition: Map.h:38
static int size
Definition: cuddSign.c:86
Definition: stmm.h:46
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
Definition: abc_global.h:105
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition: stmm.c:266
#define ABC_NAMESPACE_HEADER_END
Definition: abc_global.h:106
stmm_hash_func_type hash
Definition: stmm.h:56
int num_entries
Definition: stmm.h:58
int stmm_strhash(const char *string, int modulus)
Definition: stmm.c:514
int stmm_ptrcmp(const char *x, const char *y)
Definition: stmm.c:545
void stmm_free_table(stmm_table *table)
Definition: stmm.c:79
enum stmm_retval(* STMM_PFSR)(char *, char *, char *)
Definition: stmm.h:81
int(* stmm_compare_func_type)(const char *, const char *)
Definition: stmm.h:39
stmm_table_entry * next
Definition: stmm.h:50
stmm_table_entry * entry
Definition: stmm.h:71
int stmm_numhash(const char *x, int size)
Definition: stmm.c:527
int stmm_gen(stmm_generator *gen, char **key_p, char **value_p)
Definition: stmm.c:567
int stmm_delete_int(stmm_table *table, long *keyp, char **value)
Definition: stmm.c:456
stmm_table * table
Definition: stmm.h:70
int stmm_add_direct(stmm_table *table, char *key, char *value)
Definition: stmm.c:238
int max_density
Definition: stmm.h:59
#define EXTERN
Definition: stmm.h:31
int stmm_delete(stmm_table *table, char **keyp, char **value)
Definition: stmm.c:430
double grow_factor
Definition: stmm.h:61
#define ARGS(protos)
Definition: stmm.h:36
stmm_table * stmm_copy(stmm_table *old_table)
Definition: stmm.c:374
int stmm_find(stmm_table *table, char *key, char ***slot)
Definition: stmm.c:306
void * pMemMan
Definition: stmm.h:65
stmm_generator * stmm_init_gen(stmm_table *table)
Definition: stmm.c:551