• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

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

Status
Not open for further replies.
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.
Back
Top