19 #define st__NUMCMP(x,y) ((x) != (y))
20 #define st__NUMHASH(x,size) (Abc_AbsInt((long)x)%(size))
22 #define st__PTRHASH(x,size) ((int)(((ABC_PTRUINT_T)(x)>>2)%size))
23 #define EQUAL(func, x, y) \
24 ((((func) == st__numcmp) || ((func) == st__ptrcmp)) ?\
25 (st__NUMCMP((x),(y)) == 0) : ((*func)((x), (y)) == 0))
28 #define do_hash(key, table)\
29 ((table->hash == st__ptrhash) ? st__PTRHASH((key),(table)->num_bins) :\
30 (table->hash == st__numhash) ? st__NUMHASH((key), (table)->num_bins) :\
31 (*table->hash)((key), (table)->num_bins))
47 if (newTable == NULL) {
61 if (newTable->
bins == NULL) {
65 for(i = 0; i <
size; i++) {
66 newTable->
bins[i] = 0;
86 for(i = 0; i < table->
num_bins ; i++) {
98 #define PTR_NOT_EQUAL(table, ptr, user_key)\
99 (ptr != NULL && !EQUAL(table->compare, user_key, (ptr)->key))
101 #define FIND_ENTRY(table, hash_val, key, ptr, last) \
102 (last) = &(table)->bins[hash_val];\
104 while (PTR_NOT_EQUAL((table), (ptr), (key))) {\
105 (last) = &(ptr)->next; (ptr) = *(last);\
107 if ((ptr) != NULL && (table)->reorder_flag) {\
108 *(last) = (ptr)->next;\
109 (ptr)->next = (table)->bins[hash_val];\
110 (table)->bins[hash_val] = (ptr);\
119 hash_val =
do_hash(key, table);
139 hash_val =
do_hash(key, table);
147 *value = (long) ptr->
record;
154 #define ADD_DIRECT(table, key, value, hash_val, new)\
156 if (table->num_entries/table->num_bins >= table->max_density) {\
158 hash_val = do_hash(key,table);\
161 new = ABC_ALLOC( st__table_entry, 1);\
164 new->record = value;\
165 new->next = table->bins[hash_val];\
166 table->bins[hash_val] = new;\
167 table->num_entries++;\
177 hash_val =
do_hash(key, table);
186 hash_val =
do_hash(key, table);
189 if (newEntry == NULL) {
192 newEntry->
key = (
char *)key;
194 newEntry->
next = table->
bins[hash_val];
195 table->
bins[hash_val] = newEntry;
210 hash_val =
do_hash(key, table);
216 hash_val =
do_hash(key, table);
218 if (newEntry == NULL) {
223 newEntry->
next = table->
bins[hash_val];
224 table->
bins[hash_val] = newEntry;
235 hash_val =
do_hash(key, table);
244 hash_val =
do_hash(key, table);
247 if (newEntry == NULL) {
251 newEntry->
record = (
char *) 0;
252 newEntry->
next = table->
bins[hash_val];
253 table->
bins[hash_val] = newEntry;
255 if (slot != NULL) *slot = &newEntry->
record;
258 if (slot != NULL) *slot = &ptr->
record;
269 hash_val =
do_hash(key, table);
287 int i, old_num_bins, hash_val, old_num_entries;
290 old_bins = table->
bins;
301 if (table->
bins == NULL) {
302 table->
bins = old_bins;
308 for (i = 0; i < table->
num_bins; i++) {
313 for (i = 0; i < old_num_bins; i++) {
315 while (ptr != NULL) {
319 table->
bins[hash_val] = ptr;
334 int i, j, num_bins = old_table->
num_bins;
337 if (newEntry_table == NULL) {
341 *newEntry_table = *old_table;
343 if (newEntry_table->
bins == NULL) {
347 for(i = 0; i < num_bins ; i++) {
348 newEntry_table->
bins[i] = NULL;
349 ptr = old_table->
bins[i];
350 while (ptr != NULL) {
352 if (newEntry == NULL) {
353 for (j = 0; j <= i; j++) {
354 newEntryptr = newEntry_table->
bins[j];
355 while (newEntryptr != NULL) {
356 next = newEntryptr->
next;
366 newEntry->
next = newEntry_table->
bins[i];
367 newEntry_table->
bins[i] = newEntry;
371 return newEntry_table;
378 const char *
key = *keyp;
381 hash_val =
do_hash(key, table);
390 if (value != NULL) *value = ptr->
record;
401 char *
key = (
char *) *keyp;
404 hash_val =
do_hash(key, table);
413 if (value != NULL) *value = ptr->
record;
414 *keyp = (long) ptr->
key;
427 for(i = 0; i < table->
num_bins; i++) {
428 last = &table->
bins[i]; ptr = *last;
429 while (ptr != NULL) {
430 retval = (*func)(ptr->
key, ptr->
record, arg);
433 last = &ptr->
next; ptr = *last;
454 while ((c = *
string++) !=
'\0') {
458 return ((val < 0) ? -val : val)%modulus;
506 if (gen->
entry == NULL) {
515 if (gen->
entry == NULL) {
533 if (gen->
entry == NULL) {
542 if (gen->
entry == NULL) {
void st__free_table(st__table *table)
st__compare_func_type compare
static int rehash(st__table *table)
#define st__DEFAULT_REORDER_FLAG
void st__free_gen(st__generator *gen)
int st__delete(st__table *table, const char **keyp, char **value)
int st__insert(st__table *table, const char *key, char *value)
#define FIND_ENTRY(table, hash_val, key, ptr, last)
#define st__DEFAULT_GROW_FACTOR
int st__ptrcmp(const char *, const char *)
int(* st__hash_func_type)(const char *, int)
#define ABC_ALLOC(type, num)
int st__lookup_int(st__table *table, char *key, int *value)
st__table * st__init_table_with_params(st__compare_func_type compare, st__hash_func_type hash, int size, int density, double grow_factor, int reorder_flag)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
int st__strhash(const char *string, int modulus)
int st__find_or_add(st__table *table, char *key, char ***slot)
int st__numcmp(const char *, const char *)
int st__gen_int(st__generator *gen, const char **key_p, long *value_p)
#define st__NUMHASH(x, size)
#define ABC_NAMESPACE_IMPL_END
static uint32_t hash(uint32_t x)
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
int st__find(st__table *table, char *key, char ***slot)
st__generator * st__init_gen(st__table *table)
int st__delete_int(st__table *table, long *keyp, char **value)
#define ABC_NAMESPACE_IMPL_START
#define st__DEFAULT_MAX_DENSITY
int st__lookup(st__table *table, const char *key, char **value)
#define do_hash(key, table)
st__table * st__copy(st__table *old_table)
int st__add_direct(st__table *table, char *key, char *value)
int(* st__compare_func_type)(const char *, const char *)
#define st__PTRHASH(x, size)
int st__ptrhash(const char *, int)
int st__gen(st__generator *gen, const char **key_p, char **value_p)
#define st__DEFAULT_INIT_TABLE_SIZE
int st__numhash(const char *, int)