• 🏆 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!

Linked List Table v1.5

  • Like
Reactions: deepstrasz and Ofel
  • Linked List Table By Almia
  • Features:
    • No need to write your own linked list or code them
    • Enumeration module(actually,needed to be CnP by users)
    • No StringHash( Yay! )
    • Uses only 3 variables
  • What does this thing do?
    • The Linked List Table allows you to create a linked list by hashtables,though unlike normal linked lists,this is marginally slow(hashtables did this)
    • This thing also helps you not to code your own module for linked lists,this thing will do it for ya !
  • How to use:
    -For the initialization
    • You have to use 2 variables for the linked list:
      - variable for an index
      - variable for the list
    • Register the variable for the list ( eg . TC_List ) via CreateLinkedList
      • Custom script: set udg_TC_List = CreateLinkedList()
    • There you have it,initialization is done.
    - For getting an instance
    • Set the variable for index then call GetNewIndexFromLinkedList,this function gets the linked list you created(as shown above)
      • Custom script: set udg_TC_TempIndex = GetNewIndexFromLinkedList(udg_TC_List)
    • Now,all your needed variables for the MUI you want,index them!
      • Set TC_U[TC_TempIndex] = (Triggering unit)
      • Set TC_Timer[TC_TempIndex] = 0.00
    - For iteration
    • Please read the iteration module in the code.
    • Here is a simple demo:
      • Thunder Clap Loop
        • Events
          • Time - Every 0.03 seconds of game time
        • Conditions
        • Actions
          • -------- Set Index --------
          • Custom script: set udg_TC_Index = GetFirstIndexFromLinkedList(udg_TC_List)
          • -------- Enumerate --------
          • Custom script: loop
          • -------- Check if index is 0 --------
          • Custom script: exitwhen 0 == udg_TC_Index
          • -------- If not --------
          • -------- Code Here --------
          • -------- Ex --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • TC_Timer[TC_Index] Less than 10.00
            • Then - Actions
              • Set TC_Timer[TC_Index] = (TC_Timer[TC_Index] + 0.03)
              • Special Effect - Create a special effect attached to the origin of TC_U[TC_Index] using Abilities\Spells\Human\DispelMagic\DispelMagicTarget.mdl
              • Special Effect - Destroy (Last created special effect)
            • Else - Actions
              • -------- If object effect is finished,recycle index --------
              • Custom script: call RecycleIndexFromLinkedList(udg_TC_List, udg_TC_Index)
              • -------- null variables --------
              • Set TC_U[TC_Index] = No unit
          • -------- Set next index --------
          • Custom script: set udg_TC_Index = GetNextIndexFromLinkedList(udg_TC_List, udg_TC_Index)
          • Custom script: endloop
      This trigger is connected in the codes above.
  • Credits
    • Magtheridon96 , for teaching me this
    • Maker, for the enlightening
    • Ofel , for convincing me(yeah , he wants to learn
    • Ruke, for the alloc model
  • Changelog
    - Now uses Ruke's alloc model
    - Added GetPrev and GetLast
    - Fixed a bug about a wrong insertion method
Code :
JASS:
//************************************************************************************
//*
//*
//*                             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
Contents

Linked List Table v1.5 (Map)

Reviews
17:13, 15th Mar 2013 Magtheridon96: Approved.
Hey Almia, I am brand new to using systems, like BRAND NEW. Anyway I am currently using a sub-desirable method to apply temporary spell effects to my creatures. I really liked your test map for Timed Effects and saw it required the use of this list to function. As I am new, please forgive if my question is dumbly obvious; but, would implementing this system into my RPG (This being the first system) degrade the map performance for any of my players? and if so, how much (No issues / Lag) Also thanks for being active, I checked when you were last on to see if it'd be worth posting.
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
hello there.

This is quite one of my old resources but I must say one of also the remarkable ones I worked on.

No, this wouldn't affect your map's performance, whether it would be lag, issues, etc. because I have implemented this on my map myself.

It is up to you how would you use the system, and how would you control the leaks the triggers or codes you made produce.
 
Top