From 6130e39b18b5f53902e4eab14f6d5cdde5219563 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Mon, 1 Nov 2010 01:35:04 -0700 Subject: initial commit of public abc --- src/misc/st/st.c | 241 ++++++++++++++++++++----------------------------- src/misc/st/st.h | 50 ++++++----- src/misc/st/stmm.c | 259 +++++++++++++++++++++-------------------------------- src/misc/st/stmm.h | 39 ++++---- 4 files changed, 250 insertions(+), 339 deletions(-) (limited to 'src/misc/st') diff --git a/src/misc/st/st.c b/src/misc/st/st.c index 13445e9e..9705b987 100644 --- a/src/misc/st/st.c +++ b/src/misc/st/st.c @@ -9,9 +9,12 @@ */ #include #include -#include "abc_global.h" + #include "st.h" +ABC_NAMESPACE_IMPL_START + + #define ST_NUMCMP(x,y) ((x) != (y)) #define ST_NUMHASH(x,size) (ABC_ABS((long)x)%(size)) //#define ST_PTRHASH(x,size) ((int)((ABC_PTRUINT_T)(x)>>2)%size) // 64-bit bug fix 9/17/2007 @@ -26,51 +29,46 @@ (table->hash == st_numhash) ? ST_NUMHASH((key), (table)->num_bins) :\ (*table->hash)((key), (table)->num_bins)) -static int rehash(); -int st_numhash(), st_ptrhash(), st_numcmp(), st_ptrcmp(); +static int rehash(st_table *table); + +int st_numhash(const char*, int); +int st_ptrhash(const char*, int); +int st_numcmp(const char*, const char*); +int st_ptrcmp(const char*, const char*); st_table * -st_init_table_with_params(compare, hash, size, density, grow_factor, - reorder_flag) -int (*compare)(); -int (*hash)(); -int size; -int density; -double grow_factor; -int reorder_flag; +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 i; - st_table *new; + st_table *newTable; - new = ABC_ALLOC(st_table, 1); - if (new == NULL) { + newTable = ABC_ALLOC(st_table, 1); + if (newTable == NULL) { return NULL; } - new->compare = compare; - new->hash = hash; - new->num_entries = 0; - new->max_density = density; - new->grow_factor = grow_factor; - new->reorder_flag = reorder_flag; + newTable->compare = compare; + newTable->hash = hash; + newTable->num_entries = 0; + newTable->max_density = density; + newTable->grow_factor = grow_factor; + newTable->reorder_flag = reorder_flag; if (size <= 0) { size = 1; } - new->num_bins = size; - new->bins = ABC_ALLOC(st_table_entry *, size); - if (new->bins == NULL) { - ABC_FREE(new); + newTable->num_bins = size; + newTable->bins = ABC_ALLOC(st_table_entry *, size); + if (newTable->bins == NULL) { + ABC_FREE(newTable); return NULL; } for(i = 0; i < size; i++) { - new->bins[i] = 0; + newTable->bins[i] = 0; } - return new; + return newTable; } st_table * -st_init_table(compare, hash) -int (*compare)(); -int (*hash)(); +st_init_table(st_compare_func_type compare, st_hash_func_type hash) { return st_init_table_with_params(compare, hash, ST_DEFAULT_INIT_TABLE_SIZE, ST_DEFAULT_MAX_DENSITY, @@ -79,8 +77,7 @@ int (*hash)(); } void -st_free_table(table) -st_table *table; +st_free_table(st_table *table) { register st_table_entry *ptr, *next; int i; @@ -113,10 +110,7 @@ st_table *table; } int -st_lookup(table, key, value) -st_table *table; -register char *key; -char **value; +st_lookup(st_table *table, register const char *key, char **value) { int hash_val; register st_table_entry *ptr, **last; @@ -136,10 +130,7 @@ char **value; } int -st_lookup_int(table, key, value) -st_table *table; -register char *key; -int *value; +st_lookup_int(st_table *table, register char *key, int *value) { int hash_val; register st_table_entry *ptr, **last; @@ -176,13 +167,10 @@ int *value; } int -st_insert(table, key, value) -register st_table *table; -register char *key; -char *value; +st_insert(register st_table *table, register const char *key, char *value) { int hash_val; - st_table_entry *new; + st_table_entry *newEntry; register st_table_entry *ptr, **last; hash_val = do_hash(key, table); @@ -196,14 +184,14 @@ char *value; } hash_val = do_hash(key, table); } - new = ABC_ALLOC(st_table_entry, 1); - if (new == NULL) { + newEntry = ABC_ALLOC(st_table_entry, 1); + if (newEntry == NULL) { return ST_OUT_OF_MEM; } - new->key = key; - new->record = value; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = value; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; return 0; } else { @@ -213,13 +201,10 @@ char *value; } int -st_add_direct(table, key, value) -st_table *table; -char *key; -char *value; +st_add_direct(st_table *table, char *key, char *value) { int hash_val; - st_table_entry *new; + st_table_entry *newEntry; hash_val = do_hash(key, table); if (table->num_entries / table->num_bins >= table->max_density) { @@ -228,26 +213,23 @@ char *value; } } hash_val = do_hash(key, table); - new = ABC_ALLOC(st_table_entry, 1); - if (new == NULL) { + newEntry = ABC_ALLOC(st_table_entry, 1); + if (newEntry == NULL) { return ST_OUT_OF_MEM; } - new->key = key; - new->record = value; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = value; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; return 1; } int -st_find_or_add(table, key, slot) -st_table *table; -char *key; -char ***slot; +st_find_or_add(st_table *table, char *key, char ***slot) { int hash_val; - st_table_entry *new, *ptr, **last; + st_table_entry *newEntry, *ptr, **last; hash_val = do_hash(key, table); @@ -260,16 +242,16 @@ char ***slot; } hash_val = do_hash(key, table); } - new = ABC_ALLOC(st_table_entry, 1); - if (new == NULL) { + newEntry = ABC_ALLOC(st_table_entry, 1); + if (newEntry == NULL) { return ST_OUT_OF_MEM; } - new->key = key; - new->record = (char *) 0; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = (char *) 0; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; - if (slot != NULL) *slot = &new->record; + if (slot != NULL) *slot = &newEntry->record; return 0; } else { if (slot != NULL) *slot = &ptr->record; @@ -278,10 +260,7 @@ char ***slot; } int -st_find(table, key, slot) -st_table *table; -char *key; -char ***slot; +st_find(st_table *table, char *key, char ***slot) { int hash_val; st_table_entry *ptr, **last; @@ -301,8 +280,7 @@ char ***slot; } static int -rehash(table) -register st_table *table; +rehash(register st_table *table) { register st_table_entry *ptr, *next, **old_bins; int i, old_num_bins, hash_val, old_num_entries; @@ -348,59 +326,55 @@ register st_table *table; } st_table * -st_copy(old_table) -st_table *old_table; +st_copy(st_table *old_table) { - st_table *new_table; - st_table_entry *ptr, *newptr, *next, *new; + st_table *newEntry_table; + st_table_entry *ptr, *newEntryptr, *next, *newEntry; int i, j, num_bins = old_table->num_bins; - new_table = ABC_ALLOC(st_table, 1); - if (new_table == NULL) { + newEntry_table = ABC_ALLOC(st_table, 1); + if (newEntry_table == NULL) { return NULL; } - *new_table = *old_table; - new_table->bins = ABC_ALLOC(st_table_entry *, num_bins); - if (new_table->bins == NULL) { - ABC_FREE(new_table); + *newEntry_table = *old_table; + newEntry_table->bins = ABC_ALLOC(st_table_entry *, num_bins); + if (newEntry_table->bins == NULL) { + ABC_FREE(newEntry_table); return NULL; } for(i = 0; i < num_bins ; i++) { - new_table->bins[i] = NULL; + newEntry_table->bins[i] = NULL; ptr = old_table->bins[i]; while (ptr != NULL) { - new = ABC_ALLOC(st_table_entry, 1); - if (new == NULL) { + newEntry = ABC_ALLOC(st_table_entry, 1); + if (newEntry == NULL) { for (j = 0; j <= i; j++) { - newptr = new_table->bins[j]; - while (newptr != NULL) { - next = newptr->next; - ABC_FREE(newptr); - newptr = next; + newEntryptr = newEntry_table->bins[j]; + while (newEntryptr != NULL) { + next = newEntryptr->next; + ABC_FREE(newEntryptr); + newEntryptr = next; } } - ABC_FREE(new_table->bins); - ABC_FREE(new_table); + ABC_FREE(newEntry_table->bins); + ABC_FREE(newEntry_table); return NULL; } - *new = *ptr; - new->next = new_table->bins[i]; - new_table->bins[i] = new; + *newEntry = *ptr; + newEntry->next = newEntry_table->bins[i]; + newEntry_table->bins[i] = newEntry; ptr = ptr->next; } } - return new_table; + return newEntry_table; } int -st_delete(table, keyp, value) -register st_table *table; -register char **keyp; -char **value; +st_delete(register st_table *table, register const char **keyp, char **value) { int hash_val; - char *key = *keyp; + const char *key = *keyp; register st_table_entry *ptr, **last; hash_val = do_hash(key, table); @@ -420,10 +394,7 @@ char **value; } int -st_delete_int(table, keyp, value) -register st_table *table; -register long *keyp; -char **value; +st_delete_int(register st_table *table, register long *keyp, char **value) { int hash_val; char *key = (char *) *keyp; @@ -446,10 +417,7 @@ char **value; } int -st_foreach(table, func, arg) -st_table *table; -enum st_retval (*func)(); -char *arg; +st_foreach(st_table *table, enum st_retval (*func)(const char *, char *, char *), char *arg) { st_table_entry *ptr, **last; enum st_retval retval; @@ -477,9 +445,7 @@ char *arg; } int -st_strhash(string, modulus) -register char *string; -int modulus; +st_strhash(const char *string, int modulus) { register int val = 0; register int c; @@ -492,40 +458,31 @@ int modulus; } int -st_numhash(x, size) -char *x; -int size; +st_numhash(const char *x, int size) { return ST_NUMHASH(x, size); } int -st_ptrhash(x, size) -char *x; -int size; +st_ptrhash(const char *x, int size) { return ST_PTRHASH(x, size); } int -st_numcmp(x, y) -char *x; -char *y; +st_numcmp(const char *x, const char *y) { return ST_NUMCMP(x, y); } int -st_ptrcmp(x, y) -char *x; -char *y; +st_ptrcmp(const char *x, const char *y) { return ST_NUMCMP(x, y); } - + st_generator * -st_init_gen(table) -st_table *table; +st_init_gen(st_table *table) { st_generator *gen; @@ -541,10 +498,7 @@ st_table *table; int -st_gen(gen, key_p, value_p) -st_generator *gen; -char **key_p; -char **value_p; +st_gen(st_generator *gen, const char **key_p, char **value_p) { register int i; @@ -571,10 +525,7 @@ char **value_p; int -st_gen_int(gen, key_p, value_p) -st_generator *gen; -char **key_p; -long *value_p; +st_gen_int(st_generator *gen, const char **key_p, long *value_p) { register int i; @@ -601,8 +552,10 @@ long *value_p; void -st_free_gen(gen) -st_generator *gen; +st_free_gen(st_generator *gen) { ABC_FREE(gen); } + +ABC_NAMESPACE_IMPL_END + diff --git a/src/misc/st/st.h b/src/misc/st/st.h index b15f3c83..81bd461e 100644 --- a/src/misc/st/st.h +++ b/src/misc/st/st.h @@ -14,21 +14,25 @@ #ifndef ST_INCLUDED #define ST_INCLUDED -#ifdef __cplusplus -extern "C" { -#endif + +#include "abc_global.h" + +ABC_NAMESPACE_HEADER_START + +typedef int (*st_compare_func_type)(const char*, const char*); +typedef int (*st_hash_func_type)(const char*, int); typedef struct st_table_entry st_table_entry; struct st_table_entry { - char *key; + const char *key; char *record; st_table_entry *next; }; typedef struct st_table st_table; struct st_table { - int (*compare)(); - int (*hash)(); + st_compare_func_type compare; + st_hash_func_type hash; int num_bins; int num_entries; int max_density; @@ -49,30 +53,30 @@ struct st_generator { enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE}; -typedef enum st_retval (*ST_PFSR)(); +typedef enum st_retval (*ST_PFSR)(const char *, char *, char *); typedef int (*ST_PFI)(); -extern st_table *st_init_table_with_params (ST_PFI, ST_PFI, int, int, double, int); -extern st_table *st_init_table (ST_PFI, ST_PFI); +extern 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); +extern st_table *st_init_table (st_compare_func_type, st_hash_func_type); extern void st_free_table (st_table *); -extern int st_lookup (st_table *, char *, char **); +extern int st_lookup (st_table *, const char *, char **); extern int st_lookup_int (st_table *, char *, int *); -extern int st_insert (st_table *, char *, char *); +extern int st_insert (st_table *, const char *, char *); extern int st_add_direct (st_table *, char *, char *); extern int st_find_or_add (st_table *, char *, char ***); extern int st_find (st_table *, char *, char ***); extern st_table *st_copy (st_table *); -extern int st_delete (st_table *, char **, char **); +extern int st_delete (st_table *, const char **, char **); extern int st_delete_int (st_table *, long *, char **); extern int st_foreach (st_table *, ST_PFSR, char *); -extern int st_strhash (char *, int); -extern int st_numhash (char *, int); -extern int st_ptrhash (char *, int); -extern int st_numcmp (char *, char *); -extern int st_ptrcmp (char *, char *); +extern int st_strhash (const char *, int); +extern int st_numhash (const char *, int); +extern int st_ptrhash (const char *, int); +extern int st_numcmp (const char *, const char *); +extern int st_ptrcmp (const char *, const char *); extern st_generator *st_init_gen (st_table *); -extern int st_gen (st_generator *, char **, char **); -extern int st_gen_int (st_generator *, char **, long *); +extern int st_gen (st_generator *, const char **, char **); +extern int st_gen_int (st_generator *, const char **, long *); extern void st_free_gen (st_generator *); @@ -89,8 +93,10 @@ extern void st_free_gen (st_generator *); #define ST_OUT_OF_MEM -10000 -#ifdef __cplusplus -} -#endif + + +ABC_NAMESPACE_HEADER_END + + #endif /* ST_INCLUDED */ diff --git a/src/misc/st/stmm.c b/src/misc/st/stmm.c index 5aaf8b9d..9aed8b11 100644 --- a/src/misc/st/stmm.c +++ b/src/misc/st/stmm.c @@ -11,6 +11,9 @@ #include "extra.h" #include "stmm.h" +ABC_NAMESPACE_IMPL_START + + #define STMM_NUMCMP(x,y) ((x) != (y)) #define STMM_NUMHASH(x,size) (ABC_ABS((long)x)%(size)) //#define STMM_PTRHASH(x,size) ((int)((ABC_PTRUINT_T)(x)>>2)%size) // 64-bit bug fix 9/17/2007 @@ -25,54 +28,45 @@ (table->hash == stmm_numhash) ? STMM_NUMHASH((key), (table)->num_bins) :\ (*table->hash)((key), (table)->num_bins)) -static int rehash (); -int stmm_numhash (), stmm_ptrhash (), stmm_numcmp (), stmm_ptrcmp (); +static int rehash (stmm_table *table); +//int stmm_numhash (), stmm_ptrhash (), stmm_numcmp (), stmm_ptrcmp (); stmm_table * -stmm_init_table_with_params (compare, hash, size, density, grow_factor, - reorder_flag) - int (*compare) (); - int (*hash) (); - int size; - int density; - double grow_factor; - int reorder_flag; +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 i; - stmm_table *new; + stmm_table *newTable; - new = ABC_ALLOC(stmm_table, 1); - if (new == NULL) { + newTable = ABC_ALLOC(stmm_table, 1); + if (newTable == NULL) { return NULL; } - new->compare = compare; - new->hash = hash; - new->num_entries = 0; - new->max_density = density; - new->grow_factor = grow_factor; - new->reorder_flag = reorder_flag; + newTable->compare = compare; + newTable->hash = hash; + newTable->num_entries = 0; + newTable->max_density = density; + newTable->grow_factor = grow_factor; + newTable->reorder_flag = reorder_flag; if (size <= 0) { size = 1; } - new->num_bins = size; - new->bins = ABC_ALLOC(stmm_table_entry *, size); - if (new->bins == NULL) { - ABC_FREE (new); + newTable->num_bins = size; + newTable->bins = ABC_ALLOC(stmm_table_entry *, size); + if (newTable->bins == NULL) { + ABC_FREE(newTable); return NULL; } for (i = 0; i < size; i++) { - new->bins[i] = 0; + newTable->bins[i] = 0; } // added by alanmi - new->pMemMan = Extra_MmFixedStart(sizeof (stmm_table_entry)); - return new; + newTable->pMemMan = Extra_MmFixedStart(sizeof (stmm_table_entry)); + return newTable; } stmm_table * -stmm_init_table (compare, hash) - int (*compare) (); - int (*hash) (); +stmm_init_table (stmm_compare_func_type compare, stmm_hash_func_type hash) { return stmm_init_table_with_params (compare, hash, STMM_DEFAULT_INIT_TABLE_SIZE, @@ -82,8 +76,7 @@ stmm_init_table (compare, hash) } void -stmm_free_table (table) - stmm_table *table; +stmm_free_table (stmm_table *table) { /* register stmm_table_entry *ptr, *next; @@ -103,14 +96,13 @@ stmm_free_table (table) // added by alanmi if ( table->pMemMan ) Extra_MmFixedStop (table->pMemMan); - ABC_FREE (table->bins); - ABC_FREE (table); + ABC_FREE(table->bins); + ABC_FREE(table); } // this function recycles all the bins void -stmm_clean (table) - stmm_table *table; +stmm_clean (stmm_table *table) { int i; // clean the bins @@ -139,10 +131,7 @@ stmm_clean (table) } int -stmm_lookup (table, key, value) - stmm_table *table; - register char *key; - char **value; +stmm_lookup (stmm_table *table, register char *key, char **value) { int hash_val; register stmm_table_entry *ptr, **last; @@ -164,10 +153,7 @@ stmm_lookup (table, key, value) } int -stmm_lookup_int (table, key, value) - stmm_table *table; - register char *key; - int *value; +stmm_lookup_int (stmm_table *table, register char *key, int *value) { int hash_val; register stmm_table_entry *ptr, **last; @@ -211,13 +197,10 @@ stmm_lookup_int (table, key, value) } int -stmm_insert (table, key, value) - register stmm_table *table; - register char *key; - char *value; +stmm_insert (register stmm_table *table, register char *key, char *value) { int hash_val; - stmm_table_entry *new; + stmm_table_entry *newEntry; register stmm_table_entry *ptr, **last; hash_val = do_hash (key, table); @@ -232,16 +215,16 @@ stmm_insert (table, key, value) hash_val = do_hash (key, table); } -// new = ABC_ALLOC( stmm_table_entry, 1 ); - new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); - if (new == NULL) { +// newEntry = ABC_ALLOC( stmm_table_entry, 1 ); + newEntry = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); + if (newEntry == NULL) { return STMM_OUT_OF_MEM; } - new->key = key; - new->record = value; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = value; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; return 0; } @@ -252,13 +235,10 @@ stmm_insert (table, key, value) } int -stmm_add_direct (table, key, value) - stmm_table *table; - char *key; - char *value; +stmm_add_direct (stmm_table *table, char *key, char *value) { int hash_val; - stmm_table_entry *new; + stmm_table_entry *newEntry; hash_val = do_hash (key, table); if (table->num_entries / table->num_bins >= table->max_density) { @@ -268,28 +248,25 @@ stmm_add_direct (table, key, value) } hash_val = do_hash (key, table); -// new = ABC_ALLOC( stmm_table_entry, 1 ); - new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); - if (new == NULL) { +// newEntry = ABC_ALLOC( stmm_table_entry, 1 ); + newEntry = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); + if (newEntry == NULL) { return STMM_OUT_OF_MEM; } - new->key = key; - new->record = value; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = value; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; return 1; } int -stmm_find_or_add (table, key, slot) - stmm_table *table; - char *key; - char ***slot; +stmm_find_or_add (stmm_table *table, char *key, char ***slot) { int hash_val; - stmm_table_entry *new, *ptr, **last; + stmm_table_entry *newEntry, *ptr, **last; hash_val = do_hash (key, table); @@ -303,19 +280,19 @@ stmm_find_or_add (table, key, slot) hash_val = do_hash (key, table); } - // new = ABC_ALLOC( stmm_table_entry, 1 ); - new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); - if (new == NULL) { + // newEntry = ABC_ALLOC( stmm_table_entry, 1 ); + newEntry = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan); + if (newEntry == NULL) { return STMM_OUT_OF_MEM; } - new->key = key; - new->record = (char *) 0; - new->next = table->bins[hash_val]; - table->bins[hash_val] = new; + newEntry->key = key; + newEntry->record = (char *) 0; + newEntry->next = table->bins[hash_val]; + table->bins[hash_val] = newEntry; table->num_entries++; if (slot != NULL) - *slot = &new->record; + *slot = &newEntry->record; return 0; } else { @@ -326,10 +303,7 @@ stmm_find_or_add (table, key, slot) } int -stmm_find (table, key, slot) - stmm_table *table; - char *key; - char ***slot; +stmm_find (stmm_table *table, char *key, char ***slot) { int hash_val; stmm_table_entry *ptr, **last; @@ -351,8 +325,7 @@ stmm_find (table, key, slot) } static int -rehash (table) - register stmm_table *table; +rehash (register stmm_table *table) { register stmm_table_entry *ptr, *next, **old_bins; int i, old_num_bins, hash_val, old_num_entries; @@ -392,77 +365,73 @@ rehash (table) ptr = next; } } - ABC_FREE (old_bins); + ABC_FREE(old_bins); return 1; } stmm_table * -stmm_copy (old_table) - stmm_table *old_table; +stmm_copy (stmm_table *old_table) { - stmm_table *new_table; - stmm_table_entry *ptr, /* *newptr, *next, */ *new; + stmm_table *newEntry_table; + stmm_table_entry *ptr, /* *newEntryptr, *next, */ *newEntry; int i, /*j, */ num_bins = old_table->num_bins; - new_table = ABC_ALLOC(stmm_table, 1); - if (new_table == NULL) { + newEntry_table = ABC_ALLOC(stmm_table, 1); + if (newEntry_table == NULL) { return NULL; } - *new_table = *old_table; - new_table->bins = ABC_ALLOC(stmm_table_entry *, num_bins); - if (new_table->bins == NULL) { - ABC_FREE (new_table); + *newEntry_table = *old_table; + newEntry_table->bins = ABC_ALLOC(stmm_table_entry *, num_bins); + if (newEntry_table->bins == NULL) { + ABC_FREE(newEntry_table); return NULL; } - // allocate the memory manager for the new table - new_table->pMemMan = + // allocate the memory manager for the newEntry table + newEntry_table->pMemMan = Extra_MmFixedStart (sizeof (stmm_table_entry)); for (i = 0; i < num_bins; i++) { - new_table->bins[i] = NULL; + newEntry_table->bins[i] = NULL; ptr = old_table->bins[i]; while (ptr != NULL) { -// new = ABC_ALLOC( stmm_table_entry, 1 ); - new = - (stmm_table_entry *) Extra_MmFixedEntryFetch (new_table-> +// newEntry = ABC_ALLOC( stmm_table_entry, 1 ); + newEntry = + (stmm_table_entry *) Extra_MmFixedEntryFetch (newEntry_table-> pMemMan); - if (new == NULL) { + if (newEntry == NULL) { /* for ( j = 0; j <= i; j++ ) { - newptr = new_table->bins[j]; - while ( newptr != NULL ) + newEntryptr = newEntry_table->bins[j]; + while ( newEntryptr != NULL ) { - next = newptr->next; - ABC_FREE( newptr ); - newptr = next; + next = newEntryptr->next; + ABC_FREE( newEntryptr ); + newEntryptr = next; } } */ - Extra_MmFixedStop (new_table->pMemMan); + Extra_MmFixedStop (newEntry_table->pMemMan); - ABC_FREE (new_table->bins); - ABC_FREE (new_table); + ABC_FREE(newEntry_table->bins); + ABC_FREE(newEntry_table); return NULL; } - *new = *ptr; - new->next = new_table->bins[i]; - new_table->bins[i] = new; + *newEntry = *ptr; + newEntry->next = newEntry_table->bins[i]; + newEntry_table->bins[i] = newEntry; ptr = ptr->next; } } - return new_table; + return newEntry_table; } int -stmm_delete (table, keyp, value) - register stmm_table *table; - register char **keyp; - char **value; +stmm_delete (register stmm_table *table, register char **keyp, char **value) { int hash_val; char *key = *keyp; @@ -488,10 +457,7 @@ stmm_delete (table, keyp, value) } int -stmm_delete_int (table, keyp, value) - register stmm_table *table; - register long *keyp; - char **value; +stmm_delete_int (register stmm_table *table, register long *keyp, char **value) { int hash_val; char *key = (char *) *keyp; @@ -517,10 +483,7 @@ stmm_delete_int (table, keyp, value) } int -stmm_foreach (table, func, arg) - stmm_table *table; - enum stmm_retval (*func) (); - char *arg; +stmm_foreach (stmm_table *table, enum stmm_retval (*func) (char *, char *, char *), char *arg) { stmm_table_entry *ptr, **last; enum stmm_retval retval; @@ -552,9 +515,7 @@ stmm_foreach (table, func, arg) } int -stmm_strhash (string, modulus) - register char *string; - int modulus; +stmm_strhash (register const char *string, int modulus) { register int val = 0; register int c; @@ -567,40 +528,31 @@ stmm_strhash (string, modulus) } int -stmm_numhash (x, size) - char *x; - int size; +stmm_numhash (const char *x, int size) { return STMM_NUMHASH (x, size); } int -stmm_ptrhash (x, size) - char *x; - int size; +stmm_ptrhash (const char *x, int size) { return STMM_PTRHASH (x, size); } int -stmm_numcmp (x, y) - char *x; - char *y; +stmm_numcmp (const char *x, const char *y) { return STMM_NUMCMP (x, y); } int -stmm_ptrcmp (x, y) - char *x; - char *y; +stmm_ptrcmp (const char *x, const char *y) { return STMM_NUMCMP (x, y); } stmm_generator * -stmm_init_gen (table) - stmm_table *table; +stmm_init_gen (stmm_table *table) { stmm_generator *gen; @@ -616,10 +568,7 @@ stmm_init_gen (table) int -stmm_gen (gen, key_p, value_p) - stmm_generator *gen; - char **key_p; - char **value_p; +stmm_gen (stmm_generator *gen, char **key_p, char **value_p) { register int i; @@ -646,10 +595,7 @@ stmm_gen (gen, key_p, value_p) int -stmm_gen_int (gen, key_p, value_p) - stmm_generator *gen; - char **key_p; - long *value_p; +stmm_gen_int (stmm_generator *gen, char **key_p, long *value_p) { register int i; @@ -677,8 +623,9 @@ stmm_gen_int (gen, key_p, value_p) void -stmm_free_gen (gen) - stmm_generator *gen; +stmm_free_gen (stmm_generator *gen) { - ABC_FREE (gen); + ABC_FREE(gen); } +ABC_NAMESPACE_IMPL_END + diff --git a/src/misc/st/stmm.h b/src/misc/st/stmm.h index 9dede7d8..c23c6942 100644 --- a/src/misc/st/stmm.h +++ b/src/misc/st/stmm.h @@ -14,11 +14,15 @@ #ifndef STMM_INCLUDED #define STMM_INCLUDED + #include "extra.h" -#ifdef __cplusplus -extern "C" { -#endif + + +ABC_NAMESPACE_HEADER_START + +typedef int (*stmm_compare_func_type)(const char*, const char*); +typedef int (*stmm_hash_func_type)(const char*, int); typedef struct stmm_table_entry stmm_table_entry; typedef struct stmm_table stmm_table; @@ -33,8 +37,8 @@ struct stmm_table_entry struct stmm_table { - int (*compare) (); - int (*hash) (); + stmm_compare_func_type compare; + stmm_hash_func_type hash; int num_bins; int num_entries; int max_density; @@ -59,12 +63,11 @@ struct stmm_generator enum stmm_retval { STMM_CONTINUE, STMM_STOP, STMM_DELETE }; -typedef enum stmm_retval (*STMM_PFSR) (); -typedef int (*STMM_PFI) (); +typedef enum stmm_retval (*STMM_PFSR) (char *, char *, char *); EXTERN stmm_table *stmm_init_table_with_params -ARGS ((STMM_PFI, STMM_PFI, int, int, double, int)); -EXTERN stmm_table *stmm_init_table ARGS ((STMM_PFI, STMM_PFI)); +ARGS ((stmm_compare_func_type compare, stmm_hash_func_type hash, int size, int density, double grow_factor, int reorder_flag)); +EXTERN stmm_table *stmm_init_table ARGS ((stmm_compare_func_type, stmm_hash_func_type)); EXTERN void stmm_free_table ARGS ((stmm_table *)); EXTERN int stmm_lookup ARGS ((stmm_table *, char *, char **)); EXTERN int stmm_lookup_int ARGS ((stmm_table *, char *, int *)); @@ -76,11 +79,11 @@ EXTERN stmm_table *stmm_copy ARGS ((stmm_table *)); EXTERN int stmm_delete ARGS ((stmm_table *, char **, char **)); EXTERN int stmm_delete_int ARGS ((stmm_table *, long *, char **)); EXTERN int stmm_foreach ARGS ((stmm_table *, STMM_PFSR, char *)); -EXTERN int stmm_strhash ARGS ((char *, int)); -EXTERN int stmm_numhash ARGS ((char *, int)); -EXTERN int stmm_ptrhash ARGS ((char *, int)); -EXTERN int stmm_numcmp ARGS ((char *, char *)); -EXTERN int stmm_ptrcmp ARGS ((char *, char *)); +EXTERN int stmm_strhash ARGS ((const char *, int)); +EXTERN int stmm_numhash ARGS ((const char *, int)); +EXTERN int stmm_ptrhash ARGS ((const char *, int)); +EXTERN int stmm_numcmp ARGS ((const char *, const char *)); +EXTERN int stmm_ptrcmp ARGS ((const char *, const char *)); EXTERN stmm_generator *stmm_init_gen ARGS ((stmm_table *)); EXTERN int stmm_gen ARGS ((stmm_generator *, char **, char **)); EXTERN int stmm_gen_int ARGS ((stmm_generator *, char **, long *)); @@ -120,8 +123,10 @@ EXTERN void stmm_clean ARGS ((stmm_table *)); */ -#ifdef __cplusplus -} -#endif + + +ABC_NAMESPACE_HEADER_END + + #endif /* STMM_INCLUDED */ -- cgit v1.2.3