| 06-12-2009, 12:16 PM | #1 |
The code speaks for itself: JASS:globals integer table Tab unit table UTab SomeStruct table STab endglobals function Test takes unit u returns nothing local unit u2 set Tab[3][5] = 7 set UTab[9][2] = u set u2 = UTab[9][2] set STab[GetHandleId(u)][11] = SomeStruct.create() call STab[GetHandleId(u)][11].destroy() endfunction Compiles into: JASS:globals hashtable Tab = InitHashtable() hashtable UTab = InitHashtable() hashtable STab = InitHashtable() endglobals function Test takes unit u returns nothing local unit u2 call SaveInteger(Tab, 3, 5, 7) call SaveUnit(UTab, 9, 2, u) set u2 = LoadUnit(UTab, 9, 2) call SaveInteger(STab, GetHandleId(u), 11, s__SomeStruct__allocate()) call s__SomeStruct_destroy(LoadInteger(STab, GetHandleId(u), 11)) endfunction You can even do this: JASS:globals agent table ATab endglobals function Test takes unit u returns nothing local widget w local unit u2 set ATab[9][12] = u set w = ATab[9][12] set u2 = ATab[9][12] endfunction Compiles to: JASS:globals hashtable ATab = InitHashtable() endglobals function Test takes unit u returns nothing local widget w local unit u2 call SaveAgent(ATab, 9, 12, u) set w = LoadAgent(ATab, 9, 12) set u2 = LoadAgent(ATab, 9, 12) endfunction For flushing, no special syntax is needed, just make the tables recognized as valid hashtables. JASS:globals integer table Tab endglobals function Test takes nothing returns nothing call FlushParentHashTable(Tab) call FlushChildHashTable(Tab, 5) endfunction I don't think I need to explain why this is awesome, just hurry up and do it. |
| 06-12-2009, 01:01 PM | #2 |
meh JASS:
integer hashtable tab
I like it better. -- I think Table does this just fine. hashtables can be more powerful than just 2D arrays , if I do something in vJass with them it would have to use their whole power... |
| 06-12-2009, 01:10 PM | #3 |
we dont know yet how massive hashtable usage affects the performance, we should wait until we know more about them, before we implement stuff like that. |
| 06-12-2009, 01:16 PM | #4 |
We know it is better than gamecache which doesn't really slows down that much after massive usage. |
| 06-12-2009, 01:24 PM | #5 | |
Quote:
do we ? Havent seen ANY benchmark yet. |
| 06-12-2009, 01:29 PM | #6 |
Do them? |
| 06-12-2009, 02:04 PM | #7 | |
Quote:
The problem with Table is that there is no need to use it anymore. It's just an extra requirement for a prettier syntax (not even shorter code) within systems and no other benefit. Table was previously used for everything before because it provided the needed function of consolidating everything into one gamecache. What can you do with hashtables that you can't do with the syntax posted? It does use their whole power. The only thing it lacks compared to table is automatically using GetHandleId, StringHash, etc, but that's pretty trivial. If you think it is important you could this like: JASS:integer hashtable UTab[handle][integer] Hashtables are essentially 2d arrays without limits, the syntax should provide the ability to use them as such without every library in the world requiring Table and running a bunch of templated copies of it. |
| 06-12-2009, 02:22 PM | #8 |
Gay limits again and again. Add SaveHashtableHandle - have unlimited profit on natives level (also unlimited arrays, since you can attach array to array with unlimited depth, cross attach, linkes, shotcuts, with such stable and safe native you can build "file system" and store all data like "files") |
| 06-12-2009, 02:25 PM | #9 |
DioD, they are adding SaveHashtableHandle, that means these could compile to be not just 2d arrays but also 3d/4d/etc arrays... They could also act as 1d arrays by ignoring the child key. Thus: JASS:integer hashtable MyHash[handle] //1d array, attach a struct to a unit... integer hashtable MyHash[handle][integer] //2d array, attach a list of structs to a unit... integer hashtable MyHash[handle][integer][string] //3d array... integer hashtable MyHash[handle][integer][string][integer] //4d array etc I don't think anything other than 2d hashtables are important, the rest can be ignored if they turn out to be annoying to compile. |
| 06-13-2009, 02:48 AM | #10 |
In case anyone was wondering... JASS:globals integer hashtable HT unit hashtable UHT endglobals function test takes unit u returns nothing set HT[1][2] = 6 set UHT[3][4] = u endfunction Stuff like this will probably get added, the other un-needed ideas in this thread probably not. However, if anyone can come up with a good syntax for specifying the index types that feature might get added too. Listing some possibilities: JASS:globals integer hashtable HT[handle][integer] //vex doesn't like integer hashtable HT<handle, integer> //too similar to future template syntax? integer hashtable HT[handle, integer] integer hashtable HT(handle, integer) //don't know what else but it should probably look similar to one of these endglobals |
