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:
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.
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.