1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-25 17:29:50 +00:00

Added routines to remove an entry from the hash table.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5048 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-06-11 18:17:54 +00:00
parent ce0d51d55a
commit 279ad05150
2 changed files with 58 additions and 8 deletions

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -34,6 +34,7 @@
/* common */
#include "check.h"
#include "hashtab.h"
#include "xmalloc.h"
@ -164,6 +165,34 @@ void HT_Insert (HashTable* T, HashNode* N)
void HT_Remove (HashNode* N)
/* Remove a node from a hash table. */
{
/* Get the table from the node */
HashTable* T = N->Owner;
/* Calculate the reduced hash, which is also the slot number */
unsigned Slot = N->Hash % T->Slots;
/* Remove the entry from the single linked list */
HashNode** Q = &T->Table[Slot];
while (1) {
/* If the pointer is NULL, the node is not in the table which we will
* consider a serious error.
*/
CHECK (*Q != 0);
if (*Q == N) {
/* Found - remove it */
*Q = N->Next;
break;
}
/* Next node */
Q = &(*Q)->Next;
}
}
void HT_InsertEntry (HashTable* T, void* Entry)
/* Insert an entry into the given hash table */
{
@ -172,6 +201,21 @@ void HT_InsertEntry (HashTable* T, void* Entry)
void HT_RemoveEntry (HashTable* T, void* Entry)
/* Remove an entry from the given hash table */
{
/* Get the node from the entry */
HashNode* N = T->Func->GetHashNode (Entry);
/* Make sure the entry is actually in the given table */
CHECK (N->Owner == T);
/* Remove the node */
HT_Remove (N);
}
void HT_Walk (HashTable* T, void (*F) (void* Entry, void* Data), void* Data)
/* Walk over all nodes of a hash table. For each node, the user supplied
* function F is called, passing a pointer to the entry, and the data pointer

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 2003-2008 Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* (C) 2003-2011, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -196,9 +196,15 @@ void* HT_FindEntry (const HashTable* T, const void* Key);
void HT_Insert (HashTable* T, HashNode* N);
/* Insert a node into the given hash table */
void HT_Remove (HashNode* N);
/* Remove a node from its hash table */
void HT_InsertEntry (HashTable* T, void* Entry);
/* Insert an entry into the given hash table */
void HT_RemoveEntry (HashTable* T, void* Entry);
/* Remove an entry from the given hash table */
void HT_Walk (HashTable* T, void (*F) (void* Entry, void* Data), void* Data);
/* Walk over all nodes of a hash table. For each node, the user supplied
* function F is called, passing a pointer to the entry, and the data pointer