
The remove function was buggy I belive...
Please note that I removed the hash Table parameter as well as the mutexes because I only need one table at a time and no multithreading support - lock and unlock mutex is very slow compared to entercriticalsection_() btw

Have fun with it.
Code: Select all
Procedure HT_RemoveItem(key$)
Protected numelements, hash, index, firstinlist, lastinlist, item
numelements=PeekL(HTid)
If numelements
;Good to go! First job is to create the hash index.
hash=HT_CreateHash(numelements-1, key$)+1
;hash is now between 1 and 'numelements'.
;First check if there is list of elements with the corresponding hash.
index=HTid+hash*4
firstinlist=PeekL(index)
item = 0
If firstinlist
ChangeCurrentElement(_HTentries(),firstinlist)
Repeat
If _HTentries()\key=key$ And _HTentries()\tableid=HTid ;Key found!
item=_HTentries()
ElseIf _HTentries()\hash<>hash Or _HTentries()\tableid<>HTid ;Gone too far through the list.
lastinlist = _HTentries()
Break
EndIf
Until NextElement(_HTentries())=0
; lastinlist=_HTentries()
If item ;If there is an entry to remove.
;We now have 3 pointers to elements within the list; firstinlist, item, lastinlist.
;We need to use these to update the list accordingly.
If item=firstinlist ;Need to alter the hash table entry to point to next item.
ChangeCurrentElement(_HTentries(),item)
DeleteElement(_HTentries())
NextElement(_HTentries())
PokeL(index, _HTentries())
If _HTentries()\hash<>hash
PokeL(index, 0)
EndIf
ElseIf item = lastinlist
ChangeCurrentElement(_HTentries(),item)
DeleteElement(_HTentries())
Else
ChangeCurrentElement(_HTentries(),item)
DeleteElement(_HTentries())
EndIf
Else
MessageRequester("There is no item to remove","",0)
EndIf
EndIf
EndIf
EndProcedure