17 #define STMM_NUMCMP(x,y) ((x) != (y))
18 #define STMM_NUMHASH(x,size) (Abc_AbsInt((long)x)%(size))
20 #define STMM_PTRHASH(x,size) ((int)(((ABC_PTRUINT_T)(x)>>2)%size))
21 #define EQUAL(func, x, y) \
22 ((((func) == stmm_numcmp) || ((func) == stmm_ptrcmp)) ?\
23 (STMM_NUMCMP((x),(y)) == 0) : ((*func)((x), (y)) == 0))
26 #define do_hash(key, table)\
27 ((table->hash == stmm_ptrhash) ? STMM_PTRHASH((key),(table)->num_bins) :\
28 (table->hash == stmm_numhash) ? STMM_NUMHASH((key), (table)->num_bins) :\
29 (*table->hash)((key), (table)->num_bins))
41 if (newTable == NULL) {
55 if (newTable->
bins == NULL) {
59 for (i = 0; i <
size; i++) {
60 newTable->
bins[i] = 0;
109 for (i = 0; i < table->
num_bins; i++)
110 table->
bins[i] = NULL;
118 #define PTR_NOT_EQUAL(table, ptr, user_key)\
119 (ptr != NULL && !EQUAL(table->compare, user_key, (ptr)->key))
121 #define FIND_ENTRY(table, hash_val, key, ptr, last) \
122 (last) = &(table)->bins[hash_val];\
124 while (PTR_NOT_EQUAL((table), (ptr), (key))) {\
125 (last) = &(ptr)->next; (ptr) = *(last);\
127 if ((ptr) != NULL && (table)->reorder_flag) {\
128 *(last) = (ptr)->next;\
129 (ptr)->next = (table)->bins[hash_val];\
130 (table)->bins[hash_val] = (ptr);\
139 hash_val =
do_hash (key, table);
161 hash_val =
do_hash (key, table);
171 *value = (long) ptr->
record;
183 #define ADD_DIRECT(table, key, value, hash_val, new)\
185 if (table->num_entries/table->num_bins >= table->max_density) {\
187 hash_val = do_hash(key,table);\
190 new = (stmm_table_entry *)Extra_MmFixedEntryFetch( (Extra_MmFixed_t *)table->pMemMan );\
193 new->record = value;\
194 new->next = table->bins[hash_val];\
195 table->bins[hash_val] = new;\
196 table->num_entries++;\
206 hash_val =
do_hash (key, table);
215 hash_val =
do_hash (key, table);
220 if (newEntry == NULL) {
226 newEntry->
next = table->
bins[hash_val];
227 table->
bins[hash_val] = newEntry;
243 hash_val =
do_hash (key, table);
249 hash_val =
do_hash (key, table);
253 if (newEntry == NULL) {
259 newEntry->
next = table->
bins[hash_val];
260 table->
bins[hash_val] = newEntry;
271 hash_val =
do_hash (key, table);
280 hash_val =
do_hash (key, table);
285 if (newEntry == NULL) {
290 newEntry->
record = (
char *) 0;
291 newEntry->
next = table->
bins[hash_val];
292 table->
bins[hash_val] = newEntry;
295 *slot = &newEntry->
record;
311 hash_val =
do_hash (key, table);
331 int i, old_num_bins, hash_val, old_num_entries;
334 old_bins = table->
bins;
345 if (table->
bins == NULL) {
346 table->
bins = old_bins;
352 for (i = 0; i < table->
num_bins; i++) {
357 for (i = 0; i < old_num_bins; i++) {
359 while (ptr != NULL) {
363 table->
bins[hash_val] = ptr;
378 int i, num_bins = old_table->
num_bins;
381 if (newEntry_table == NULL) {
385 *newEntry_table = *old_table;
387 if (newEntry_table->
bins == NULL) {
395 for (i = 0; i < num_bins; i++) {
396 newEntry_table->
bins[i] = NULL;
397 ptr = old_table->
bins[i];
398 while (ptr != NULL) {
401 if (newEntry == NULL) {
421 newEntry->
next = newEntry_table->
bins[i];
422 newEntry_table->
bins[i] = newEntry;
426 return newEntry_table;
436 hash_val =
do_hash (key, table);
459 char *
key = (
char *) *keyp;
462 hash_val =
do_hash (key, table);
473 *keyp = (long) ptr->
key;
488 for (i = 0; i < table->
num_bins; i++) {
489 last = &table->
bins[i];
491 while (ptr != NULL) {
492 retval = (*func) (ptr->
key, ptr->
record, arg);
519 while ((c = *
string++) !=
'\0') {
523 return ((val < 0) ? -val : val) % modulus;
571 if (gen->
entry == NULL) {
580 if (gen->
entry == NULL) {
598 if (gen->
entry == NULL) {
607 if (gen->
entry == NULL) {
#define STMM_DEFAULT_REORDER_FLAG
static int rehash(stmm_table *table)
int stmm_foreach(stmm_table *table, enum stmm_retval(*func)(char *, char *, char *), char *arg)
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
#define STMM_NUMHASH(x, size)
stmm_compare_func_type compare
int(* stmm_hash_func_type)(const char *, int)
int stmm_insert(stmm_table *table, char *key, char *value)
int stmm_lookup_int(stmm_table *table, char *key, int *value)
#define ABC_ALLOC(type, num)
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)
int stmm_gen_int(stmm_generator *gen, char **key_p, long *value_p)
int stmm_numcmp(const char *x, const char *y)
void stmm_clean(stmm_table *table)
int stmm_lookup(stmm_table *table, char *key, char **value)
int stmm_ptrhash(const char *x, int size)
#define FIND_ENTRY(table, hash_val, key, ptr, last)
void stmm_free_gen(stmm_generator *gen)
#define ABC_NAMESPACE_IMPL_END
#define STMM_DEFAULT_GROW_FACTOR
static uint32_t hash(uint32_t x)
#define STMM_PTRHASH(x, size)
#define STMM_DEFAULT_INIT_TABLE_SIZE
#define do_hash(key, table)
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
int stmm_strhash(const char *string, int modulus)
#define ABC_NAMESPACE_IMPL_START
int stmm_ptrcmp(const char *x, const char *y)
void stmm_free_table(stmm_table *table)
int(* stmm_compare_func_type)(const char *, const char *)
int stmm_numhash(const char *x, int size)
int stmm_gen(stmm_generator *gen, char **key_p, char **value_p)
int stmm_delete_int(stmm_table *table, long *keyp, char **value)
int stmm_add_direct(stmm_table *table, char *key, char *value)
int stmm_delete(stmm_table *table, char **keyp, char **value)
#define STMM_DEFAULT_MAX_DENSITY
stmm_table * stmm_copy(stmm_table *old_table)
#define STMM_NUMCMP(x, y)
int stmm_find(stmm_table *table, char *key, char ***slot)
stmm_generator * stmm_init_gen(stmm_table *table)