• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Trigger condition and StringHash function

Status
Not open for further replies.
Level 4
Joined
May 14, 2018
Messages
34
Hello guys!
I`m still making some cool(Actually not) stuff, and i got few questions

1. There is any difference between using condition for trigger and If/Then/Else in Jass trigger.
I mean there is any difference in speed or there is any leaks if i`ll use conditions? Or there is no difference at all?

2. There is any possibility that using StringHash() as child key with same Parent key may lead to overwites of already existing data for this Parent key?


Thank in advance for answers
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
Since you asked if simply using a triggercondition would create a leak, you clearly do not understand what a leak actually is or why they happen. I suggest you review these threads to understand why that question is pretty silly:
https://www.hiveworkshop.com/threads/things-that-leak.35124/
https://www.hiveworkshop.com/threads/memory-leaks.263410/

The difference is that a trigger that fails its conditions step never gets past the TriggerEvaluate() call that checks them, thus saving the overhead of the trigger actually 'happening'. In most situations it is a minor performance gain to have triggers fail at conditions rather than in an if-block that starts the actions, but if your trigger fires many times per second then it's likely to be a more significant performance gain that you might care about. In a way a TriggerCondition is 'faster' to evaluate than an If-block but that difference likely never matters.

If you can use conditions, you probably should. For simple stuff that doesn't run very frequently at all or has small overhead to begin with you can just use a TriggerAction with an If-block. If you were using GUI, some things are not available from the conditions menu in GUI so in that case you must instead use an If-block of your own design. But you're not.
2. There is any possibility that using StringHash() as child key with same Parent key may lead to overwites of already existing data for this Parent key?
StringHash should be a 1:1 function so there will be no collisions as long as you don't literally reuse the (parent, child) combo. You are doing something like this, right? call SaveHashtableStuff(ParentKey, StringHash(I2S(ParentKey)), somedatayoustore)
 
Level 4
Joined
May 14, 2018
Messages
34
Since you asked if simply using a triggercondition would create a leak, you clearly do not understand what a leak actually is or why they happen. I suggest you review these threads to understand why that question is pretty silly:
https://www.hiveworkshop.com/threads/things-that-leak.35124/
https://www.hiveworkshop.com/threads/memory-leaks.263410/

The difference is that a trigger that fails its conditions step never gets past the TriggerEvaluate() call that checks them, thus saving the overhead of the trigger actually 'happening'. In most situations it is a minor performance gain to have triggers fail at conditions rather than in an if-block that starts the actions, but if your trigger fires many times per second then it's likely to be a more significant performance gain that you might care about. In a way a TriggerCondition is 'faster' to evaluate than an If-block but that difference likely never matters.

If you can use conditions, you probably should. For simple stuff that doesn't run very frequently at all or has small overhead to begin with you can just use a TriggerAction with an If-block. If you were using GUI, some things are not available from the conditions menu in GUI so in that case you must instead use an If-block of your own design. But you're not.

StringHash should be a 1:1 function so there will be no collisions as long as you don't literally reuse the (parent, child) combo. You are doing something like this, right? call SaveHashtableStuff(ParentKey, StringHash(I2S(ParentKey)), somedatayoustore)

Thank you for answer,
Actually i know a lot about leaks, but i just was wondering - is there any trick about ITE/Condition that i don`t know.
I just didn`t find any information about it, so i decided to ask
And i was wondering, there is any difference in performance beetwen COndition and ITE in Jass triggers at all


About StringHash - I just wanted to know, if there is any possibility for combination like this:
call SaveHashtableStuff(StringHash("Some Parent string"), StringHash("Some Child string"), somedatayoustore)
can be overwrited by another pair of StringHash Parent/Child combination except of the same one.

This isn`t a critical questions for me, but i just want to know this things better if i`m using them now
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
You can swap the child/parent keys to get a second unique address for the same combination (with implications rergarding properly flushing), but aside from that no the only way to get a collision is literally using the exact same two input strings to StringHash. Multiple hashtables can of course store different data under that same combination of two keys.
 
Status
Not open for further replies.
Top