• 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.

[JASS] hashtable question

Status
Not open for further replies.
It is possible, but not inherently. You have to keep track of all the values you use. I would do it in a linked list.

JASS:
struct Example
    private thistype next
    private thistype prev
    
    private integer parentKey

    method destroy takes nothing returns nothing
        set this.next.prev = this.prev // remove the node from the list
        set this.prev.next = this.next

        call this.deallocate() 
    endmethod

    static method loopThrough takes nothing returns nothing
        // this will demonstrate how to loop through the parent Keys
        local thistype node = thistype(0).next
        loop
            exitwhen node == 0
            call SaveUnitHandle(someHashTable, this.parentKey, 0, GetTriggerUnit())
            // saves the trigger unit under each parent key
            set node = node.next
        endloop
    endmethod

    static method create takes unit u returns thistype
        local thistype this = thistype.allocate()

        set this.next = thistype(0).next // enter the node in the list
        set this.prev = thistype(0)
        set this.next.prev = this
        set thistype(0).next = this

        set this.parentKey = GetHandleId(u) // set the parent key to whatever
                                                          // just an example
        return this
    endmethod
endstruct

Of course, this doesn't really have any practical use. However, it shows how to make a list of the instances and loop through the parent keys.
 
Status
Not open for further replies.
Top