• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Hashtable clearing questions

Status
Not open for further replies.
Level 12
Joined
Jan 2, 2016
Messages
973
Okay, there are few functions:
JASS:
native  RemoveSavedInteger                    takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedReal                        takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedBoolean                    takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedString                    takes hashtable table, integer parentKey, integer childKey returns nothing
native  RemoveSavedHandle                    takes hashtable table, integer parentKey, integer childKey returns nothing
that aparently clear fields of a hashtable.
If I do:
JASS:
call SaveInteger(udg_Table, 0, 0, 1)
call RemoveSavedInteger(udg_Table, 0, 0)
will it be the same as when I do:
JASS:
call SaveInteger(udg_Table, 0, 0, 1)
call FlushChildHashtable(udg_Table, 0)
(If I didn't have any other things saved in the hashtable)
Or will it be less effective?

The answer to this question will determine how will I be cleaning 1 of my hashtables from here on.
Tho, I have 1 more question:
If I have 5 values saved in a child hashtable, will it be faster if I used "ClearChildHashtable" or it wouldn't matter if I use 5 times "RemoveSavedInteger"?

I'm kind a asking this, because I have a hashtable, that uses units' Handles, and until now I was keeping track how many triggers are using this unit's table at the moment, and when they become 0 - I was clearing it.
But now I can clear only the fields that I don't need, so I wouldn't need to track how many triggers are using it, so things become much simpler - I just remove the values the expired trigger needed.

So I'm just wondering if this will have any impact on the performance.
 
Level 12
Joined
Jan 2, 2016
Messages
973
You don't do that. You use Flushhashtable() at least I have not seen an exception for this yet.

Well, imagine my situation:
I have 2 triggers that use the units' handle ids.
If both of the triggers are used on the same unit, at the same time. When 1 of them ends, if I flush the whole child hashtable - the other trigger will start malfunctioning.
That's why I want to clear only the fields each trigger uses.
I don't wanna create a seperate hashtable for every trigger that uses the unit's handle id.

Before I figured that it can be done in the said way (With RemoveSaved$VALUE$) - I was doing it another way:
JASS:
set i = LoadInteger(udg_Unit_Table, id, 0)
if i == 1 then
call FlushChildHashtable(udg_Unit_Table, id)
else
call SaveInteger(udg_Unit_Table, id, 0, i-1)
endif

// and I was increasing the integer when another trigger begins using the hashtable

call SaveInteger(udg_Unit_Table, id, 0, 1 + LoadInteger(udg_Unit_Table, id, 0))
But this way seems more inconvenient to me, since if a lot of triggers use it - it may take a lot of time till it gets flushed, and a lot of its fields will take up memory.
 
Flushing is very fast. I think WaterKnight tested that it ran well even on millions of entries.

You shouldn't worry about performance in this case. Use whatever makes sense in the problem. If you only want to remove N elements from the hashtable, you can remove them individually. If you want to remove all elements under some shared parent ID, then use FlushChildHashtable(...).

However, FlushChildHashtable(...) is typically convenient and it is very fast. Sometimes you may want adjust the way you store things so that it is easy to clear later on. This may involve rearranging your keys or choosing keys specifically for your problem.
 
Status
Not open for further replies.
Top