what are Tlists/Tlinks?

BlitzMax Forums/BlitzMax Beginners Area/what are Tlists/Tlinks?

markcw(Posted 2009) [#1]
I give up. So what are they? Where can I find a clear explanation of them?

Bleh.


Nate the Great(Posted 2009) [#2]
tlists are lists of all of the types you put in them with list.addlast(temp:mytype)

so when you say

For m:mytype = EachIn mylist
Next


it will iterate through every type you put in that list


ImaginaryHuman(Posted 2009) [#3]
Basically TList is a linked list - a chain of joined-together links. Each link contains an object which you store within it. So it lets you chain together lots of objects. You can add and remove links in the chain easily and the gap left will be closed.

Search for linked lists on wikipedia.


markcw(Posted 2009) [#4]
Ok, I think I get Tlist now. So you could have several different objects in the same list?

What about Tlink?


degac(Posted 2009) [#5]

So you could have several different objects in the same list?


Yes


What about Tlink?



TLINK is the 'link' to a determinated object into the list.

Generally you dont' know what position a determinated object has in the list.
With its LINK you can get it immediately.
So you can REMOVE it, get its VALUE or move to the prev or next item-link in the list.
When you add an object to a list a best practice is to store in a field the link.

Stupidest example in the world
Type myobject
	Field value:Int
	Field link:TLink
	
End Type

Local mylist:TList=New TList
Local ob:myobject

For k=1 To 100
ob=New myobject
ob.value=k
ob.link=mylist.addlast(ob)
Next



markcw(Posted 2009) [#6]
I'm thankful for stupid examples.


markcw(Posted 2009) [#7]
How do you update the current object?

I have a list of strings in a tlist and a tlink pointing to the current one, how do I change the string pointed to by tlink?


REDi(Posted 2009) [#8]
Local list:TList = New TList

list.addlast("one")
list.addlast("two")
Local link:TLink = List.addlast("four")

link._value = "three"

Local s$
For s=EachIn list
	Print s
Next



markcw(Posted 2009) [#9]
Crap _value is in Tlink. Where do you guys learn this stuff??


kfprimm(Posted 2009) [#10]
BRL.LinkedList or,
C:\Program Files\BlitzMax\mod\brl.mod\linkedlist.mod

Often, I've found that viewing source files can be a very good source of documentation.


markcw(Posted 2009) [#11]
Behold the stupidist example in the world!
' arrays.bmx

SuperStrict
Framework brl.basic

Local arr:Int[]=[9,8,7,6,5,4,3,2,1]
Local i:Int

Print "-arr contents"
For i=EachIn arr
  Print i
Next

Print "-arr.length"
Print arr.length

arr=arr[..18]

Print "-arr.length after slice operator"
Print arr.length

Print "-arr 0..8 loop"
For i=0 To arr.length-1
  Print arr[i]
Next



markcw(Posted 2009) [#12]
Ok, I have a Tlink to the current Tlist object.

I want to go back N times in the list but I have to avoid loosing my current Tlink if N times is too many.

Do I have to store the Tlink or is there a smarter way?


degac(Posted 2009) [#13]
Type tdatum
	Field value:Int
	Field link:TLink
	
End Type

Global list_mylist:TList=New TList


'some data
Local i:Int,da:tdatum
Local curlink:TLink,prevlink:TLink

For i=1 To 10

da=New tdatum
da.value=i*10

da.link=list_mylist.addlast(da)
Next

'print the content of the list

For da=EachIn list_mylist
	Print "> "+da.value
Next

'find the item in the list with VALUE=60

For da=EachIn list_mylist
	If da.value=60
		'curlink=da.link ' this is a FASTER solution
		'or ...> 
		curlink = list_mylist.FindLink(da) ' this is SLOW ->
' Bmax need to scan the entire list to find the link...better saving it into the user-type
		
	End If
Next

If curlink<>Null
	Print "New link found..."
	Print "Move BACK of 3 link..."
	
	For Local s:Int=1 To 3
		prevlink=curlink.PrevLink()
         ' you should check if PREVLINK is null or not...
 
		curlink=prevlink
	Next
	
	Print "Now What is value of CURLINK? ="+tdatum(curlink.value()).value
	'you need to CAST into your type ... link.Value() will return an OBJECT
	
	
End If



markcw(Posted 2009) [#14]
How do you continue code to the next line? Is it ..?

Edit: too slow. :)