Moderator
M
Moderator
17:13, 15th Mar 2013
Magtheridon96: Approved.
Magtheridon96: Approved.
//************************************************************************************
//*
//*
//* LINKED LIST TABLE
//*
//* BY : ALMIA
//*
//*
//************************************************************************************
//*
//* Used to create linked list
//*
//************************************************************************************
//*
//*
//* CODE API
//*
//* constant function LLT_PrevArrayValueKey takes nothing returns integer
//* constant function LLT_NextArrayValueKey takes nothing returns integer
//* constant function LLT_RecycleArrayValueKey takes nothing returns integer
//* constant function LLT_ICChildKey takes nothing returns integer
//* - system constants for settings
//* - Recommended not to be touched
//*
//* function CreateLinkedList takes nothing returns integer
//* - Creates linked lists
//*
//* function ClearLinkedList takes integer list returns nothing
//* - Clears linked lists cached values
//*
//* function DestroyLinkedList takes integer list returns nothing
//* - Destroys linked list
//*
//* function GetNewIndexFromLinkedList takes integer list returns integer
//* - Allocates a new instance for the linked list
//*
//* function RecycleIndexFromLinkedList takes integer list,integer index returns nothing
//* - Recycles the instance
//* - Commonly used when a code's effect ends
//*
//* function GetNextIndexFromLinkedList takes integer index , integer list returns integer
//* - Gets next index for the enumeration of index
//*
//* function GetPrevIndexFromLinkedList takes integer index , integer list returns integer
//* - Gets prev index for the enumeration of index
//*
//* function GetFirstIndexFromLinkedList takes integer list returns integer
//* - Gets first index for the enumeration of index
//*
//* function GetLastIndexFromLinkedList takes integer list returns integer
//* - Gets last index for the enumeration of index
//*
//************************************************************************************
//*
//* ITERATION MODULE
//*
//* Module for iterating instance
//* Must be CnPed
//*
//* All words in between "$" should be replaced by
//* your own variable
//*
//* Legend:
//*
//* $LIST$ = Your List
//* $INDEX$ = Your Index
//* $CODE$ = Your code
//*
//*
//* set $INDEX$ = GetFirstIndexFromLinkedList($LIST$)
//*
//* loop
//* exitwhen $INDEX$ == 0
//*
//* $CODE$
//* ( NOTE : If the code's effect ends
//* please recycle index via calling:
//* call RecycleIndexFromLinkedList($LIST$, $INDEX$)
//* in a custom script)
//*
//* set $INDEX$ = GetNextIndexFromLinkedList($LIST$, $INDEX$)
//*
//* endloop
//*
//*
//* DESCRIPTION :
//*
//* This way,you can iterate indexed variables
//* unlike Indexed Arrays or Dynamic Indexing
//* You use custom scripts because GUI For Loop Integer
//* cannot handle this kind of iteration
//*
//************************************************************************************
//*
//* Variables :
//*
//* LLT_Table = hashtable
//* LLT_RC = integer array
//*
//************************************************************************************
//*
//* Credits :
//*
//* - Magtheridon96
//* - Maker
//* - Ruke
//*
//************************************************************************************
//***********************************************************
//*
//* SETTINGS
//*
//***********************************************************
//The following constants refer to minimum value of next
//prev and recycle.
constant function LLT_PrevArrayValueKey takes nothing returns integer
return 0
endfunction
constant function LLT_NextArrayValueKey takes nothing returns integer
return JASS_MAX_ARRAY_SIZE// 8192
endfunction
constant function LLT_RecycleArrayValueKey takes nothing returns integer
return 2* JASS_MAX_ARRAY_SIZE //16384
endfunction
constant function LLT_ICChildKey takes nothing returns integer
return -1
endfunction
//***********************************************************
//*
//* TOOLS
//*
//***********************************************************
function LLT_GetNextKey takes integer index returns integer
return LLT_NextArrayValueKey() + index
endfunction
function LLT_GetPrevKey takes integer index returns integer
return LLT_PrevArrayValueKey() + index
endfunction
function LLT_GetRCKey takes integer index returns integer
return LLT_RecycleArrayValueKey() + index
endfunction
//* SETS and GETS functions
//Get Values
function GetNextIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetNextKey(index))
endfunction
function GetPrevIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetPrevKey(index))
endfunction
function GetRecycleIndexOfList takes integer list , integer index returns integer
return LoadInteger(udg_LLT_Table, list, LLT_GetRCKey(index))
endfunction
//Set Values
function SetNextIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetNextKey(index), value)
endfunction
function SetPrevIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetPrevKey(index), value)
endfunction
function SetRecycleIndexOfList takes integer list , integer index , integer value returns nothing
call SaveInteger(udg_LLT_Table, list, LLT_GetRCKey(index), value)
endfunction
//***********************************************************
//*
//* MAIN FUNCTIONS
//*
//***********************************************************
function CreateLinkedList takes nothing returns integer
local integer index
//Initializing
if null == udg_LLT_Table then
set udg_LLT_Table = InitHashtable()
set udg_LLT_RC[0] = 1
endif
set index = udg_LLT_RC[0]
if udg_LLT_RC[index] == 0 then
set udg_LLT_RC[0] = index + 1
else
set udg_LLT_RC[0] = udg_LLT_RC[index]
endif
call SetRecycleIndexOfList(index, 0, 1)
return index
endfunction
function ClearLinkedList takes integer list returns nothing
call FlushChildHashtable(udg_LLT_Table, list)
endfunction
function DestroyLinkedList takes integer list returns nothing
call ClearLinkedList(list)
set udg_LLT_RC[list] = udg_LLT_RC[0]
set udg_LLT_RC[0] = list
endfunction
function GetNewIndexFromLinkedList takes integer list returns integer
local integer this = GetRecycleIndexOfList(list, 0)
//Allocating Instance
if GetRecycleIndexOfList(list, this) == 0 then
call SetRecycleIndexOfList(list, 0, this + 1)
else
call SetRecycleIndexOfList(list, 0, GetRecycleIndexOfList(list, this))
endif
// Adding the instance to list
call SetNextIndexOfList(list, this, 0)
call SetPrevIndexOfList(list, this, GetPrevIndexOfList(list, 0))
call SetNextIndexOfList(list, GetPrevIndexOfList(list, 0), this)
call SetPrevIndexOfList(list, 0, this)
return this
endfunction
function RecycleIndexFromLinkedList takes integer list,integer index returns nothing
//Recycling instance
call SetNextIndexOfList(list, GetPrevIndexOfList(list, index), GetNextIndexOfList(list, index))
call SetPrevIndexOfList(list, GetNextIndexOfList(list, index), GetPrevIndexOfList(list, index))
call SetRecycleIndexOfList(list, index, GetRecycleIndexOfList(list, 0))
call SetRecycleIndexOfList(list, 0, index)
endfunction
//***********************************************************
//*
//* EXTRA FUNCTIONS
//*
//***********************************************************
function GetNextIndexFromLinkedList takes integer list , integer index returns integer
return GetNextIndexOfList(list, index)
endfunction
function GetPrevIndexFromLinkedList takes integer list, integer index returns integer
return GetPrevIndexOfList(list, index)
endfunction
function GetFirstIndexFromLinkedList takes integer list returns integer
return GetNextIndexOfList(list, 0)
endfunction
function GetLastIndexFromLinkedList takes integer list returns integer
return GetPrevIndexOfList(list, 0)
endfunction