A global hashtable? o.O

the Immortal

I know, I know...
Reaction score
51
Ynow, after we (in fact 'you') had that discussion about a global GROUP, isn't it time for a global hashtable, lols? =P

No, apart from the jokes, there are many spells where only one row (column) of the hashtable is needed. Should I post some links? Though am sure everyone can find. So instead of making the user paste some indexing/attaching system (be it unit, trigger, timer or w/e.. plus you can -always- make it optional) or needlessly create tens of hashtables only to use a single key or two of them, why isn't something as simple as that implemented?:
JASS:

library_once HASH
    globals
        hashtable HASH    //damn silly name, but we have 'GROUP' so diaf!
    endglobals
endlibrary


And when you want to use it, just create a public key and.. voilà?

So this
JASS:

scope SomeSpell
    globals
        hashtable ht
    endglobals

    function onCast takes nothing returns nothing
        local data d = LoadInteger(ht, 0, GetHandleId(GetTriggerUnit()))
        ...
    endfunction
    
    ...

endscope

becomes this:
JASS:
library_once HASH
    globals
        hashtable HASH    //damn silly name, but we have 'GROUP' ?
    endglobals
endlibrary
scope SomeSpell requires HASH
    globals
        public key UNITID_ROW     //another silly name, out of ideas today
    endglobals

    function onCast takes nothing returns nothing
        local data d = LoadInteger(HASH, UNITID_ROW, GetHandleId(GetTriggerUnit()))
        ...
    endfunction

    ...

endscope



Actually for me it doesn't matter if I have 1000 hashtables or only one, as the speed difference should be.. negligible. But since it seems to be a problem, I am putting it here for discussing.. without much hopes to accomplish anything btw =D

Nothing's wrong with unit indexing / attaching, of course.. but I hate having to paste a whole system only for a single spell to work. As, I think, most of the time happens.
Make these optional, use hashtables. Or better - use a single hashtable.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Unit indexing systems are a must have, if you ask me. Hashtables are fast, but arrayed globals and getting UnitUserData is still like 80% faster.
And if that doesn't matter to you, then indexed global arrays are still better, because they save lines of code.

Besides, it's absolutely no problem to import indexing systems, as they do not require manual setup. They work completely automaticly (at least the popular ones).

If you "have to import" an indexing system "just for one spell", where is the problem with that? Modularity is a pro, not a con. And maybe some day you will want this other spell that uses indexing too.

Of all systems you can import into your map, indexing systems are possibly the most vital.
 

weaaddar

New Member
Reaction score
6
A lot of people use the Table library to do exactly what you are talking about.

Also eventually, Vex will translate large dynamic arrays to hashtable so you probably can just do something like "integer array Table[9000,81000]" and have native built in table.


And you really don't need an indexing system they aren't a mega speed increase, its about twice as fast to use GetUserData then Hashtable natives that is true.
 

the Immortal

I know, I know...
Reaction score
51
> Unit indexing systems are a must have, if you ask me.
Sure, but when for a simple bash snippet, I have to attach to units, triggers, and timers, (or instead of trigger-attaching use a damage detection system) why should I import 3 systems instead of use 1 hashtable row and 'suffer' + 0.0001ms execution time?

> Of all systems you can import into your map, indexing systems are possibly the most vital.
They would be 'vital' if it wasn't possible to do exactly the same things without them. (excluding unit-structs as this is completely another question..)

> A lot of people use the Table library to do exactly what you are talking about.
Wasn't aware of its existence. Will look into it later.


And, okay, let me rephrase my question:
If I simply want to attach data to handles, why should I import 2, 3, or more systems, instead of use a hashtable in the form of that little snippet? For efficiency?
ArrayGet[UnitId()] execution time is neglectfully small. HashtableGet is less than twice slower than it. No good code should call these more than once / run. And even at 32 times / second the performance loss is still equal to zero, given it's 2k9 and we are running a game from 2k3 or so.

Yes, there might be exceptions in the form of gigantic maps-o-systems. But for at least 95% of the time.. it wouldn't matter at all.

Please correct me if I see these things wrong.

Best regards,
Ix
 

weaaddar

New Member
Reaction score
6
Yeah table is pretty much one of the best utility libraries I can suggest. It's a clean wrapper around the native's and so it all inline. It also gives you array notation.

So you use it like::
JASS:

HandleTable myTable = HandleTable.create();
myTable[someUnitVar] = someStruct;
if(myTable.exists(someOtherUnit))
{
    someValue = myTable[someOtherUnit];
}
myTable.flush();
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top