Bugzilla bug #32184: added 'const' versions of hash table lookup

functions that don't reorder the hash entries.
Modified files: plhash.h, plhash.c
This commit is contained in:
wtc%netscape.com 2000-03-24 23:13:45 +00:00
Родитель 92abe5891c
Коммит 7bd983c4ca
2 изменённых файлов: 52 добавлений и 0 удалений

Просмотреть файл

@ -195,6 +195,34 @@ PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key)
return hep;
}
/*
** Same as PL_HashTableRawLookup but doesn't reorder the hash entries.
*/
PR_IMPLEMENT(PLHashEntry *const *)
PL_HashTableRawLookupConst(const PLHashTable *ht, PLHashNumber keyHash,
const void *key)
{
PLHashEntry *he, *const *hep;
PLHashNumber h;
#ifdef HASHMETER
ht->nlookups++;
#endif
h = keyHash * GOLDEN_RATIO;
h >>= ht->shift;
hep = &ht->buckets[h];
while ((he = *hep) != 0) {
if (he->keyHash == keyHash && (*ht->keyCompare)(key, he->key)) {
break;
}
hep = &he->next;
#ifdef HASHMETER
ht->nsteps++;
#endif
}
return hep;
}
PR_IMPLEMENT(PLHashEntry *)
PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
PLHashNumber keyHash, const void *key, void *value)
@ -348,6 +376,23 @@ PL_HashTableLookup(PLHashTable *ht, const void *key)
return 0;
}
/*
** Same as PL_HashTableLookup but doesn't reorder the hash entries.
*/
PR_IMPLEMENT(void *)
PL_HashTableLookupConst(const PLHashTable *ht, const void *key)
{
PLHashNumber keyHash;
PLHashEntry *he, *const *hep;
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookupConst(ht, keyHash, key);
if ((he = *hep) != 0) {
return he->value;
}
return 0;
}
/*
** Iterate over the entries in the hash table calling func for each
** entry found. Stop if "f" says to (return value & PR_ENUMERATE_STOP).

Просмотреть файл

@ -104,6 +104,9 @@ PL_HashTableRemove(PLHashTable *ht, const void *key);
PR_EXTERN(void *)
PL_HashTableLookup(PLHashTable *ht, const void *key);
PR_EXTERN(void *)
PL_HashTableLookupConst(const PLHashTable *ht, const void *key);
PR_EXTERN(PRIntn)
PL_HashTableEnumerateEntries(PLHashTable *ht, PLHashEnumerator f, void *arg);
@ -123,6 +126,10 @@ PL_CompareValues(const void *v1, const void *v2);
PR_EXTERN(PLHashEntry **)
PL_HashTableRawLookup(PLHashTable *ht, PLHashNumber keyHash, const void *key);
PR_EXTERN(PLHashEntry *const *)
PL_HashTableRawLookupConst(const PLHashTable *ht, PLHashNumber keyHash,
const void *key);
PR_EXTERN(PLHashEntry *)
PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep, PLHashNumber keyHash,
const void *key, void *value);