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) {
51 newTable->
hash = hash;
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);\
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++;\
182 if (table->num_entries/table->num_bins >= table->max_density) {
189 if (newEntry == NULL) {
192 newEntry->
key = (
char *)
key;
194 newEntry->
next = table->bins[hash_val];
195 table->bins[hash_val] = newEntry;
196 table->num_entries++;
211 if (table->num_entries / table->num_bins >= table->max_density) {
218 if (newEntry == NULL) {
223 newEntry->
next = table->bins[hash_val];
224 table->bins[hash_val] = newEntry;
225 table->num_entries++;
240 if (table->num_entries / table->num_bins >= table->max_density) {
247 if (newEntry == NULL) {
251 newEntry->
record = (
char *) 0;
252 newEntry->
next = table->bins[hash_val];
253 table->bins[hash_val] = newEntry;
254 table->num_entries++;
255 if (slot != NULL) *slot = &newEntry->
record;
258 if (slot != NULL) *slot = &ptr->
record;
287 int i, old_num_bins, hash_val, old_num_entries;
290 old_bins = table->bins;
291 old_num_bins = table->num_bins;
292 old_num_entries = table->num_entries;
295 table->num_bins = (int)(table->grow_factor * old_num_bins);
296 if (table->num_bins % 2 == 0) {
297 table->num_bins += 1;
299 table->num_entries = 0;
301 if (table->bins == NULL) {
302 table->bins = old_bins;
303 table->num_bins = old_num_bins;
304 table->num_entries = old_num_entries;
308 for (i = 0; i < table->num_bins; i++) {
313 for (i = 0; i < old_num_bins; i++) {
315 while (ptr != NULL) {
318 ptr->
next = table->bins[hash_val];
319 table->bins[hash_val] = ptr;
320 table->num_entries++;
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;
393 table->num_entries--;
401 char *
key = (
char *) *keyp;
414 *keyp = (long) ptr->
key;
416 table->num_entries--;
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;
439 table->num_entries--;
451 unsigned char * ustring = (
unsigned char *)
string;
454 while ((c = *ustring++) !=
'\0') {
457 return (
int)(val%modulus);
505 if (gen->
entry == NULL) {
507 for(i = gen->
index; i < gen->table->num_bins; i++) {
514 if (gen->
entry == NULL) {
532 if (gen->
entry == NULL) {
534 for(i = gen->
index; i < gen->table->num_bins; i++) {
541 if (gen->
entry == NULL) {
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_NAMESPACE_IMPL_START typedef signed char value
int st__gen(st__generator *gen, const char **key_p, char **value_p)
int st__foreach(st__table *table, enum st__retval(*func)(char *, char *, char *), char *arg)
int st__delete_int(st__table *table, long *keyp, char **value)
st__table * st__copy(st__table *old_table)
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)
int st__delete(st__table *table, const char **keyp, char **value)
#define st__PTRHASH(x, size)
int st__ptrhash(const char *, int)
int st__find_or_add(st__table *table, char *key, char ***slot)
int st__ptrcmp(const char *, const char *)
#define st__NUMHASH(x, size)
#define do_hash(key, table)
#define FIND_ENTRY(table, hash_val, key, ptr, last)
void st__free_gen(st__generator *gen)
int st__find(st__table *table, char *key, char ***slot)
int st__strhash(const char *string, int modulus)
int st__numhash(const char *, int)
int st__lookup(st__table *table, const char *key, char **value)
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
int st__gen_int(st__generator *gen, const char **key_p, long *value_p)
int st__numcmp(const char *, const char *)
st__generator * st__init_gen(st__table *table)
int st__add_direct(st__table *table, char *key, char *value)
int st__insert(st__table *table, const char *key, char *value)
void st__free_table(st__table *table)
int(* st__compare_func_type)(const char *, const char *)
#define st__DEFAULT_GROW_FACTOR
#define st__DEFAULT_MAX_DENSITY
#define st__DEFAULT_REORDER_FLAG
#define st__DEFAULT_INIT_TABLE_SIZE
int(* st__hash_func_type)(const char *, int)
st__compare_func_type compare