mirror of
https://github.com/cc65/cc65.git
synced 2025-02-27 14:29:52 +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:
parent
37393c645e
commit
b34d2df08b
@ -77,7 +77,22 @@ static void HT_Alloc (HashTable* T)
|
|||||||
HashNode* HT_Find (const HashTable* T, const void* Key)
|
HashNode* HT_Find (const HashTable* T, const void* Key)
|
||||||
/* Find the node with the given index */
|
/* 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;
|
HashNode* N;
|
||||||
|
|
||||||
/* If we don't have a table, there's nothing to find */
|
/* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate the hash over the index */
|
|
||||||
Hash = T->Func->GenHash (Key);
|
|
||||||
|
|
||||||
/* Search for the entry in the given chain */
|
/* Search for the entry in the given chain */
|
||||||
N = T->Table[Hash % T->Slots];
|
N = T->Table[Hash % T->Slots];
|
||||||
while (N) {
|
while (N) {
|
||||||
@ -96,7 +108,7 @@ HashNode* HT_Find (const HashTable* T, const void* Key)
|
|||||||
* if it is not really necessary.
|
* if it is not really necessary.
|
||||||
*/
|
*/
|
||||||
if (N->Hash == Hash &&
|
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 */
|
/* Found */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -118,7 +130,7 @@ void* HT_FindEntry (const HashTable* T, const void* Key)
|
|||||||
HashNode* N = HT_Find (T, Key);
|
HashNode* N = HT_Find (T, Key);
|
||||||
|
|
||||||
/* Convert the node into an entry if necessary */
|
/* 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. */
|
/* 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 */
|
/* Calculate the reduced hash */
|
||||||
RHash = N->Hash % T->Slots;
|
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 */
|
/* Walk over all entries in this chain */
|
||||||
while (N) {
|
while (N) {
|
||||||
/* Call the user function */
|
/* Call the user function */
|
||||||
F (N->Entry, Data);
|
F (HN_GetEntry (N), Data);
|
||||||
/* Next node in chain */
|
/* Next node in chain */
|
||||||
N = N->Next;
|
N = N->Next;
|
||||||
}
|
}
|
||||||
|
@ -109,10 +109,20 @@ INLINE void InitHashNode (HashNode* N, void* Entry)
|
|||||||
N->Entry = Entry;
|
N->Entry = Entry;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define InitHashNode(N, Entry) \
|
#define InitHashNode(N, E) \
|
||||||
(N)->Next = 0; \
|
(N)->Next = 0, \
|
||||||
(N)->Owner = 0; \
|
(N)->Owner = 0, \
|
||||||
(N)->Entry = (Entry)
|
(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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -175,6 +185,11 @@ void FreeHashTable (HashTable* T);
|
|||||||
HashNode* HT_Find (const HashTable* T, const void* Key);
|
HashNode* HT_Find (const HashTable* T, const void* Key);
|
||||||
/* Find the node with the given 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);
|
void* HT_FindEntry (const HashTable* T, const void* Key);
|
||||||
/* Find the node with the given key and return the corresponding entry */
|
/* Find the node with the given key and return the corresponding entry */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user