21#ifndef ABC__misc__hash__hashGen_h
22#define ABC__misc__hash__hashGen_h
72#define Hash_GenForEachEntry( pHash, pEntry, bin ) \
73 for(bin=-1, pEntry=NULL; bin < pHash->nBins; (!pEntry)?(pEntry=pHash->pArray[++bin]):(pEntry=pEntry->pNext)) \
91static int Hash_DefaultHashFuncStr(
void *
key,
int nBins )
93 const char*
p = (
const char*)
key;
99 return (
unsigned)h % nBins;
102static int Hash_DefaultCmpFuncStr(
void * key1,
void * key2 )
104 return strcmp((
const char*)key1, (
const char*) key2);
118static int Hash_DefaultHashFuncInt(
void *
key,
int nBins )
120 return (
long)
key % nBins;
134static int Hash_DefaultCmpFuncInt(
void * key1,
void* key2 )
136 return (
long)key1 - (long)key2;
152 int (*Hash_FuncHash)(
void *,
int),
153 int (*Hash_FuncComp)(
void *,
void *),
160 p->fHash = Hash_FuncHash? Hash_FuncHash : (int (*)(
void *, int))Hash_DefaultHashFuncStr;
161 p->fComp = Hash_FuncComp? Hash_FuncComp : (int (*)(
void *,
void *))Hash_DefaultCmpFuncStr;
162 p->fFreeKey = fFreeKey;
185 bin = (*(
p->fHash))(
key,
p->nBins);
188 pEntry =
p->pArray[bin];
190 if ( !
p->fComp(pEntry->
key,
key) ) {
193 pEntry = pEntry->
pNext;
210static inline void Hash_GenWriteEntry(
Hash_Gen_t *
p,
void *
key,
void * data )
216 bin = (*(
p->fHash))(
key,
p->nBins);
219 pLast = &(
p->pArray[bin]);
220 pEntry =
p->pArray[bin];
222 if ( !
p->fComp(pEntry->
key,
key) ) {
226 pLast = &(pEntry->
pNext);
227 pEntry = pEntry->
pNext;
234 pEntry->
pNext = NULL;
235 pEntry->
key = (
char *)
key;
259 bin = (*(
p->fHash))(
key,
p->nBins);
262 pLast = &(
p->pArray[bin]);
263 pEntry =
p->pArray[bin];
265 if ( !
p->fComp(pEntry->
key,
key) )
267 pLast = &(pEntry->
pNext);
268 pEntry = pEntry->
pNext;
276 pEntry->
pNext = NULL;
277 pEntry->
key = (
char *)
key;
303 bin = (*(
p->fHash))(
key,
p->nBins);
306 pLast = &(
p->pArray[bin]);
307 pEntry =
p->pArray[bin];
309 if ( !
p->fComp(pEntry->
key,
key) ) {
312 *pLast = pEntry->
pNext;
318 pLast = &(pEntry->
pNext);
319 pEntry = pEntry->
pNext;
343 for(bin = 0; bin <
p->nBins; bin++) {
344 pEntry =
p->pArray[bin];
349 pEntry = pEntry->
pNext;
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
int(* Hash_GenCompFunction_t)(void *key, void *data)
int(* Hash_GenHashFunction_t)(void *key, int nBins)
typedefABC_NAMESPACE_HEADER_START struct Hash_Gen_t_ Hash_Gen_t
INCLUDES ///.
struct Hash_Gen_Entry_t_ Hash_Gen_Entry_t
struct Hash_Gen_Entry_t_ * pNext
Hash_GenHashFunction_t fHash
Hash_Gen_Entry_t ** pArray
Hash_GenCompFunction_t fComp