text stringlengths 0 357 |
|---|
* |
* "pNew" is a pointer to the hash table that is to be initialized. |
* keyClass is one of the constants SJHASH_INT, SJHASH_POINTER, |
* SJHASH_BINARY, or SJHASH_STRING. The value of keyClass |
* determines what kind of key the hash table will use. "copyKey" is |
* true if the hash table should make its own private copy of keys and |
* false if it should just use the supplied pointer. CopyKey only makes |
* sense for SJHASH_STRING and SJHASH_BINARY and is ignored |
* for other key classes. |
*/ |
void dc_hash_init(dc_hash_t *pNew, int keyClass, int copyKey) |
{ |
assert( pNew!=0); |
assert( keyClass>=DC_HASH_INT && keyClass<=DC_HASH_BINARY); |
pNew->keyClass = keyClass; |
if (keyClass==DC_HASH_POINTER || keyClass==DC_HASH_INT) copyKey = 0; |
pNew->copyKey = copyKey; |
pNew->first = 0; |
pNew->count = 0; |
pNew->htsize = 0; |
pNew->ht = 0; |
} |
/* Remove all entries from a hash table. Reclaim all memory. |
* Call this routine to delete a hash table or to reset a hash table |
* to the empty state. |
*/ |
void dc_hash_clear(dc_hash_t *pH) |
{ |
dc_hashelem_t *elem; /* For looping over all elements of the table */ |
if (pH == NULL) { |
return; |
} |
elem = pH->first; |
pH->first = 0; |
if (pH->ht) sjhashFree(pH->ht); |
pH->ht = 0; |
pH->htsize = 0; |
while (elem) |
{ |
dc_hashelem_t *next_elem = elem->next; |
if (pH->copyKey && elem->pKey) |
{ |
sjhashFree(elem->pKey); |
} |
sjhashFree(elem); |
elem = next_elem; |
} |
pH->count = 0; |
} |
/* Hash and comparison functions when the mode is SJHASH_INT |
*/ |
static int intHash(const void *pKey, int nKey) |
{ |
return nKey ^ (nKey<<8) ^ (nKey>>8); |
} |
static int intCompare(const void *pKey1, int n1, const void *pKey2, int n2) |
{ |
return n2 - n1; |
} |
/* Hash and comparison functions when the mode is SJHASH_POINTER |
*/ |
static int ptrHash(const void *pKey, int nKey) |
{ |
uintptr_t x = Addr(pKey); |
return x ^ (x<<8) ^ (x>>8); |
} |
static int ptrCompare(const void *pKey1, int n1, const void *pKey2, int n2) |
{ |
if (pKey1==pKey2) return 0; |
if (pKey1<pKey2) return -1; |
return 1; |
} |
/* Hash and comparison functions when the mode is SJHASH_STRING |
*/ |
static int strHash(const void *pKey, int nKey) |
{ |
return sjhashNoCase((const char*)pKey, nKey); |
} |
static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2) |
{ |
if (n1!=n2) return 1; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.