So a while back, we started to see a lot of "black magic" pop up (I'm looking at you Jesus4Lyf ), and i started wondering if it would be worth learning linked lists, as I am a ridiculously slow learning when it comes to new concepts.
Then after making a few spells and stuff, I realised that I am using the struct stacks a lot, and maybe it would be helpful to implement a linked list that can be used to keep track of the currently used structs to reduce complexity a little, and by complexity I mean making it easier to write and stuff. I'm not sure whether its faster or not, but I would assume they would be around the same.
So I went a-learnin' and basically I've come up with this:
Okay so I'm not even sure if it works as I'm not on my home computer, so feedback is good. If it doesn't work I don't want it done for me (at first ), maybe just some hints.
What I want to do in the future:
- Add a boolean variable to see whether or not a struct is already assigned to a node.
- Anything that anyone can point out.
Thanks in advance.
EDIT:
Oh and the reason I am using textmacro and integer members is because I don't have the latest Jasshelper, I want to be able to test it when i get on my home computer. I will probably update it when I read the jasshelper manual a bit more.
Then after making a few spells and stuff, I realised that I am using the struct stacks a lot, and maybe it would be helpful to implement a linked list that can be used to keep track of the currently used structs to reduce complexity a little, and by complexity I mean making it easier to write and stuff. I'm not sure whether its faster or not, but I would assume they would be around the same.
So I went a-learnin' and basically I've come up with this:
JASS:
library LLM
//! textmacro LIST
integer next = 0
integer prev = 0
static integer first = 0
static integer last = 0
static integer max = 0
method linkNode takes nothing returns boolean
if .first == 0 then
set .first = this
else
set .prev = .last
set .prev.next = this
endif
set .last = this
set .max = .max + 1
return true
endmethod
method unlinkNode takes nothing returns boolean
if .first == this then
set .first = .next
endif
if .last == this then
set .last = .prev
endif
set .prev.next = .next
set .next.prev = .prev
set .max = .max - 1
return true
endmethod
method getNext takes nothing returns integer
return .next
endmethod
method getPrev takes nothing returns integer
return .prev
endmethod
method getMax takes nothing returns integer
return .max
endmethod
//! endtextmacro
endlibrary
Okay so I'm not even sure if it works as I'm not on my home computer, so feedback is good. If it doesn't work I don't want it done for me (at first ), maybe just some hints.
What I want to do in the future:
- Add a boolean variable to see whether or not a struct is already assigned to a node.
- Anything that anyone can point out.
Thanks in advance.
EDIT:
Oh and the reason I am using textmacro and integer members is because I don't have the latest Jasshelper, I want to be able to test it when i get on my home computer. I will probably update it when I read the jasshelper manual a bit more.