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

[Std Collections] Collections

Collections are more or less implemented the exact same way. I'm pretty much tired of writing them, so I am putting them all into a Standard Collections thread. This will not have more complicated collections like Splay Trees, AVL Trees, B-Trees, B+Trees, Red-Black Trees, and so forth because they are more complicated than the basic standard collections and they should go into their own threads.


Collection Index


Back To Collection Index

JASS:
library CircularLinkedList /* v1.0.0.0
*************************************************************************************
*
*   Sentinel: list
*
*   Faster add/removal than linked list
*   Less memory usage than linked list
*   Slower iteration than linked list
*
*       local Node3 node = list
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == list
*           set data = node.data
*
*           //code
*       endloop
*
*       local Node3 node = list
*       local integer sentinel = list.sentinel
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == sentinel
*           set data = node.data
*
*           //code
*       endloop
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ ListHead /*
*       */ Node2 /*
*
************************************************************************************
*
*   struct CircularLinkedList implements ListHead
*
*       method init takes nothing returns nothing
*           -   initialize (after a clear)
*
*       static method create takes nothing returns thistype
*           -   list = CircularLinkedList.create()
*
*       method push takes Pointer data returns nothing
*           -   list.push(data)
*       method enqueue takes Pointer data returns nothing
*           -   list.enqueue(data)
*
*       method remove takes Pointer data returns boolean
*           -   list.remove(data)
*       method delete takes nothing returns nothing
*           -   node.delete()
*
************************************************************************************/
    struct CircularLinkedList extends array
        implement ListHeadProperties
        
        method init takes nothing returns nothing
            set first = this
            set last = this
        endmethod
        
        static method create takes nothing returns thistype
            local thistype this = ListHead.allocate()
            
            call init()
            
            return this
        endmethod
        
        method push takes Pointer data returns nothing
            local Node2 node = Node2.allocate()
            
            set node.next = first
            set node.prev = this
            set first.prev = node
            set first = node
            
            set node.data = data
        endmethod
        
        method enqueue takes Pointer data returns nothing
            local Node2 node = Node2.allocate()
            
            set node.prev = last
            set node.next = this
            set last.next = node
            set last = node
            
            set node.data = data
        endmethod
        
        method delete takes nothing returns nothing
            set Node2(this).next.prev = Node2(this).prev
            set Node2(this).prev.next = Node2(this).next
            
            call Pointer(this).deallocate()
        endmethod
        
        method remove takes Pointer data returns boolean
            local Node2 node = first
            
            loop
                exitwhen node == this or node.data == data
                set node = node.next
            endloop
            
            if (node.data == data) then
                call Pointer(node).deallocate()
                return true
            endif
            
            return false
        endmethod
    endstruct
endlibrary



Back To Collection Index

JASS:
library LinkedList /* v1.0.0.0
*************************************************************************************
*
*   Linked list with the pointer of the list acting as the sentinel node.
*
*   Slower add/removal than circular linked list
*   More memory usage than circular linked list
*   Faster iteration than circular linked list
*
*       local Node3 node = list
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == 0
*           set data = node.data
*
*           //code
*       endloop
*
*       local Node3 node = list
*       local integer sentinel = list.sentinel
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == sentinel
*           set data = node.data
*
*           //code
*       endloop
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ ListHead /*
*       */ Node3 /*
*
************************************************************************************
*
*   struct LinkedList implements ListHead
*
*       method init takes nothing returns nothing
*           -   initialize (after a clear)
*
*       static method create takes nothing returns thistype
*           -   list = LinkedList.create()
*
*       method push takes Pointer data returns nothing
*           -   list.push(data)
*       method enqueue takes Pointer data returns nothing
*           -   list.enqueue(data)
*
*       method remove takes Pointer data returns boolean
*           -   list.remove(data)
*       method delete takes nothing returns nothing
*           -   node.delete()
*
************************************************************************************/
    struct LinkedList extends array
        implement ListHeadProperties
        
        method init takes nothing returns nothing
            set first = 0
            set last = 0
        endmethod
        static method create takes nothing returns thistype
            local thistype this = ListHead.allocate()
            
            call init()
            
            return this
        endmethod
        
        method push takes Pointer data returns nothing
            local Node3 node = Node3.allocate()
            
            set node.next = first
            set node.prev = 0
            
            if (0 == first) then
                set last = node
            else
                set first.prev = node
            endif
            set first = node
            
            set node.head = this
            set node.data = data
        endmethod
        
        method enqueue takes Pointer data returns nothing
            local Node3 node = Node3.allocate()
            
            set node.next = 0
            set node.prev = last
            
            if (0 == last) then
                set first = node
            else
                set last.next = node
            endif
            set last = node
            
            set node.head = this
            set node.data = data
        endmethod
        
        method delete takes nothing returns nothing
            local Node3 node = this
            set this = node.head
            
            if (0 == node.next) then
                set last = node.prev
            else
                set node.next.prev = node.prev
            endif
            if (0 == node.prev) then
                set first = node.next
            else
                set node.prev.next = node.next
            endif
            
            call Pointer(node).deallocate()
        endmethod
        
        method remove takes Pointer data returns boolean
            loop
                set this = Node3(this).next
                exitwhen 0 == this or Node3(this).data == data
            endloop
            
            if (0 != this) then
                call delete()
                return true
            endif
            
            return false
        endmethod
    endstruct
endlibrary



Back To Collection Index

JASS:
/*
*   when instancing is needed
*/
module Stack
    readonly thistype next
    
    method push takes thistype node returns nothing
        set node.next = next
        set next = node
    endmethod
    method pop takes nothing returns thistype
        local thistype node = next
        set next = node.next
        return node
    endmethod
    method clear takes nothing returns nothing
        set next = 0
    endmethod
endmodule



Back To Collection Index

JASS:
/*
*   when using values between 1 and 8191 and instancing is not needed
*/
module StaticStack
    readonly thistype next
    
    static method push takes thistype node returns nothing
        set node.next = thistype(0).next
        set thistype(0).next = node
    endmethod
    static method pop takes nothing returns thistype
        local thistype node = thistype(0).next
        set thistype(0).next = node.next
        return node
    endmethod
    static method clear takes nothing returns nothing
        set thistype(0).next = 0
    endmethod
endmodule



Back To Collection Index

JASS:
/*
*   when using non integers or values not between 1 and 8191 and instancing
*   is not needed
*/
module ArrayStack
    readonly static integer size = 0
    
    static method push takes nothing returns thistype
        set size = size + 1
        return size
    endmethod
    static method pop takes nothing returns thistype
        set size = size - 1
        return size + 1
    endmethod
    static method clear takes nothing returns nothing
        set size = 0
    endmethod
endmodule



Back To Collection Index

JASS:
module Queue
    readonly thistype last
    readonly thistype next
    
    method enqueue takes thistype node returns nothing
        set last.next = node
        set last = node
        set node.next = 0
    endmethod
    method pop takes nothing returns thistype
        local thistype node = next
        set next = node.next
        if (0 == next) then
            set last = this
        endif
        return node
    endmethod
    method clear takes nothing returns nothing
        set next = 0
        set last = this
    endmethod
endmodule



Back To Collection Index

JASS:
module StaticQueue
    readonly static thistype last = 0
    readonly thistype next
    
    static method operator head takes nothing returns thistype
        return 0
    endmethod
    
    static method enqueue takes thistype node returns nothing
        set last.next = node
        set last = node
        set node.next = 0
    endmethod
    static method pop takes nothing returns thistype
        local thistype node = thistype(0).next
        set thistype(0).next = node.next
        if (0 == thistype(0).next) then
            set last = 0
        endif
        return node
    endmethod
    static method clear takes nothing returns nothing
        set thistype(0).next = 0
        set last = 0
    endmethod
endmodule



Back To Collection Index

JASS:
module ArrayQueue
    readonly static thistype first = 0
    readonly static thistype last = 0
    
    static method enqueue takes nothing returns thistype
        set last = last + 1
        if (8192 == last) then
            set last = 1
        endif
        return last
    endmethod
    static method pop takes nothing returns thistype
        set first = first + 1
        if (8192 == first) then
            set first = 1
        endif
        return first
    endmethod
    static method clear takes nothing returns nothing
        set first = 0
        set last = 0
    endmethod
endmodule



Back To Collection Index

JASS:
/*
*   Faster iteration
*   More memory
*   Slower add/remove
*/
module List
    thistype head
    thistype next
    thistype prev
    
    method enqueue takes thistype node returns nothing
        set node.next = 0
        set node.prev = prev
        
        if (0 == prev) then
            set next = node
        else
            set prev.next = node
        endif
        set prev = node
        
        set node.head = this
    endmethod
    method push takes thistype node returns nothing
        set node.prev = 0
        set node.next = next
        
        if (0 == next) then
            set prev = node
        else
            set next.prev = node
        endif
        set next = node
        
        set node.head = this
    endmethod
    method remove takes nothing returns nothing
        if (0 == prev) then
            set head.next = next
        else
            set prev.next = next
        endif
        if (0 == next) then
            set head.prev = prev
        else
            set next.prev = prev
        endif
    endmethod
    method clear takes nothing returns nothing
        set head = this
        set next = 0
        set prev = 0
    endmethod
endmodule



Back To Collection Index

JASS:
/*
*   Slower iteration
*   Less memory
*   Faster add/remove
*/
module CircularList
    //not readonly for possible sorting
    thistype next
    thistype prev
    
    method enqueue takes thistype node returns nothing
        set node.next = this
        set node.prev = prev
        set prev.next = node
        set prev = node
    endmethod
    method push takes thistype node returns nothing
        set node.next = next
        set node.prev = this
        set next.prev = node
        set next = node
    endmethod
    method remove takes nothing returns nothing
        set prev.next = next
        set next.prev = prev
    endmethod
    method clear takes nothing returns nothing
        set next = this
        set prev = this
    endmethod
endmodule



Back To Collection Index

JASS:
/*
*   when a value needs to be removed from anywhere in list and instancing
*   is not needed. This has efficiency benefits of both List and CircularList.
*/
module StaticList
    //not readonly for possible sorting
    thistype next
    thistype prev
    
    static method operator head takes nothing returns thistype
        return 0
    endmethod
    
    static method enqueue takes thistype node returns nothing
        set node.next = thistype(0)
        set node.prev = thistype(0).prev
        set thistype(0).prev.next = node
        set thistype(0).prev = node
    endmethod
    static method push takes thistype node returns nothing
        set node.next = thistype(0).next
        set node.prev = thistype(0)
        set thistype(0).next.prev = node
        set thistype(0).next = node
    endmethod
    method remove takes nothing returns nothing
        set prev.next = next
        set next.prev = prev
    endmethod
    static method clear takes nothing returns nothing
        set thistype(0).next = 0
        set thistype(0).prev = 0
    endmethod
endmodule



Back To Collection Index

JASS:
//empty



Back To Collection Index

JASS:
//empty



Back To Collection Index

JASS:
library Stack /* v1.0.0.0
*************************************************************************************
*
*   Sentinel: 0
*
*   Faster add/removal than queue
*   Less memory usage than queue
*   Faster iteration than circular linked list
*
*       local Node1 node = stack
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == 0
*           set data = node.data
*
*           //code
*       endloop
*
*       local Node1 node = stack
*       local integer sentinel = stack.sentinel
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == sentinel
*           set data = node.data
*
*           //code
*       endloop
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node1 /*
*       */ StackHead /*
*
************************************************************************************
*
*   struct Stack implements StackHead
*
*       method init takes nothing returns nothing
*           -   initialize (after a clear)
*
*       static method create takes nothing returns thistype
*           -   stack = Stack.create()
*
*       method push takes Pointer data returns nothing
*           -   stack.enqueue(data)
*       method pop takes nothing returns Pointer
*           -   stack.pop()
*
************************************************************************************/
    struct Stack extends array
        implement StackHeadProperties
        
        method init takes nothing returns nothing
            set first = 0
            set sentinel = 0
        endmethod
        
        static method create takes nothing returns thistype
            local thistype this = StackHead.allocate()
            
            call init()
            
            return this
        endmethod
        
        method push takes Pointer data returns nothing
            local Node1 node = Node1.allocate()
            
            set node.next = first
            set first = node
            
            set node.data = data
        endmethod
        
        method pop takes nothing returns Pointer
            local Node1 node = first
            
            if (0 == node) then
                return 0
            endif
            
            set first = node.next
            
            call Pointer(node).deallocate()
            
            return node.data
        endmethod
    endstruct
endlibrary



Back To Collection Index

JASS:
library Queue /* v1.0.0.0
*************************************************************************************
*
*   Sentinel Node: 0
*
*   Faster add/removal than linked list
*   Less memory usage than linked list
*   Faster iteration than circular linked list
*
*       local Node1 node = queue
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == 0
*           set data = node.data
*
*           //code
*       endloop
*
*       local Node1 node = queue
*       local integer sentinel = queue.sentinel
*       local Pointer data
*       loop
*           set node = node.next
*           exitwhen node == sentinel
*           set data = node.data
*
*           //code
*       endloop
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ QueueHead /*
*       */ Node1 /*
*
************************************************************************************
*
*   struct Queue implements QueueHead
*
*       method init takes nothing returns nothing
*           -   initialize (after a clear)
*
*       static method create takes nothing returns thistype
*           -   queue = Queue.create()
*
*       method enqueue takes Pointer data returns nothing
*           -   queue.enqueue(data)
*       method pop takes nothing returns Pointer
*           -   queue.pop()
*
************************************************************************************/
    struct Queue extends array
        implement QueueHeadProperties
        
        method init takes nothing returns nothing
            set first = 0
            set last = this
        endmethod
        
        static method create takes nothing returns thistype
            local thistype this = QueueHead.allocate()
            
            set first = 0
            set last = this
            
            return this
        endmethod
        
        method enqueue takes Pointer data returns nothing
            local Node1 node = Node1.allocate()
            
            set last.next = node
            set last = node
            set node.next = 0
            
            set node.data = data
        endmethod
        
        method pop takes nothing returns Pointer
            local Node1 node = first
            
            if (0 == node) then
                return 0
            endif
            
            set first = node.next
            if (0 == first) then
                set last = this
            endif
            
            call Pointer(node).deallocate()
            
            return node.data
        endmethod
    endstruct
endlibrary



Back To Collection Index

JASS:
//empty



Back To Collection Index

JASS:
//empty



Back To Collection Index

JASS:
library Vector /* v1.0.0.0
*************************************************************************************
*
*   A Dynamically Sizing Array
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*
************************************************************************************
*
*   struct Vector extends array
*       readonly IntegerPointer arrayObject
*           -   useful for sorting, pass the arrayObject instead of the vector.
*
*       integer size
*
*       method operator [] takes integer index returns Pointer
*       method operator []= takes integer index, Pointer data returns nothing
*
*       static method create takes nothing returns Vector
*       method destroy takes nothing returns nothing
*
*       method find takes integer startIndex, Pointer data returns integer
*           -   -1 means not found
*       method count takes Pointer data returns integer
*           -   0 means not in vector
*
************************************************************************************/
    struct Vector extends array
        method operator arrayObject takes nothing returns IntegerPointer
            return IntegerPointer(this)[0]
        endmethod
    
        private method operator object takes nothing returns IntegerPointer
            return IntegerPointer(this)[0]
        endmethod
        private method operator object= takes IntegerPointer newObject returns nothing
            local IntegerPointer oldObject = object
            local integer size = oldObject.size
            local integer newSize = newObject.size
            
            if (size > newSize) then
                set size = newSize
            endif
            
            loop
                set size = size - 1
                set newObject[size] = oldObject[size]
                exitwhen 0 == size
            endloop
            
            call oldObject.deallocate()
            set IntegerPointer(this)[0] = newObject
        endmethod
        
        method operator size takes nothing returns integer
            return object.size
        endmethod
        method operator size= takes integer newSize returns nothing
            if (size == newSize) then
                return
            endif
            set object = IntegerPointer.allocate(newSize)
        endmethod
        
        method operator [] takes integer index returns Pointer
            return object[index]
        endmethod
        method operator []= takes integer index, Pointer data returns nothing
            if (index > size) then
                set size = R2I(index * 1.2)
            endif
            set object[index] = data
        endmethod
        
        static method create takes nothing returns thistype
            local thistype this = IntegerPointer.allocate(1)
            set IntegerPointer(this)[0] = IntegerPointer.allocate(5)
            return this
        endmethod
        
        method destroy takes nothing returns nothing
            call object.deallocate()
            call IntegerPointer(this).deallocate()
        endmethod
        
        method find takes integer startIndex, Pointer data returns integer
            local integer size
            set this = object
            set size = IntegerPointer(this).size
            loop
                exitwhen startIndex > size or IntegerPointer(this)[startIndex] == data
                set startIndex = startIndex + 1
            endloop
            if (startIndex > size) then
                return -1
            endif
            return startIndex
        endmethod
        
        method count takes Pointer data returns integer
            local integer size
            local integer count = 0
            set this = object
            set size = IntegerPointer(this).size
            loop
                set size = size - 1
                if (IntegerPointer(this)[size] == data) then
                    set count = count + 1
                endif
                exitwhen 0 == size
            endloop
            return count
        endmethod
    endstruct
endlibrary



Back To Collection Index

Standard nodes are necessary so that general algorithms can be applied to any data structure meeting that standard. Standard nodes only contain properties, which allows any resource to use them.
JASS:
library Node0 /* v1.0.0.0
*************************************************************************************
*
*   1D Node without data
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*
************************************************************************************
*
*   struct Node0
*
*       static constant integer PROPERTY_next
*
*       thistype next
*
*       static method allocate takes nothing returns thistype
*
*   Extending
*       //! runtextmacro EXTEND("Node0", "PROP_COUNT")
*       module NodeProperties0
*
************************************************************************************/
    module NodeProperties0
        //! runtextmacro CREATE_PROPERTY("next", "0", "thistype")
    endmodule
    struct Node0 extends array
        //! runtextmacro EXTEND_NOTHING("1")
        implement NodeProperties0
    endstruct
endlibrary

JASS:
library Node1 /* v1.0.0.0
*************************************************************************************
*
*   1D Node, for stacks and queues
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node0 /*
*
************************************************************************************
*
*   struct Node1
*
*       static constant integer PROPERTY_data
*
*       Pointer data
*
*   Extending
*       //! runtextmacro EXTEND("Node1", "PROP_COUNT")
*       module NodeProperties1
*
************************************************************************************/
    module NodeProperties1
        implement NodeProperties0
        //! runtextmacro CREATE_PROPERTY("data", "Node0.PROP_COUNT + 0", "Pointer")
    endmodule
    struct Node1 extends array
        //! runtextmacro EXTEND("Node0", "1")
        implement NodeProperties1
    endstruct
endlibrary

JASS:
library Node2 /* v1.0.0.0
*************************************************************************************
*
*   2D Node, for lists and queue heads
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node1  /*
*
************************************************************************************
*
*   struct Node2 extends Node1
*
*       static constant integer PROPERTY_prev
*
*       thistype prev
*
*   Extending
*       //! runtextmacro EXTEND("Node2", "PROP_COUNT")
*       module NodeProperties2
*
************************************************************************************/    
    module NodeProperties2
        implement NodeProperties1
        //! runtextmacro CREATE_PROPERTY("prev", "Node1.PROP_COUNT + 0", "thistype")
    endmodule
    struct Node2 extends array
        //! runtextmacro EXTEND("Node1", "1")
        implement NodeProperties2
    endstruct
endlibrary

JASS:
library Node3 /* v1.0.0.0
*************************************************************************************
*
*   3D Node, for list nodes
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node2  /*
*
************************************************************************************
*
*   struct Node3 extends Node2
*
*       static constant integer PROPERTY_head
*
*       thistype head
*
*   Extending
*       //! runtextmacro EXTEND("Node3", "PROP_COUNT")
*       module NodeProperties3
*
************************************************************************************/    
    module NodeProperties3
        implement NodeProperties2
        //! runtextmacro CREATE_PROPERTY("head", "Node2.PROP_COUNT + 0", "thistype")
    endmodule
    struct Node3 extends array
        //! runtextmacro EXTEND("Node2", "1")
        implement NodeProperties3
    endstruct
endlibrary

JASS:
library NodeTree /* v1.0.0.0
*************************************************************************************
*
*   Node for trees
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*
************************************************************************************
*
*   struct NodeTree
*
*       static constant integer PROPERTY_left
*       static constant integer PROPERTY_right
*       static constant integer PROPERTY_parent
*       static constant integer PROPERTY_data
*
*       thistype left
*       thistype right
*       thistype parent
*       Pointer data
*
*       static method allocate takes nothing returns thistype
*
*   Extending
*       //! runtextmacro EXTEND("NodeTree", "PROP_COUNT")
*       module NodeTreeProperties
*
************************************************************************************/    
    module NodeTreeProperties
        //! runtextmacro CREATE_PROPERTY("left", "0", "thistype")
        //! runtextmacro CREATE_PROPERTY("right", "1", "thistype")
        //! runtextmacro CREATE_PROPERTY("parent", "2", "thistype")
        //! runtextmacro CREATE_PROPERTY("data", "3", "Pointer")
    endmodule
    struct NodeTree extends array
        //! runtextmacro EXTEND_NOTHING("4")
        implement NodeTreeProperties
    endstruct
endlibrary

JASS:
library NodeTreeWeight /* v1.0.0.0
*************************************************************************************
*
*   Node for binary search trees
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ NodeTree /*
*
************************************************************************************
*
*   struct NodeTreeWeight extends NodeTree
*
*       static constant integer PROPERTY_weight
*
*       integer weight
*
*   Extending
*       //! runtextmacro EXTEND("NodeTreeWeight", "PROP_COUNT")
*       module NodeTreeWeightProperties
*
************************************************************************************/    
    module NodeTreeWeightProperties
        //! runtextmacro CREATE_PROPERTY("weight", "NodeTree.PROP_COUNT + 0", "integer")
    endmodule
    struct NodeTreeWeight extends array
        //! runtextmacro EXTEND("NodeTree", "1")
        implement NodeTreeWeightProperties
    endstruct
endlibrary

JASS:
library TreeHead /* v1.0.0.0
*************************************************************************************
*
*   Pointer to a tree
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*
************************************************************************************
*
*   struct NodeTree
*
*       static constant integer PROPERTY_first
*
*       NodeTree first
*
*       static method allocate takes nothing returns thistype
*
*   Extending
*       //! runtextmacro EXTEND("NodeTree", "PROP_COUNT")
*       module NodeTreeProperties
*
************************************************************************************/    
    module TreeHeadProperties
        //! runtextmacro CREATE_PROPERTY("first", "0", "NodeTree")
    endmodule
    struct TreeHead extends array
        //! runtextmacro EXTEND_NOTHING("1")
        implement TreeHeadProperties
    endstruct
endlibrary

JASS:
library StackHead /* v1.0.0.0
*************************************************************************************
*
*   Pointer to a stack
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node1  /*
*
************************************************************************************
*
*   struct StackHead bound to Node1
*
*       static constant integer PROPERTY_first
*       static constant integer PROPERTY_sentinel
*
*       Node1 first -> next
*       integer sentinel -> data
*
*   Extending
*       //! runtextmacro EXTEND("StackHead", "PROP_COUNT")
*       module StackHeadProperties
*
************************************************************************************/    
    module StackHeadProperties
        //! runtextmacro CREATE_PROPERTY("first", "Node1.PROPERTY_next", "Node1")
        //! runtextmacro CREATE_PROPERTY("sentinel", "Node1.PROPERTY_data", "integer")
    endmodule
    struct StackHead extends array
        //! runtextmacro EXTEND("Node1", "0")
        implement StackHeadProperties
    endstruct
endlibrary

JASS:
library QueueHead /* v1.0.0.0
*************************************************************************************
*
*   Pointer to a queue
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ Node2  /*
*       */ Node1 /*
*
************************************************************************************
*
*   struct QueueHead bound to Node2
*
*       static constant integer PROPERTY_first
*       static constant integer PROPERTY_last
*       static constant integer PROPERTY_sentinel
*       
*       Node2 first -> next
*       Node2 last -> prev
*       integer sentinel -> data
*
*   Extending
*       //! runtextmacro EXTEND("QueueHead", "PROP_COUNT")
*       module QueueHeadProperties
*
************************************************************************************/    
    module QueueHeadProperties
        //! runtextmacro CREATE_PROPERTY("first", "Node2.PROPERTY_next", "Node1")
        //! runtextmacro CREATE_PROPERTY("last", "Node2.PROPERTY_prev", "Node1")
        //! runtextmacro CREATE_PROPERTY("sentinel", "Node2.PROPERTY_data", "integer")
    endmodule
    struct QueueHead extends array
        //! runtextmacro EXTEND("Node2", "0")
        implement QueueHeadProperties
    endstruct
endlibrary

JASS:
library ListHead /* v1.0.0.0
*************************************************************************************
*
*   Pointer to a queue
*
*************************************************************************************
*
*   */uses/*
*
*       */ Malloc /*                 hiveworkshop.com/forums/submissions-414/system-malloc-221509/
*       */ QueueHead  /*
*       */ Node3 /*
*
************************************************************************************
*
*   struct ListHead extends QueueHead
*
*   Extending
*       //! runtextmacro EXTEND("ListHead", "PROP_COUNT")
*       module ListHeadProperties
*
************************************************************************************/    
    module ListHeadProperties
        //! runtextmacro CREATE_PROPERTY("first", "QueueHead.PROPERTY_first", "Node3")
        //! runtextmacro CREATE_PROPERTY("last", "QueueHead.PROPERTY_last", "Node3")
        //! runtextmacro CREATE_PROPERTY("sentinel", "QueueHead.PROPERTY_sentinel", "integer")
    endmodule
    struct ListHead extends array
        //! runtextmacro EXTEND("QueueHead", "0")
        implement ListHeadProperties
    endstruct
endlibrary
 
Last edited:
JASS:
module Stack
    readonly thistype next

How many times have I mentioned that readonly doesn't protect module elements from being set by the implementing struct? Well it is pretty useless to add readonly since you are not protecting the user in any way. The only way to do this is to make "next" private and make a "get" operator for it.
 
Top