PrevLink() & NextLink()
BlitzMax Forums/BlitzMax Programming/PrevLink() & NextLink() How do I use those commands?
You can't, when you're using eachin, since eachin gives you the actual object (aka. value) in question, rather than the TLink. I've answered on CW but here's a clumsy example...
You'll need to add checks whether my_next_link and my_prev_link are null to avoid errors.
If anybody can clean this up I'd appreciate it.
my_list:TList=CreateList() Type my_type Field my_num End Type For x = 5 To 11 f:my_Type = New my_Type f.my_num=x ListAddLast my_list,f Next currentLink:TLink=my_list.firstlink() Repeat currenttype:my_type = my_type(currentlink.value()) If currenttype.my_num=9 ' This is the value/field you're looking for. my_next_link:TLink=currentlink.nextlink() my_prev_link:TLink=currentlink.prevlink() my_next_type:my_type = my_type(my_next_link.value()) my_next_type.my_num=999 my_prev_type:my_type = my_type(my_prev_link.value()) my_prev_type.my_num=888 currentlink:TLink=currentlink.nextlink() Else currentlink:TLink=currentlink.nextlink() EndIf Until currentlink=Null For a:my_type = EachIn my_list Print a.my_num Next
You'll need to add checks whether my_next_link and my_prev_link are null to avoid errors.
If anybody can clean this up I'd appreciate it.
I'm working on a totally restructured and rewritten version of TList (Group and node rather than TList and TLink). Also included is a LIFO (last in first out) stack that is used for for/eachin loops so that you can get the current node object for nested loops.
I've got alot of it working, but still yet to finish all the functions, document and test them. It will also be much more hierarchy friendly. Groups extend nodes so they can be used as the nodes of other groups.
The main problem i'm trying to deal with now is that if you exit a for eachin loop withour letting it finish, it never gets popped off the enums stack. Not a major problem, but if you have code right after that relys on getting the handle of the current node for the parent loop, you'll accidently access the loop from before. Also it wastes memory.
I'm going to post a request thread so that a method is called when exiting the enumerator.
I had a modification of the linkedlists module that allowed TLink access during looping. The problem was i was also trying to edit the list using this and ended up messing up the link structure so that it wouldnt iterate right. My hierarchy lib will have lots of convenience functions to help with this kind of thing.
I've got alot of it working, but still yet to finish all the functions, document and test them. It will also be much more hierarchy friendly. Groups extend nodes so they can be used as the nodes of other groups.
The main problem i'm trying to deal with now is that if you exit a for eachin loop withour letting it finish, it never gets popped off the enums stack. Not a major problem, but if you have code right after that relys on getting the handle of the current node for the parent loop, you'll accidently access the loop from before. Also it wastes memory.
I'm going to post a request thread so that a method is called when exiting the enumerator.
I had a modification of the linkedlists module that allowed TLink access during looping. The problem was i was also trying to edit the list using this and ended up messing up the link structure so that it wouldnt iterate right. My hierarchy lib will have lots of convenience functions to help with this kind of thing.
Am I missing something?
Or
Strict Type test Field a:Int Field b:Int Field c:Int End Type Local list:TList = New TList For Local i:Int=1 To 10 Local t:test = New test t.a = i t.b = i t.c = i list.AddLast(t) Next For Local t:test=EachIn list If t.a = 5 Local link:TLink = list.FindLink(t) If link.NextLink() Local nextt:test = test(link.NextLink().Value()) nextt.b = 200 nextt.c = 300 EndIf EndIf Next For Local t:test=EachIn list Print t.a Print t.b Print t.c Print Next
Or
Strict Type test Field link:TLink Field a:Int Field b:Int Field c:Int End Type Local list:TList = New TList For Local i:Int=1 To 10 Local t:test = New test t.a = i t.b = i t.c = i t.link = list.AddLast(t) Next For Local t:test=EachIn list If t.a = 5 If t.link.NextLink() Local nextt:test = test(t.link.NextLink().Value()) nextt.b = 200 nextt.c = 300 EndIf EndIf Next For Local t:test=EachIn list Print t.a Print t.b Print t.c Print Next
I think we mean a faster way. Although #2 is decent speed, The added work would be annoiying. imagine #1 with a lis of 10000 objects - very slow.
Thank you people, I can get on with my work now :D