Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Snippet] New Table

Discussion in 'JASS Resources' started by Bribe, Jan 25, 2011.

  1. Bannar

    Bannar

    Joined:
    Mar 19, 2008
    Messages:
    3,099
    Resources:
    20
    Spells:
    5
    Tutorials:
    1
    JASS:
    14
    Resources:
    20
    Edited post above to provide a more in-depth answer.
    Examples: List<T> and Vector<T>.
     
  2. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    So... This works right?
    call Ht.real.remove

    That's very neat.
     
  3. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Yep, that's the beauty of it.
     
  4. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    What's the point of HashTable against Table ?

    Have a look there please :
    http://www.hiveworkshop.com/forums/lab-715/custom-wait-278948/

    There will be collisions or not in the current version ?
    Should i use TableArray instead ?
    What are the limits and is it possible to have collisions (Table, HashTable, TableArray) ?
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    This doesn't suffer any collisions. HashTables are just as powerful as normal hashtables, but avoid the 256 limit and run twice as slowly unless you cache the parent key's Table for repeated uses.

    Not sure if the link you sent me was correct as I didn't see any mention of Tables.
     
  6. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    You didn't really answer to my question, when should i use an Hashtable, a Table and a TableArray ?

    It is correct, check the second library. (requires Wait, which requires Table)
    However i had forgotten the requires.
     
  7. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    8,375
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Table: when you only need child key access.

    TableArray: when you'd normally create a Table array variable, use this instead. It can also be created so a single struct instance has a full array of Tables.

    HashTable: when you need a parent key to be larger than a TableArray size would require.
     
  8. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Sorry but i'm still confused, it seems i can use the 3 for the same thing, just with a different syntax, at least for my example.
    Ofc i could check your code, but it's a total mess (no offense) with all these textmacros and sugar vJass syntax.

    So would you be kind enough to check my code and say what's the best option please ?
     
  9. Almia

    Almia

    Joined:
    Apr 24, 2012
    Messages:
    4,842
    Resources:
    35
    Spells:
    30
    Tutorials:
    4
    JASS:
    1
    Resources:
    35
    Table is just the child key, TableArray is an allocated arrays of Tables, tho the parent key is limited. Meanwhile, HashTable exceeds the limit of TableArray (Based on what Bribe explained)
     
  10. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    Use case:
    - Table.type[child], one dimension
    - TableArray[parent].type[child], two dimension

    Have never used this HashTable tho so I donno.
     
  11. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Then why can you also use the 2d syntax with Table and Hashtable ?
     
  12. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    Because Table has this operator that returns Table.
    Code (vJASS):
    method operator [] takes integer key returns Table

    Not just 2d, you can even do any dimension with that operator. But that is really not the purpose of the operator.
    Until now, I think that operator is just the sort term of saving integer, instead of Table.integer[index] = 0, you can do Table[index] = 0 instead. But why it returns Table? That's still a mystery : P

    HashTable, as Bribe said, is the same as TableArray just with bigger parent key size. So it's normal if you can do 2d with that thing.
     
  13. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I know about the operator, what i mean is that it seems redundant.
    It's funny how my question is simple and straight to the point but not are the answers.
     
  14. EdwardElric

    EdwardElric

    Joined:
    Jun 19, 2010
    Messages:
    49
    Resources:
    0
    Resources:
    0
    Already searched a lot to find an example of how to store tables into tables. here are 2 links where Bribe himself says, that it is supported, but as always (till yet), I found no example:
    "... you can manually store nested Tables and get syntax like table[value1][value2][value3][value4][value5]"
    post #20: http://beta.roflmania.com/threads/multidimension.276330/
    "Something like set pt[this][10]['A']['G'].unit[1] = GetTriggerUnit() is now supported (obviously the example is an exaggeration)."
    post #11: http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/

    to be more specific, given following example, how would I apply it?
    Code (vJASS):

    // i need a 4D-array like this:
        // [ELEMENT][TIER][TOWER][LEVEL]=ABILITY RAWCODE
        // [    1-8][ 1-6][  1-4][  0-8]
       
        // MAX STORAGE SIZE OF Bribe's Table = 2 ^ 31 - 1
        // HOW IT WORKS:
        // all stored data from created & used table is shared among 1 hashtable from library table, hence the size 2 ^ 31 - 1
        // "You can have up to 2 ^ 31 - 1 Table instances."
        // [url]http://www.hiveworkshop.com/forums/jass-resources-412/snippet-new-table-188084/[/url]
        // "As for the length, I think it just follows the normal limit.
        //  Wc3 integers are 32-bit signed integers with a limit of 2147483647 (2^31 - 1)."
        // [url]http://www.wc3c.net/showthread.php?t=110243[/url]
       
    // init global variables:
    globals
        private Table gTab_element
        private Table gTab_tier
        private Table gTab_tower
        private Table gTab_level
    endglobals
       
    // create tables later in a function:
        set gTab_element = Table.create()
        set gTab_tier = Table.create()
        set gTab_tower = Table.create()
        set gTab_level = Table.create()
       
    // and now what?
        set gTab_element[1]=gTab_tier[1]=gTab_tower[1]=gTab_level[0] = 'SAA0'
    ???
     


    edit:
    wait, or is it simple like that?
    Code (vJASS):

    library tableMultiD initializer Init requires Table

    // init global variable:
    globals
        private Table gTab_multiD
    endglobals

    private function Init takes nothing returns nothing
    // create table:
        set gTab_multiD = Table.create()

    // store data:
        set gTab_multiD[1][1][1][0]='SAA0'
        set gTab_multiD[1][1][1][1]='SAA1'
        set gTab_multiD[1][1][1][2]='SAA2'
        //...
    endfunction

    endlibrary
     


    edit 2:
    after some more reading in 'Jasshelper' & trying to understand Bribe's script & hiveworkshop-chat with 'Almia' & 'Wietlol', I guess this isn't achievable as easy as I thought. my current imagination of how it could work, is to write 4 structs with operator overloading nested to every previous struct. but that seems quite too challenging for me...
     
    Last edited: May 9, 2016
  15. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    You were not straight to the point. Your questions (and your discussions) made me think that you don't understand why you can do TableArray syntax with Table. If you were going straight to the point, you better say that operator is a redundant from the first place, which I agree.
     
  16. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Well, read again my first questions then.
    Ok i give up until i have a clear answer.
     
  17. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    Your question, in short, was about difference of Table, TableArray, and HashTable. How is it supposed to be related to what you have just stated about redundant operator? Maybe I'm too stupid to understand.
     
  18. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Well, i don't want to begin a fight or anything like that.
    For me it was clear, but maybe it wasn't for you, ok.
    This one at least : http://www.hiveworkshop.com/forums/2823264-post288.html

    Now, i will wait for Bribe or anyone else that can explain when and why you will use HashTable, Table or TableArray.
    Anyway i'm quite sure i'm not the only one which is wondering that.
    The Bribe's example of usage in the very first post of this thread doesn't make it clear imho.
     
  19. Kazeon

    Kazeon

    Joined:
    Oct 12, 2011
    Messages:
    3,296
    Resources:
    38
    Icons:
    2
    Tools:
    1
    Maps:
    7
    Spells:
    21
    Tutorials:
    3
    JASS:
    4
    Resources:
    38
    Maybe I can help. You can use Table if you only need one dimension variable. But judging from your code, you are using 2 dimension. So you should use TableArray instead because using Table will not work (it compiles but should not work correctly). I still don't understand as well in what case I should use HashTable, neither ever used it.

    I use Table quite a lot so I know some things. But if you still want to hear the answer directly from the creator, it's fine then : P
     
  20. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,413
    Resources:
    1
    JASS:
    1
    Resources:
    1
    Oh ok, you're not supposed to use the 2d syntax with Table ?
    I thought you could with Vexorian Table's, but well i will wait for Bribe :p