From 96ce71ad5f67892da908192279b0cfbda59c227b Mon Sep 17 00:00:00 2001 From: uz Date: Sun, 21 Aug 2011 13:31:30 +0000 Subject: [PATCH] Removed the functions that work on HashNodes since they are mostly useless now. git-svn-id: svn://svn.cc65.org/cc65/trunk@5243 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/common/hashtab.c | 57 ++++++++++++-------------------------------- src/common/hashtab.h | 17 ++++--------- 2 files changed, 19 insertions(+), 55 deletions(-) diff --git a/src/common/hashtab.c b/src/common/hashtab.c index e57cf727b..965ee867c 100644 --- a/src/common/hashtab.c +++ b/src/common/hashtab.c @@ -101,20 +101,6 @@ static void HT_Alloc (HashTable* T) -HashNode* HT_Find (const HashTable* T, const void* Key) -/* Find the node with the given index */ -{ - /* If we don't have a table, there's nothing to find */ - if (T->Table == 0) { - return 0; - } - - /* Search for the entry */ - return HT_FindHash (T, Key, T->Func->GenHash (Key)); -} - - - 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. @@ -150,18 +136,19 @@ HashNode* HT_FindHash (const HashTable* T, const void* Key, unsigned Hash) -void* HT_FindEntry (const HashTable* T, const void* Key) -/* Find the node with the given index and return the corresponding entry */ +void* HT_Find (const HashTable* T, const void* Key) +/* Find the entry with the given key and return it */ { - /* Since the HashEntry must be first member, we can use HT_Find here */ - return HT_Find (T, Key); + /* Search for the entry */ + return HT_FindHash (T, Key, T->Func->GenHash (Key)); } -void HT_Insert (HashTable* T, HashNode* N) -/* Insert a node into the given hash table */ +void HT_Insert (HashTable* T, void* Entry) +/* Insert an entry into the given hash table */ { + HashNode* N; unsigned RHash; /* If we don't have a table, we need to allocate it now */ @@ -169,6 +156,9 @@ void HT_Insert (HashTable* T, HashNode* N) HT_Alloc (T); } + /* The first member of Entry is also the hash node */ + N = Entry; + /* Generate the hash over the node key. */ N->Hash = T->Func->GenHash (T->Func->GetKey (N)); @@ -185,9 +175,12 @@ void HT_Insert (HashTable* T, HashNode* N) -void HT_Remove (HashTable* T, HashNode* N) -/* Remove a node from a hash table. */ +void HT_Remove (HashTable* T, void* Entry) +/* Remove an entry from the given hash table */ { + /* The first member of Entry is also the hash node */ + HashNode* N = Entry; + /* Calculate the reduced hash, which is also the slot number */ unsigned Slot = N->Hash % T->Slots; @@ -210,26 +203,6 @@ void HT_Remove (HashTable* T, HashNode* N) -void HT_InsertEntry (HashTable* T, void* Entry) -/* Insert an entry into the given hash table */ -{ - /* Since the hash node must be first member, Entry is also the pointer to - * the hash node. - */ - HT_Insert (T, Entry); -} - - - -void HT_RemoveEntry (HashTable* T, void* Entry) -/* Remove an entry from the given hash table */ -{ - /* The entry is the first member, so we can just convert the pointer */ - HT_Remove (T, Entry); -} - - - void HT_Walk (HashTable* T, int (*F) (void* Entry, void* Data), void* Data) /* Walk over all nodes of a hash table, optionally deleting entries from the * table. For each node, the user supplied function F is called, passing a diff --git a/src/common/hashtab.h b/src/common/hashtab.h index 0ebc069b4..f4a4ba3cb 100644 --- a/src/common/hashtab.h +++ b/src/common/hashtab.h @@ -139,27 +139,18 @@ 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! */ -HashNode* HT_Find (const HashTable* T, const void* Key); -/* Find the node with the given key*/ - 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. */ -void* HT_FindEntry (const HashTable* T, const void* Key); -/* Find the node with the given key and return the corresponding entry */ - -void HT_Insert (HashTable* T, HashNode* N); -/* Insert a node into the given hash table */ - -void HT_Remove (HashTable* T, HashNode* N); -/* Remove a node from its hash table */ +void* HT_Find (const HashTable* T, const void* Key); +/* Find the entry with the given key and return it */ -void HT_InsertEntry (HashTable* T, void* Entry); +void HT_Insert (HashTable* T, void* Entry); /* Insert an entry into the given hash table */ -void HT_RemoveEntry (HashTable* T, void* Entry); +void HT_Remove (HashTable* T, void* Entry); /* Remove an entry from the given hash table */ void HT_Walk (HashTable* T, int (*F) (void* Entry, void* Data), void* Data); -- 2.39.5