From: cuz Date: Wed, 22 Oct 2003 19:13:02 +0000 (+0000) Subject: More tweaking of the new hashtab module X-Git-Tag: V2.12.0~1234 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ff2dca420b7e63266f85a8fb9cdc0d6294b62a11;p=cc65 More tweaking of the new hashtab module git-svn-id: svn://svn.cc65.org/cc65/trunk@2560 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/common/hashtab.c b/src/common/hashtab.c index 72319a6a2..3572086ed 100644 --- a/src/common/hashtab.c +++ b/src/common/hashtab.c @@ -96,7 +96,7 @@ HashNode* HT_Find (const HashTable* T, const void* Key) * if it is not really necessary. */ if (N->Hash == Hash && - T->Func->Compare (Key, T->Func->GetIndex (N->Entry))) { + T->Func->Compare (Key, T->Func->GetKey (N->Entry))) { /* Found */ break; } @@ -133,8 +133,8 @@ void HT_Insert (HashTable* T, HashNode* N) HT_Alloc (T); } - /* Generate the hash for the node contents */ - N->Hash = T->Func->GenHash (T->Func->GetIndex (N->Entry)); + /* Generate the hash over the node key. */ + N->Hash = T->Func->GenHash (T->Func->GetKey (N->Entry)); /* Calculate the reduced hash */ RHash = N->Hash % T->Slots; @@ -143,6 +143,9 @@ void HT_Insert (HashTable* T, HashNode* N) N->Next = T->Table[RHash]; T->Table[RHash] = N; + /* Set the owner */ + N->Owner = T; + /* One more entry */ ++T->Count; } diff --git a/src/common/hashtab.h b/src/common/hashtab.h index 24e492716..b50acee42 100644 --- a/src/common/hashtab.h +++ b/src/common/hashtab.h @@ -59,7 +59,7 @@ struct HashNode { void* Entry; /* Pointer to user entry data */ }; -#define STATIC_HASHNODE_INITIALIZER(Entry) { 0, 0, 0, Entry } +#define STATIC_HASHNODE_INITIALIZER(Entry) { 0, 0, 0, Entry } /* Hash table functions */ typedef struct HashFunctions HashFunctions; @@ -68,8 +68,8 @@ struct HashFunctions { unsigned (*GenHash) (const void* Key); /* Generate the hash over a key. */ - const void* (*GetIndex) (void* Entry); - /* Given a pointer to the user entry data, return a pointer to the index */ + const void* (*GetKey) (void* Entry); + /* Given a pointer to the user entry data, return a pointer to the key */ HashNode* (*GetHashNode) (void* Entry); /* Given a pointer to the user entry data, return a pointer to the hash node */ @@ -99,7 +99,7 @@ struct HashTable { #if defined(HAVE_INLINE) INLINE void InitHashNode (HashNode* N, void* Entry) -/* Initialize a hash node */ +/* Initialize a hash node. */ { N->Next = 0; N->Owner = 0;