[JASS] JASS Hashtable Remove Hash Key Question

Level 5
Joined
Mar 18, 2023
Messages
52
For Hashtables in JASS, I know that we can use flushchildHashtable function to set saved booleans to false and remove the hash key. I was wondering if RemoveSavedBoolean also sets the saved boolean to false and removes the hash key too. Or does RemoveSavedBoolean only set it to false but the hash key still remains there in the hashtable.
 
Level 5
Joined
Mar 18, 2023
Messages
52
RemoveSavedBoolean removes the value from the parent-child key pair in a hashtable. By invoking the function above, the stored value in the hash key (child) is flushed and the default result (false) is returned by LoadBoolean afterwards.
When you mean by "the stored value in the hash key (child) is flushed" do you mean that the index of the hashtable is flushed. What I mean is if the index of the hashtable is flushed, then you would be able to recycle to same index that was just flushed. I know flushchildhashtable does this but I just want to verify if RemovedSavedBoolean also does the same thing.
 
Before answering that, it would be helpful to think of hash tables in JASS as 2D-arrays.

So, for our hashtable (let's call it hash), we can essentially think of it like this:
Code:
hash = []  // Forgive the 1D-array syntax; assume it is a 2D-array.

When we call SaveX (note that SaveX is a placeholder for multiple functions following the same pattern) with our hashtable and a parent-child key pair, this is analogous to the following:
Code:
hash[parentKey][childKey] = value

Similarly, calling RemoveSavedX is analogous to the following:
Code:
del hash[parentKey][childKey];

What RemoveSavedX does is remove the stored value at that given parent-child key pair.
At that point, there is no stored value in that given parent-child key pair within the hashtable, so when we want
to look up the value at that parent-child key pair (which is not defined), we need to have a fallback value.

Code:
print(hash[parentKey][childKey]) // Prints 0, false or null depending on what LoadX (placeholder for all of its variants) function is used.

With that in mind, we can proceed with the following example:
Code:
hash = []
hash[parentKey][childKey] = value1
hash[parentKey][childKey2] = value2
hash[parentKey][childKey3] = value3

// We now have 3 values stored at the given parent key of our hashtable.
del hash[parentKey][childKey]  // Calling RemoveSavedX here.

// We now have 2 values stored at the given parent key of our hashtable.
print(hash[parentKey][childKey]) // Will return default value.
print(hash[parentKey][childKey2]) // value2
print(hash[parentKey][childKey3]) // value3

Now, if we call FlushChildHashtable on our given hashtable using our parent key, this will flush all of the child keys in that parent key, which is analogous to the following:
Code:
// Based on the above example, we still have 2 values.

del hash[parentKey]
// This is equivalent to the following (under the hood):
// del hash[parentKey][childKey2]
// del hash[parentKey][childKey3]

// At this point, we no longer have any values stored at the given parent key.
print(hash[parentKey][childKey2]) // Will return default value.
print(hash[parentKey][childKey3]) // Will return default value.

With that said, there should be no problems reusing the same parent key after flushing all of its children keys down the drain (with Child Protection Service's Acknowledgment, of course).
 
Top