Deleting item from list
BlitzMax Forums/BlitzMax Beginners Area/Deleting item from list
| ||
Hi its been a while since i used Linked lists and i cant remember how to delete an item. i am going through the list using the EachIn with a next loop command ,and i wanted to use the ListRemove command, but it needs an item of type TLink so it can remove it. how do i get the item in this form. hope that makes sense. Thanks for any help :) |
| ||
Nah... ListRemove(myList,myTypeInstance) No link needed. |
| ||
thanks john, i saw that but it says its not that fast because it ahs to scan the list first. i am using it in a game so i need it to be quick. i think i might use NextLink to go through the list instead. |
| ||
I've always used list.remove(object) and never encountered any noticable/problematic speed issues. I've never even come across anything that's made me want to optimise. Depending on what you're doing you might find TMaps to be more suited. |
| ||
sorry i meant i wanted to use the RemoveLink command, i made a mistake earlier, apologies, but how do i get the link to use in that?, thats what i meant. i could use the ListRemove one but it does sound a waste scanning through the whole list to find it, if i am traversing the list already. i might have lots of Linkedlists for all sorts of objects so would be useful just to remove the link. thank you :) |
| ||
Like Gfk, I haven't been concerned by the speed issues. ListAddLast returns the Tlink of the added entry, so you can store that (usually in a field of the object you added) for later use when removing it. |
| ||
ahh thank you John i will store that. easy when you know how. Thank you very much :) |
| ||
if you are really concerned about speed, the best way to go about it is to stop from creating and deleting objects constantly. Recycling will greatly increase your speed. |
| ||
Type TSomething Field me:TLink Method New() me = somelist.AddLast(Self) End Method Method Kill() me.Remove() End Method End Type |