text
stringlengths
0
357
return sjhashStrNICmp((const char*)pKey1,(const char*)pKey2,n1);
}
/* Hash and comparison functions when the mode is SJHASH_BINARY
*/
static int binHash(const void *pKey, int nKey)
{
int h = 0;
const char *z = (const char *)pKey;
while (nKey-- > 0)
{
h = (h<<3) ^ h ^ *(z++);
}
return h & 0x7fffffff;
}
static int binCompare(const void *pKey1, int n1, const void *pKey2, int n2)
{
if (n1!=n2) return 1;
return memcmp(pKey1,pKey2,n1);
}
/* Return a pointer to the appropriate hash function given the key class.
*
* About the syntax:
* The name of the function is "hashFunction". The function takes a
* single parameter "keyClass". The return value of hashFunction()
* is a pointer to another function. Specifically, the return value
* of hashFunction() is a pointer to a function that takes two parameters
* with types "const void*" and "int" and returns an "int".
*/
static int (*hashFunction(int keyClass))(const void*,int)
{
switch (keyClass)
{
case DC_HASH_INT: return &intHash;
case DC_HASH_POINTER:return &ptrHash;
case DC_HASH_STRING: return &strHash;
case DC_HASH_BINARY: return &binHash;;
default: break;
}
return 0;
}
/* Return a pointer to the appropriate hash function given the key class.
*/
static int (*compareFunction(int keyClass))(const void*,int,const void*,int)
{
switch (keyClass)
{
case DC_HASH_INT: return &intCompare;
case DC_HASH_POINTER: return &ptrCompare;
case DC_HASH_STRING: return &strCompare;
case DC_HASH_BINARY: return &binCompare;
default: break;
}
return 0;
}
/* Link an element into the hash table
*/
static void insertElement(dc_hash_t *pH, /* The complete hash table */
struct _ht *pEntry, /* The entry into which pNew is inserted */
dc_hashelem_t *pNew) /* The element to be inserted */
{
dc_hashelem_t *pHead; /* First element already in pEntry */
pHead = pEntry->chain;
if (pHead)
{
pNew->next = pHead;
pNew->prev = pHead->prev;
if (pHead->prev) { pHead->prev->next = pNew; }
else { pH->first = pNew; }
pHead->prev = pNew;
}
else
{
pNew->next = pH->first;
if (pH->first) { pH->first->prev = pNew; }
pNew->prev = 0;
pH->first = pNew;
}
pEntry->count++;
pEntry->chain = pNew;
}
/* Resize the hash table so that it cantains "new_size" buckets.
* "new_size" must be a power of 2. The hash table might fail
* to resize if sjhashMalloc() fails.
*/