Struct or Hashtable

Ayanami

칼리
Reaction score
288
I'm currently making a custom damage system for my own use in a map. However, I can't decide if using a Struct or Hashtable is faster.

Every time a unit is damaged, I'm basically checking for any damage events (critical strike, bash, lifesteal, etc). So, I run another trigger from my damage trigger which does the damage event effects. So now, there are two ways in which I have thought of to do this.

One, use a Struct and iterate through all the instances every time the unit is damaged. Then I can compare the each instance's member "u" (a unit) to check if the "u" is the damaging unit. Then I would run the trigger. For example:

JASS:
private function iterate takes nothing returns nothing
    local thistype this = thistype(0)
    
    loop
        set this = this.next
        exitwhen this == 0
        
        if this.u == DamageSource then // DamageSource is a global unit var that will store the damage source
            call TriggerEvaluate(this.trig)
        endif
    endloop
endfunction


Two, use a Struct with a hashtable. So instead of iterating through all the instances of the struct, I make use of a hashtable to only load those instances that are associated with the damage source.

Which one would be more efficient? I'm thinking a scenario: there are 30 units in the map. Each unit has 2 damage events (a critical strike and bash). That would mean there would be a total of 60 struct instances. So by using the first method, I would need to iterate through all 60 instances every time a unit is damaged. Using the second method, I would only have to run through 2 instances every time a unit is damaged. Is looping through all instances faster than having to use hashtable? I think i read somewhere that hashtable is pretty slow.
 

dudeim

New Member
Reaction score
22
A hash table is alot slower then struct I thought like 80% (although I might be totally off with the percentage).
 

Nestharus

o-o
Reaction score
84
It depends on how many globals you have in your map, but it takes a lot of operations and globals before hashtables are faster than array reads.
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Use AIDS.
Make a linked list to the unit.
Attach the list to the unit.
When event is triggered, fire the trigger in the list that is attached to the unit.
It is the most efficient way that I can think of. :)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top