Hashtable

Status
Not open for further replies.
Level 16
Joined
Feb 22, 2006
Messages
960
you can compare it to new art of storing data.

I don't know if you use jass or gui but first you have to create a hashtable (1 is enough in most cases) then you cann store data in this hashtable for that you have the first and second key. it's in some way similar to a 2d array

JASS:
//*********
globals
     hashtable table
endglobals

function //*****
     local unit u = CreateUnit(xxx)
     set table = CreateHashtable()
     call SaveUnitHandle(table,1,1,u)
endfunction

function otherone //****
     local unit u = LoadUnitHandle(table,1,1)
endfunction
 
Level 7
Joined
Mar 8, 2009
Messages
360
or an example with handles (from timerUtils):

JASS:
    globals
        private hashtable table
    endglobals

    function SetTimerData takes timer t, integer value returns nothing
        call SaveInteger(table,0, GetHandleId(t), value)
    endfunction

    function GetTimerData takes timer t returns integer
        return LoadInteger(table, 0, GetHandleId(t))
    endfunction

although i don't know why you should need two integer keys

EDIT: you also have to initialise a hashtable:
JASS:
set table = InitHashtable()
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Table is like an array except that it can use handles or strings as indices.

For example:
JASS:
// Normal arrays
local integer array table
local integer i = 4
set table[4] = 25
JASS:
// HandleTables:
local HandleTable table = HandleTable.create()
local unit u = CreateUnit(...)
set table[u] = 25
// u is used as index. It's a way to link a number to a handle, in this case linking a number to a unit.
 
Level 9
Joined
Mar 27, 2009
Messages
309
So... how much more efficient if this really?... than say... storing 304 integer variables in a single array [For current project]

I have a few arrays... So i could store them both in one hashtableh?

(yes it's a tableh :D Wacom ftw, Southpark ftw... ok im done)
 
So... how much more efficient if this really?... than say... storing 304 integer variables in a single array [For current project]

I have a few arrays... So i could store them both in one hashtableh?

(yes it's a tableh :D Wacom ftw, Southpark ftw... ok im done)
Hashtables are no more efficient than arrays - in fact they're about 2 times slower due to taking two indeces. The advantage with hashtables is their infinite index size, so you can "attach" data to units, timers, etc, by using their "handle id" as an index.
 
Status
Not open for further replies.
Top