[JASS] [Hashtables] Checking if there are any child keys bound to a parent keys

Status
Not open for further replies.

Oli

Oli

Level 3
Joined
Aug 9, 2015
Messages
33
Hi,
My question is short and simple, but unintuitive to answer by myself.
I wish to check if there are any keys bound to a parent key. Is it possible? If so, then how?
 
Hello.
It's possible, though you'll have to do all of the implementation yourself.

The idea behind the implementation is as follows:

1.) Create a meta hashtable that stores the number of entries within a parent key of a given hashtable.

2.) Write an unwieldy amount of wrapper functions that tell the meta hashtable when a value has been assigned to another hashtable with the specified parent and child keys.

Such an implementation would look like this (in vJASS)

JASS:
library Metatable

globals
    private hashtable metatable = InitHashtable()
endglobals

//! textmacro META_SET takes FUNCNAME, NATIVE, TYPE, ENTRYCHECK
function $FUNCNAME$ takes hashtable hash, integer parentKey, integer childKey, $TYPE$ value returns nothing
    if (not $ENTRYCHECK$(hash, parentKey, childKey)) then
        call SaveInteger(metatable, GetHandleId(hash), parentKey, LoadInteger(metatable, GetHandleId(hash), parentKey) + 1)
    endif
endfunction
//! endtextmacro

// Repeat this for the number of hashtable setter natives
//! runtextmacro META_SET("SaveIntegerEx", "SaveInteger", "integer", "HaveSavedInteger")
...

function FlushChildHashtableEx takes hashtable hash, integer parentKey returns nothing
    call RemoveSavedInteger(metatable, hash, parentKey)
    call FlushChildHashtable(hash, parentKey)
endfunction

endlibrary
 
Status
Not open for further replies.
Top