• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

jass]

JASS:
integer array next
integer array prev

integer instanceCount = 0
integer array recycler
    
function add takes integer node returns nothing
    set next[node] = 0
    set prev[node] = prev[0]
    set next[prev[0]] = node
    set prev[0] = node
endfunction
    
function remove takes integer node returns nothing
    set next[prev[node]] = next[node]
    set prev[next[node]] = prev[node]
endfunction

function loop takes nothing returns nothing
    local integer this = next[0]
    loop
        exitwhen this == 0
        // Your code here using "this" as the current index :D
        set this = next[this]
    endloop
endfunction

function allocateIndex takes nothing returns integer
    local integer index = recycler[0]
    if index == 0 then
        set instanceCount = instanceCount + 1
        set index = instanceCount
    else
        set recycler[0] = recycler[index]
    endif

    return index
endfunction

function deallocateIndex takes integer index returns nothing
    set recycler[this] = recycler[0]
    set recycler[0] = this
endfunction
Last edited:
Top