diff --git a/src/common/hashtab.c b/src/common/hashtab.c index 965ee867c..376e26a28 100644 --- a/src/common/hashtab.c +++ b/src/common/hashtab.c @@ -194,6 +194,7 @@ void HT_Remove (HashTable* T, void* Entry) if (*Q == N) { /* Found - remove it */ *Q = N->Next; + --T->Count; break; } /* Next node */ @@ -235,6 +236,7 @@ void HT_Walk (HashTable* T, int (*F) (void* Entry, void* Data), void* Data) if (F (*Cur, Data)) { /* Delete the node from the chain */ *Cur = Next; + --T->Count; } else { /* Next node in chain */ Cur = &(*Cur)->Next; diff --git a/src/common/hashtab.h b/src/common/hashtab.h index f4a4ba3cb..0543ac087 100644 --- a/src/common/hashtab.h +++ b/src/common/hashtab.h @@ -139,6 +139,16 @@ INLINE HashTable* NewHashTable (unsigned Slots, const HashFunctions* Func) void FreeHashTable (HashTable* T); /* Free a hash table. Note: This will not free the entries in the table! */ +#if defined(HAVE_INLINE) +INLINE unsigned HT_GetCount (const HashTable* T) +/* Return the number of items in the table. */ +{ + return T->Count; +} +#else +#define HT_GetCount(T) ((T)->Count) +#endif + HashNode* HT_FindHash (const HashTable* T, const void* Key, unsigned Hash); /* Find the node with the given key. Differs from HT_Find in that the hash * for the key is precalculated and passed to the function.