text stringlengths 0 357 |
|---|
static void rehash(dc_hash_t *pH, int new_size) |
{ |
struct _ht *new_ht; /* The new hash table */ |
dc_hashelem_t *elem, *next_elem; /* For looping over existing elements */ |
int (*xHash)(const void*,int); /* The hash function */ |
assert( (new_size & (new_size-1))==0); |
new_ht = (struct _ht *)sjhashMalloc( new_size*sizeof(struct _ht)); |
if (new_ht==0) return; |
if (pH->ht) sjhashFree(pH->ht); |
pH->ht = new_ht; |
pH->htsize = new_size; |
xHash = hashFunction(pH->keyClass); |
for(elem=pH->first, pH->first=0; elem; elem = next_elem) |
{ |
int h = (*xHash)(elem->pKey, elem->nKey) & (new_size-1); |
next_elem = elem->next; |
insertElement(pH, &new_ht[h], elem); |
} |
} |
/* This function (for internal use only) locates an element in an |
* hash table that matches the given key. The hash for this key has |
* already been computed and is passed as the 4th parameter. |
*/ |
static dc_hashelem_t *findElementGivenHash(const dc_hash_t *pH, /* The pH to be searched */ |
const void *pKey, /* The key we are searching for */ |
int nKey, |
int h) /* The hash for this key. */ |
{ |
dc_hashelem_t *elem; /* Used to loop thru the element list */ |
int count; /* Number of elements left to test */ |
int (*xCompare)(const void*,int,const void*,int); /* comparison function */ |
if (pH->ht) |
{ |
struct _ht *pEntry = &pH->ht[h]; |
elem = pEntry->chain; |
count = pEntry->count; |
xCompare = compareFunction(pH->keyClass); |
while (count-- && elem) |
{ |
if ((*xCompare)(elem->pKey,elem->nKey,pKey,nKey)==0) |
{ |
return elem; |
} |
elem = elem->next; |
} |
} |
return 0; |
} |
/* Remove a single entry from the hash table given a pointer to that |
* element and a hash on the element's key. |
*/ |
static void removeElementGivenHash(dc_hash_t *pH, /* The pH containing "elem" */ |
dc_hashelem_t* elem, /* The element to be removed from the pH */ |
int h) /* Hash value for the element */ |
{ |
struct _ht *pEntry; |
if (elem->prev) |
{ |
elem->prev->next = elem->next; |
} |
else |
{ |
pH->first = elem->next; |
} |
if (elem->next) |
{ |
elem->next->prev = elem->prev; |
} |
pEntry = &pH->ht[h]; |
if (pEntry->chain==elem) |
{ |
pEntry->chain = elem->next; |
} |
pEntry->count--; |
if (pEntry->count<=0) |
{ |
pEntry->chain = 0; |
} |
if (pH->copyKey && elem->pKey) |
{ |
sjhashFree(elem->pKey); |
} |
sjhashFree( elem); |
pH->count--; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.