TList : AddLast etc...

BlitzMax Forums/BlitzMax Programming/TList : AddLast etc...

Filax(Posted 2008) [#1]
Hi

I'm a little bit lost whith the bmax tlink commands
(like addlast addfirst from blitz3D) Anybody can help
me ?

Original code (blitz3D) :



My blitzmax code :




Dreamora(Posted 2008) [#2]
why do you not just use for local t:thingyT = eachin thingyTList ...


N(Posted 2008) [#3]
Try changing AddLast to AddFirst and doing something like this for you update code:
Local Mx:Int=MouseX()
Local My:Int=MouseY()

Local newlist:TList = thingyTList.Copy()

For Local this:thingyT = EachIn thingyTList
    If (mx >= this.x) And (mx <= (this.x+this.width-1)) And ..
        (my >= this.y) And (my <= (this.y+this.height-1))

        newlist.Remove( this )
        newlist.AddFirst( this )

    EndIf
Next

thingyTList.Clear()
thingyTList = newlist
newlist = Null ' precaution


I have to admit though, I'm somewhat confused. You wrote a GUI for BMax, and you're not sure how linked lists work? O_o


Dreamora(Posted 2008) [#4]
Might explain why users of the library opted it to tripple the speed ^^


Filax(Posted 2008) [#5]
Pure Cane Soda : You are right it's strange :) Maybe an alien
instead me, wrote the library? :) i understand the method
EachIn without problem but the approach via while / Wend
and tlink is maybe usefull too? Thanks for your help :)

Edit :
But as you can see the list in the blitz code is browsed
from the last to the first. the method eachin browse the
list from start to end. This is why I am asking the
question about the tlink :)

Dreamora : What? :/


DavidDC(Posted 2008) [#6]
Filax, I think you are looking for TLink.PrevLink:TLink() and TList.InsertAfterLink:TLink(value:Object, pred:TLink)


Filax(Posted 2008) [#7]
You are right David! but the doc do not really help me :/


DavidDC(Posted 2008) [#8]
Does this help?

Pseudocode:

Local link:TLink = List.LastLink()

While link

	If TListItemType(link.Value()) = ItemWeAreSearchingFor
		List.InsertAfterLink(NewListItem,link)
		Exit
	EndIf

	link = PrevLink()

Wend



Dreamora(Posted 2008) [#9]
the approach you use there makes only partially sense.

what makes more sense is to store the TLink you get from addFirst / AddLast when adding an element to the object that you added.
That allows you to get the previous / next element of each element in the list as well as removing it instantanous from the list if needed.
moving it around the list is as well no problem


Filax(Posted 2008) [#10]
I'll try others methods, thanks for help :)


dmaz(Posted 2008) [#11]
here is an extended list I did where you can go from any link forwards or backwards
http://www.blitzbasic.com/codearcs/codearcs.php?code=1807


Filax(Posted 2008) [#12]
Thanks Dmaz i'll take a look ;)


Jake L.(Posted 2008) [#13]
Did you know, that eachin is that intelligent to only return values of a certain type? I didn't until now...



Until now I thought that obj will be Null for TB-objects.

Blitzmax is such a lovely language!