- Joined
- Aug 1, 2013
- Messages
- 4,658
Hi all.
I dont really know if such a thing exists like this but I just created it... dont know why.
If there does exist one, please link it.
Otherwise, just this:
Sorry for no documentation but it should be very simple.
You create a new object for each linked list that you need.
Every Linked List Object (created using textmacros) has 8190 indexes.
Every Linked List Object creates a linked list for every id.
The actual data of each index can be created by the system or spell that uses the linked list.
You as map maker should be able to make sure that there will never be more than 8190 indexes.
I dont really know if such a thing exists like this but I just created it... dont know why.
If there does exist one, please link it.
Otherwise, just this:
JASS:
/! textmacro CREATE_LINKED_LIST takes NAME
library LL$NAME$
globals
integer LL_$NAME$_NewIndex = 0
boolean array LL_$NAME$_IsOccupied
integer array LL_$NAME$_FirstIndex
integer array LL_$NAME$_LastIndex
integer array LL_$NAME$_PreviousIndex
integer array LL_$NAME$_NextIndex
endglobals
//System function
function $NAME$_NewIndex takes nothing returns integer
loop
set LL_$NAME$_NewIndex = LL_$NAME$_NewIndex +1
if LL_$NAME$_NewIndex >= 8191 then
set LL_$NAME$_NewIndex = 1
endif
exitwhen not LL_$NAME$_IsOccupied[LL_$NAME$_NewIndex]
endloop
set LL_$NAME$_IsOccupied[LL_$NAME$_NewIndex] = true
return LL_$NAME$_NewIndex
endfunction
//User function
function $NAME$_CreateIndex takes integer id returns integer
local integer newIndex = $NAME$_NewIndex()
set LL_$NAME$_NextIndex[LL_$NAME$_LastIndex[id]] = newIndex
set LL_$NAME$_PreviousIndex[newIndex] = LL_$NAME$_LastIndex[id]
set LL_$NAME$_LastIndex[id] = newIndex
return newIndex
endfunction
//User function
function $NAME$_GetIndex takes integer id, integer index returns integer
local integer i = 0
local integer result = LL_$NAME$_FirstIndex[id]
loop
exitwhen i >= index
set result = LL_$NAME$_NextIndex[result]
if result == 0 then
return -1
endif
set i = i +1
endloop
return result
endfunction
//User function
function $NAME$_RemoveIndex takes integer id, integer index returns nothing
local integer i = 0
local integer remove = LL_$NAME$_FirstIndex[id]
loop
exitwhen i >= index
set remove = LL_$NAME$_NextIndex[remove]
set i = i +1
endloop
set LL_$NAME$_PreviousIndex[LL_$NAME$_NextIndex[remove]] = LL_$NAME$_PreviousIndex[remove]
set LL_$NAME$_NextIndex[LL_$NAME$_PreviousIndex[remove]] = LL_$NAME$_NextIndex[remove]
set LL_$NAME$_IsOccupied[remove] = false
if remove == LL_$NAME$_LastIndex[id] then
set LL_$NAME$_LastIndex[id] = LL_$NAME$_PreviousIndex[remove]
endif
if remove == LL_$NAME$_FirstIndex[id] then
set LL_$NAME$_FirstIndex[id] = LL_$NAME$_NextIndex[remove]
endif
endfunction
endlibrary
//! endtextmacro
Sorry for no documentation but it should be very simple.
You create a new object for each linked list that you need.
Every Linked List Object (created using textmacros) has 8190 indexes.
Every Linked List Object creates a linked list for every id.
The actual data of each index can be created by the system or spell that uses the linked list.
You as map maker should be able to make sure that there will never be more than 8190 indexes.