• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] simple dynamic stack

Status
Not open for further replies.
Level 17
Joined
Apr 27, 2008
Messages
2,455
simple dynamic data structure

I want an easy-to-make-and-use-from-crash dynamic data structure.

I need to store X things and get them later.
I don't need to keep the relative order, so if the best choice is not a stack i don't care.
It must be dynamic, so simple stacks with an integer array like the blue version of TimerUtils is not enough.

First i thought that was as simple as that :

JASS:
...
    
    private struct Stack
        lightning light
        thistype next        
    endstruct
...
        local Stack s
        local Stack temp
        
        set s = Stack.create()
        set temp = s
        loop
        // ...
        exitwhen ...
            set temp.next = Stack.create()
            set temp = temp.next
                set temp.light = AddLightningEx("HWPB",true,GetUnitX(caster),GetUnitY(caster),100,GetUnitX(ll.enum),GetUnitY(ll.enum),10)
        endloop

Now, i use the Stack s :

JASS:
...
        local Stack s = ...
 
        call s.destroy()
        loop
        set s = s.next
        exitwhen s == 0
            call DestroyLightning(s.light)
            set s.light = null
            call s.destroy()
        endloop
    endfunction

But then i've realized that .next pointers are not erased, in fact the best idea i have is to use a double linked list instead, then i can erase all pointers going through the Stack.

Someone has a better idea ?
 
Yeah, you can either use a double linked list or do something along the lines of:
JASS:
local Stack s = ...
local Stack temp = ...
loop
    set temp = s
    set s = s.next
    exitwhen s == 0
    call DestroyLightning(s.light)
    set s.light = null
    call s.destroy()
    set temp.next = 0
endloop

That should clear the pointers as well if I'm not mistaken. (and that should be a viable solution if that is all that you are looking for)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I was going with a double linked list, because i've failed to use correctly a temp variable, but maybe i did something wrong.
Your script should work now i'm seeing it, i will try it because it's a better solution than a double linked list.

Thx.

EDIT : Tested, and obviously works as intented.
 
Last edited:
Status
Not open for further replies.
Top