mirror of
https://github.com/cc65/cc65.git
synced 2025-01-13 09:31:53 +00:00
Do also remove the Owner pointer from the HashNode making it ~50% of its
original size. git-svn-id: svn://svn.cc65.org/cc65/trunk@5159 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
f571ec44ae
commit
6b79f5bbb1
@ -46,6 +46,32 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
HashTable* InitHashTable (HashTable* T, unsigned Slots, const HashFunctions* Func)
|
||||||
|
/* Initialize a hash table and return it */
|
||||||
|
{
|
||||||
|
/* Initialize the fields */
|
||||||
|
T->Slots = Slots;
|
||||||
|
T->Count = 0;
|
||||||
|
T->Table = 0;
|
||||||
|
T->Func = Func;
|
||||||
|
|
||||||
|
/* Return the initialized table */
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void DoneHashTable (HashTable* T)
|
||||||
|
/* Destroy the contents of a hash table. Note: This will not free the entries
|
||||||
|
* in the table!
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Just free the array with the table pointers */
|
||||||
|
xfree (T->Table);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FreeHashTable (HashTable* T)
|
void FreeHashTable (HashTable* T)
|
||||||
/* Free a hash table. Note: This will not free the entries in the table! */
|
/* Free a hash table. Note: This will not free the entries in the table! */
|
||||||
{
|
{
|
||||||
@ -153,21 +179,15 @@ void HT_Insert (HashTable* T, HashNode* N)
|
|||||||
N->Next = T->Table[RHash];
|
N->Next = T->Table[RHash];
|
||||||
T->Table[RHash] = N;
|
T->Table[RHash] = N;
|
||||||
|
|
||||||
/* Set the owner */
|
|
||||||
N->Owner = T;
|
|
||||||
|
|
||||||
/* One more entry */
|
/* One more entry */
|
||||||
++T->Count;
|
++T->Count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void HT_Remove (HashNode* N)
|
void HT_Remove (HashTable* T, HashNode* N)
|
||||||
/* Remove a node from a hash table. */
|
/* 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 */
|
/* Calculate the reduced hash, which is also the slot number */
|
||||||
unsigned Slot = N->Hash % T->Slots;
|
unsigned Slot = N->Hash % T->Slots;
|
||||||
|
|
||||||
@ -205,13 +225,7 @@ void HT_RemoveEntry (HashTable* T, void* Entry)
|
|||||||
/* Remove an entry from the given hash table */
|
/* Remove an entry from the given hash table */
|
||||||
{
|
{
|
||||||
/* The entry is the first member, so we can just convert the pointer */
|
/* The entry is the first member, so we can just convert the pointer */
|
||||||
HashNode* N = Entry;
|
HT_Remove (T, Entry);
|
||||||
|
|
||||||
/* Make sure the entry is actually in the given table */
|
|
||||||
CHECK (N->Owner == T);
|
|
||||||
|
|
||||||
/* Remove the node */
|
|
||||||
HT_Remove (N);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,6 @@
|
|||||||
typedef struct HashNode HashNode;
|
typedef struct HashNode HashNode;
|
||||||
struct HashNode {
|
struct HashNode {
|
||||||
HashNode* Next; /* Next entry in hash list */
|
HashNode* Next; /* Next entry in hash list */
|
||||||
struct HashTable* Owner; /* Owner table */
|
|
||||||
unsigned Hash; /* The full hash value */
|
unsigned Hash; /* The full hash value */
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,12 +104,9 @@ INLINE void InitHashNode (HashNode* N)
|
|||||||
/* Initialize a hash node. */
|
/* Initialize a hash node. */
|
||||||
{
|
{
|
||||||
N->Next = 0;
|
N->Next = 0;
|
||||||
N->Owner = 0;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define InitHashNode(N) \
|
#define InitHashNode(N) do { (N)->Next = 0; } while (0)
|
||||||
(N)->Next = 0, \
|
|
||||||
(N)->Owner = 0
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -121,40 +117,13 @@ INLINE void InitHashNode (HashNode* N)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
HashTable* InitHashTable (HashTable* T, unsigned Slots, const HashFunctions* Func);
|
||||||
INLINE HashTable* InitHashTable (HashTable* T, unsigned Slots, const HashFunctions* Func)
|
|
||||||
/* Initialize a hash table and return it */
|
/* Initialize a hash table and return it */
|
||||||
{
|
|
||||||
/* Initialize the fields */
|
|
||||||
T->Slots = Slots;
|
|
||||||
T->Count = 0;
|
|
||||||
T->Table = 0;
|
|
||||||
T->Func = Func;
|
|
||||||
|
|
||||||
/* Return the initialized table */
|
void DoneHashTable (HashTable* T);
|
||||||
return T;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define InitHashTable(T, Slots, Func) \
|
|
||||||
(T)->Slots = (Slots), \
|
|
||||||
(T)->Count = 0, \
|
|
||||||
(T)->Table = 0, \
|
|
||||||
(T)->Func = (Func), \
|
|
||||||
(T)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE void DoneHashTable (HashTable* T)
|
|
||||||
/* Destroy the contents of a hash table. Note: This will not free the entries
|
/* Destroy the contents of a hash table. Note: This will not free the entries
|
||||||
* in the table!
|
* in the table!
|
||||||
*/
|
*/
|
||||||
{
|
|
||||||
/* Just free the array with the table pointers */
|
|
||||||
xfree (T->Table);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#define DoneHashTable(T) xfree ((T)->Table)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE HashTable* NewHashTable (unsigned Slots, const HashFunctions* Func)
|
INLINE HashTable* NewHashTable (unsigned Slots, const HashFunctions* Func)
|
||||||
@ -184,7 +153,7 @@ void* HT_FindEntry (const HashTable* T, const void* Key);
|
|||||||
void HT_Insert (HashTable* T, HashNode* N);
|
void HT_Insert (HashTable* T, HashNode* N);
|
||||||
/* Insert a node into the given hash table */
|
/* Insert a node into the given hash table */
|
||||||
|
|
||||||
void HT_Remove (HashNode* N);
|
void HT_Remove (HashTable* T, HashNode* N);
|
||||||
/* Remove a node from its hash table */
|
/* Remove a node from its hash table */
|
||||||
|
|
||||||
void HT_InsertEntry (HashTable* T, void* Entry);
|
void HT_InsertEntry (HashTable* T, void* Entry);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user