nghash cleanup, fix typeof compare_func
This commit is contained in:
parent
7ac266e2e7
commit
abfa90832d
|
|
@ -34,7 +34,7 @@ typedef struct ngtable_rec {
|
||||||
struct nghashbox;
|
struct nghashbox;
|
||||||
|
|
||||||
typedef unsigned int (*nghash_func)(struct nghashbox *, void *) ;
|
typedef unsigned int (*nghash_func)(struct nghashbox *, void *) ;
|
||||||
typedef int (*COMPARE_FUNC)(void *,void *) ;
|
typedef int (*nghash_compare_func)(const void *, const void *) ;
|
||||||
|
|
||||||
struct nghashbox {
|
struct nghashbox {
|
||||||
NGTABLEPTR *hash_table ;
|
NGTABLEPTR *hash_table ;
|
||||||
|
|
@ -42,7 +42,7 @@ struct nghashbox {
|
||||||
NGTABLEPTR last_entry ; /* last entry into hash table */
|
NGTABLEPTR last_entry ; /* last entry into hash table */
|
||||||
NGTABLEPTR enumeratePtr ; /* used to enumerate hash table */
|
NGTABLEPTR enumeratePtr ; /* used to enumerate hash table */
|
||||||
NGTABLEPTR searchPtr ; /* used for find again mechanism */
|
NGTABLEPTR searchPtr ; /* used for find again mechanism */
|
||||||
void *compare_func ; /* the comparison function */
|
nghash_compare_func compare_func ; /* the comparison function */
|
||||||
nghash_func hash_func ; /* the hash function */
|
nghash_func hash_func ; /* the hash function */
|
||||||
double growth_factor ; /* how much to grow table by */
|
double growth_factor ; /* how much to grow table by */
|
||||||
int size ; /* the size of the table */
|
int size ; /* the size of the table */
|
||||||
|
|
@ -97,9 +97,9 @@ we want to intentionally assign it. The compiler is warning unnecessarily.
|
||||||
#define NGHASH_DEF_HASH_NUM ((nghash_func) NGHASH_FUNC_NUM)
|
#define NGHASH_DEF_HASH_NUM ((nghash_func) NGHASH_FUNC_NUM)
|
||||||
|
|
||||||
/* the default comparison functions */
|
/* the default comparison functions */
|
||||||
#define NGHASH_DEF_CMP_STR NGHASH_FUNC_STR
|
#define NGHASH_DEF_CMP_STR ((nghash_compare_func) NGHASH_FUNC_STR)
|
||||||
#define NGHASH_DEF_CMP_PTR (void *) NGHASH_FUNC_PTR
|
#define NGHASH_DEF_CMP_PTR ((nghash_compare_func) NGHASH_FUNC_PTR)
|
||||||
#define NGHASH_DEF_CMP_NUM (void *) NGHASH_FUNC_PTR
|
#define NGHASH_DEF_CMP_NUM ((nghash_compare_func) NGHASH_FUNC_PTR)
|
||||||
|
|
||||||
/* defines for unique flag */
|
/* defines for unique flag */
|
||||||
|
|
||||||
|
|
@ -267,7 +267,7 @@ Function:
|
||||||
is pointer comparison.
|
is pointer comparison.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern NGHASHPTR nghash_init_with_parms( void *comp_func,
|
extern NGHASHPTR nghash_init_with_parms( nghash_compare_func comp_func,
|
||||||
nghash_func hash_func, int numentries, int max_density,
|
nghash_func hash_func, int numentries, int max_density,
|
||||||
double growth, NGHASHFLAGS_T flags ) ;
|
double growth, NGHASHFLAGS_T flags ) ;
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ REVISIONS:
|
||||||
static NGTABLEPTR _nghash_find_item(NGHASHPTR hhtable,void *user_key,void *data) ;
|
static NGTABLEPTR _nghash_find_item(NGHASHPTR hhtable,void *user_key,void *data) ;
|
||||||
|
|
||||||
|
|
||||||
NGHASHPTR nghash_init_with_parms(void *comp_func, nghash_func hash_func, int num,
|
NGHASHPTR nghash_init_with_parms(nghash_compare_func comp_func, nghash_func hash_func, int num,
|
||||||
int max, double growth, NGHASHFLAGS_T flags)
|
int max, double growth, NGHASHFLAGS_T flags)
|
||||||
{
|
{
|
||||||
BOOL unique ; /* entries are to be unique */
|
BOOL unique ; /* entries are to be unique */
|
||||||
|
|
@ -54,7 +54,7 @@ NGHASHPTR nghash_init_with_parms(void *comp_func, nghash_func hash_func, int num
|
||||||
/* prime size */
|
/* prime size */
|
||||||
hashtable->size = nghash_table_size( num ) ;
|
hashtable->size = nghash_table_size( num ) ;
|
||||||
}
|
}
|
||||||
hashtable->compare_func = (void *) comp_func ;
|
hashtable->compare_func = comp_func ;
|
||||||
hashtable->hash_func = hash_func ;
|
hashtable->hash_func = hash_func ;
|
||||||
|
|
||||||
hashtable->hash_table = NGMALLOC( hashtable->size, NGTABLEPTR ) ;
|
hashtable->hash_table = NGMALLOC( hashtable->size, NGTABLEPTR ) ;
|
||||||
|
|
@ -229,7 +229,7 @@ void * _nghash_find(NGHASHPTR hashtable, void * user_key,BOOL *status)
|
||||||
int ret_code ;
|
int ret_code ;
|
||||||
long hfunc ;
|
long hfunc ;
|
||||||
unsigned int hsum ;
|
unsigned int hsum ;
|
||||||
COMPARE_FUNC compare_func ;
|
nghash_compare_func compare_func ;
|
||||||
NGTABLEPTR curPtr ;
|
NGTABLEPTR curPtr ;
|
||||||
NGTABLEPTR *table ;
|
NGTABLEPTR *table ;
|
||||||
|
|
||||||
|
|
@ -259,13 +259,13 @@ void * _nghash_find(NGHASHPTR hashtable, void * user_key,BOOL *status)
|
||||||
if( curPtr ){
|
if( curPtr ){
|
||||||
/* list started at this hash */
|
/* list started at this hash */
|
||||||
for( ; curPtr ; curPtr=curPtr->next ) {
|
for( ; curPtr ; curPtr=curPtr->next ) {
|
||||||
if( hashtable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( hashtable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( hashtable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( hashtable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
hashtable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
hashtable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) hashtable->compare_func ;
|
compare_func = hashtable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
@ -304,20 +304,20 @@ void * _nghash_find_again(NGHASHPTR hashtable, void * user_key,BOOL *status)
|
||||||
{
|
{
|
||||||
int ret_code ; /* comparison return code */
|
int ret_code ; /* comparison return code */
|
||||||
NGTABLEPTR curPtr ; /* current hashtable entry */
|
NGTABLEPTR curPtr ; /* current hashtable entry */
|
||||||
COMPARE_FUNC compare_func ; /* user defined comparison function */
|
nghash_compare_func compare_func ; /* user defined comparison function */
|
||||||
|
|
||||||
/* initialization */
|
/* initialization */
|
||||||
DS(hashtable->access++;) ;
|
DS(hashtable->access++;) ;
|
||||||
|
|
||||||
if( hashtable->searchPtr ){
|
if( hashtable->searchPtr ){
|
||||||
for(curPtr=hashtable->searchPtr->next; curPtr ; curPtr=curPtr->next ) {
|
for(curPtr=hashtable->searchPtr->next; curPtr ; curPtr=curPtr->next ) {
|
||||||
if( hashtable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( hashtable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( hashtable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( hashtable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
hashtable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
hashtable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) hashtable->compare_func ;
|
compare_func = hashtable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
@ -347,7 +347,7 @@ void * nghash_delete(NGHASHPTR hashtable, void * user_key)
|
||||||
long hfunc ;
|
long hfunc ;
|
||||||
unsigned int hsum ;
|
unsigned int hsum ;
|
||||||
void * user_data_p ;
|
void * user_data_p ;
|
||||||
COMPARE_FUNC compare_func ;
|
nghash_compare_func compare_func ;
|
||||||
NGTABLEPTR curPtr, *prevPtr ;
|
NGTABLEPTR curPtr, *prevPtr ;
|
||||||
NGTABLEPTR *table ;
|
NGTABLEPTR *table ;
|
||||||
|
|
||||||
|
|
@ -379,13 +379,13 @@ void * nghash_delete(NGHASHPTR hashtable, void * user_key)
|
||||||
/* list started at this hash */
|
/* list started at this hash */
|
||||||
prevPtr = table + hsum ;
|
prevPtr = table + hsum ;
|
||||||
for( ; curPtr ; prevPtr = &(curPtr->next), curPtr=curPtr->next ) {
|
for( ; curPtr ; prevPtr = &(curPtr->next), curPtr=curPtr->next ) {
|
||||||
if( hashtable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( hashtable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( hashtable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( hashtable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
hashtable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
hashtable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) hashtable->compare_func ;
|
compare_func = hashtable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
@ -420,7 +420,7 @@ void * nghash_insert(NGHASHPTR hashtable, void * user_key, void * data)
|
||||||
int ret_code ;
|
int ret_code ;
|
||||||
long hfunc ;
|
long hfunc ;
|
||||||
unsigned int hsum ;
|
unsigned int hsum ;
|
||||||
COMPARE_FUNC compare_func ;
|
nghash_compare_func compare_func ;
|
||||||
NGTABLEPTR curPtr, temptr, curTable ;
|
NGTABLEPTR curPtr, temptr, curTable ;
|
||||||
NGTABLEPTR *table ;
|
NGTABLEPTR *table ;
|
||||||
|
|
||||||
|
|
@ -452,13 +452,13 @@ void * nghash_insert(NGHASHPTR hashtable, void * user_key, void * data)
|
||||||
/* list started at this hash */
|
/* list started at this hash */
|
||||||
for( curPtr = temptr ; curPtr ; curPtr=curPtr->next ) {
|
for( curPtr = temptr ; curPtr ; curPtr=curPtr->next ) {
|
||||||
DS(hashtable->collision++;) ;
|
DS(hashtable->collision++;) ;
|
||||||
if( hashtable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( hashtable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( hashtable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( hashtable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
hashtable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
hashtable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key);
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key);
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) hashtable->compare_func ;
|
compare_func = hashtable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
@ -513,7 +513,7 @@ static NGTABLEPTR _nghash_find_item(NGHASHPTR htable,void * user_key,void * data
|
||||||
int ret_code ;
|
int ret_code ;
|
||||||
long hfunc ;
|
long hfunc ;
|
||||||
unsigned int hsum ;
|
unsigned int hsum ;
|
||||||
COMPARE_FUNC compare_func ;
|
nghash_compare_func compare_func ;
|
||||||
NGTABLEPTR curPtr, temptr ;
|
NGTABLEPTR curPtr, temptr ;
|
||||||
NGTABLEPTR *table ;
|
NGTABLEPTR *table ;
|
||||||
|
|
||||||
|
|
@ -542,13 +542,13 @@ static NGTABLEPTR _nghash_find_item(NGHASHPTR htable,void * user_key,void * data
|
||||||
if( (temptr = table[hsum]) != NULL ){
|
if( (temptr = table[hsum]) != NULL ){
|
||||||
/* list started at this hash */
|
/* list started at this hash */
|
||||||
for(curPtr=temptr ; curPtr ; curPtr=curPtr->next ) {
|
for(curPtr=temptr ; curPtr ; curPtr=curPtr->next ) {
|
||||||
if( htable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( htable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( htable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( htable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
htable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
htable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key);
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key);
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) htable->compare_func ;
|
compare_func = htable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
@ -750,7 +750,7 @@ BOOL nghash_deleteItem(NGHASHPTR hashtable, void * user_key, void * data)
|
||||||
int ret_code ;
|
int ret_code ;
|
||||||
long hfunc ;
|
long hfunc ;
|
||||||
unsigned long hsum ;
|
unsigned long hsum ;
|
||||||
COMPARE_FUNC compare_func ;
|
nghash_compare_func compare_func ;
|
||||||
NGTABLEPTR curPtr, temptr, *prevPtr ;
|
NGTABLEPTR curPtr, temptr, *prevPtr ;
|
||||||
NGTABLEPTR *table ;
|
NGTABLEPTR *table ;
|
||||||
|
|
||||||
|
|
@ -784,13 +784,13 @@ BOOL nghash_deleteItem(NGHASHPTR hashtable, void * user_key, void * data)
|
||||||
/* -----------------------------------------------------------------
|
/* -----------------------------------------------------------------
|
||||||
* Look for match.
|
* Look for match.
|
||||||
----------------------------------------------------------------- */
|
----------------------------------------------------------------- */
|
||||||
if( hashtable->compare_func == (void *) NGHASH_DEF_CMP_STR ) {
|
if( hashtable->compare_func == NGHASH_DEF_CMP_STR ) {
|
||||||
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
ret_code = strcmp((char *)curPtr->key, (char *) user_key ) ;
|
||||||
} else if ( hashtable->compare_func == (void *) NGHASH_DEF_CMP_PTR||
|
} else if ( hashtable->compare_func == NGHASH_DEF_CMP_PTR ||
|
||||||
hashtable->compare_func == (void *) NGHASH_DEF_CMP_NUM ){
|
hashtable->compare_func == NGHASH_DEF_CMP_NUM ) {
|
||||||
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
ret_code = NGHASH_PTR_COMPARE_FUNC( curPtr->key, user_key );
|
||||||
} else {
|
} else {
|
||||||
compare_func = (COMPARE_FUNC) hashtable->compare_func ;
|
compare_func = hashtable->compare_func ;
|
||||||
ret_code = compare_func (curPtr->key, user_key);
|
ret_code = compare_func (curPtr->key, user_key);
|
||||||
}
|
}
|
||||||
if( ret_code == STRINGEQ ){
|
if( ret_code == STRINGEQ ){
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue