- Joined
- Apr 24, 2012
- Messages
- 5,113
[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
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[/code]
Im a confused about this.
Can someone post some example usage(no vJASS please)
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
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[/code]
Im a confused about this.
Can someone post some example usage(no vJASS please)