1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Melee Mapping contest #3 - Poll is up! Vote for the best 4v4 melee maps!
    Dismiss Notice
  3. The 30th edition of the Modeling Contest is finally up! The Portable Buildings need your attention, so come along and have a blast!
    Dismiss Notice
  4. We have a new contest going on right now! Join the 11th Music Contest! You are to make a Cinematic modern sound-track for this contest, so come and compete with other people for fun.
    Dismiss Notice

Linked List Table v1.5

Submitted by Almia
This bundle is marked as approved. It works and satisfies the submission rules.
  • 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 :
Code (vJASS):
//************************************************************************************
//*
//*
//*                             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
Moderator
17:13, 15th Mar 2013 Magtheridon96: Approved.
  1. 17:13, 15th Mar 2013
    Magtheridon96: Approved.
     
  2. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    ~Reserved
     
  3. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,005
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Remember that talk we had the other day?
     
  4. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Updated
    Happy now,Mag? :D
     
    Last edited: Mar 15, 2013
  5. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Updated.
    As of what you said Mag.

    Suggesting anything coz i have to update my Spell Indexer to use this.

    edit

    Mag ingore that module,gonna update it.

    edit

    Also gonna update the GetFirstIndex and NextIndex
     
    Last edited: Mar 16, 2013
  6. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,005
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Yes, the function names are much better now c:

    I would've done:
    LinkedListGetNext
    LinkedListGetPrevious
    LinkedList<name here>
    etc...

    But this is fine too as long as the API is listed properly and documented at the top of the script.
     
  7. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Listed properly? what do you mean? It is documented in the top of the script,with explanations
     
  8. Ofel

    Ofel

    Joined:
    Mar 29, 2012
    Messages:
    406
    Resources:
    10
    Spells:
    10
    Resources:
    10
    Just a little question. What's API??
     
  9. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,005
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    Application Programming Interface.

    The functions, methods, structs, modules, interfaces and variables that you use and have access to in a certain library.
     
  10. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    System will be updated later.
    I will use another method to initialize this system so users won't need to worry initializing this thing.


    edit
    Updated.
     
    Last edited: Mar 18, 2013
  11. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Updated.
     
  12. Veronnis

    Veronnis

    Joined:
    Jul 19, 2010
    Messages:
    96
    Resources:
    4
    Models:
    1
    Maps:
    3
    Resources:
    4
    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.
     
  13. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,839
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    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.
     
  14. Veronnis

    Veronnis

    Joined:
    Jul 19, 2010
    Messages:
    96
    Resources:
    4
    Models:
    1
    Maps:
    3
    Resources:
    4
    Okay, thank you! I'll have to read the tutorial about leaks and such as I'm only vaguely familiar with them.