From d0d550be660a40893f6c86d737d813c8dddef151 Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 21 Aug 2011 16:56:40 +0000 Subject: [PATCH] Fix errors in tracking the number of items in the table. Added function HT_GetCount to retrieve the number of items. git-svn-id: svn://svn.cc65.org/cc65/trunk@5248 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/hashtab.c | 2 ++ src/common/hashtab.h | 10 ++++++++++ 2 files changed, 12 insertions(+) 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. -- 2.39.5