1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-04 13:29:35 +00:00

New function and bug fix

git-svn-id: svn://svn.cc65.org/cc65/trunk@2609 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-11-04 18:59:12 +00:00
parent 37393c645e
commit b34d2df08b
3 changed files with 40 additions and 13 deletions

View File

@ -77,7 +77,22 @@ static void HT_Alloc (HashTable* T)
HashNode* HT_Find (const HashTable* T, const void* Key)
/* Find the node with the given index */
{
unsigned Hash;
/* 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.
*/
{
HashNode* N;
/* If we don't have a table, there's nothing to find */
@ -85,9 +100,6 @@ HashNode* HT_Find (const HashTable* T, const void* Key)
return 0;
}
/* Generate the hash over the index */
Hash = T->Func->GenHash (Key);
/* Search for the entry in the given chain */
N = T->Table[Hash % T->Slots];
while (N) {
@ -96,7 +108,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->GetKey (N->Entry)) == 0) {
T->Func->Compare (Key, T->Func->GetKey (HN_GetEntry (N))) == 0) {
/* Found */
break;
}
@ -118,7 +130,7 @@ void* HT_FindEntry (const HashTable* T, const void* Key)
HashNode* N = HT_Find (T, Key);
/* Convert the node into an entry if necessary */
return N? N->Entry : 0;
return N? HN_GetEntry (N) : 0;
}
@ -134,7 +146,7 @@ void HT_Insert (HashTable* T, HashNode* N)
}
/* Generate the hash over the node key. */
N->Hash = T->Func->GenHash (T->Func->GetKey (N->Entry));
N->Hash = T->Func->GenHash (T->Func->GetKey (HN_GetEntry (N)));
/* Calculate the reduced hash */
RHash = N->Hash % T->Slots;
@ -182,7 +194,7 @@ void HT_Walk (HashTable* T, void (*F) (void* Entry, void* Data), void* Data)
/* Walk over all entries in this chain */
while (N) {
/* Call the user function */
F (N->Entry, Data);
F (HN_GetEntry (N), Data);
/* Next node in chain */
N = N->Next;
}

View File

@ -109,10 +109,20 @@ INLINE void InitHashNode (HashNode* N, void* Entry)
N->Entry = Entry;
}
#else
#define InitHashNode(N, Entry) \
(N)->Next = 0; \
(N)->Owner = 0; \
(N)->Entry = (Entry)
#define InitHashNode(N, E) \
(N)->Next = 0, \
(N)->Owner = 0, \
(N)->Entry = (E)
#endif
#if defined(HAVE_INLINE)
INLINE void* HN_GetEntry (HashNode* N)
/* Get the entry from a hash node */
{
return N->Entry;
}
#else
#define HN_GetEntry(N) (N)->Entry
#endif
@ -175,6 +185,11 @@ void FreeHashTable (HashTable* T);
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 */

View File

@ -10,7 +10,7 @@ export WATCOM = c:\\watcom
export INCLUDE = $(WATCOM)\\h
# We will use the windows compiler under linux (define as empty for windows)
WINE = wine --
WINE = wine --
# Programs
AR = $(WINE) WLIB