14 years
edited 8 years
1 library StaticUniqueList /* v1.0.0.2
2 ************************************************************************************3 *4 * */ uses /*
5 *6 * */ ErrorMessage /*
7 *8 ************************************************************************************9 *10 * module StaticUniqueList11 *12 * Description13 * -------------------------14 *15 * Node Properties:16 *17 * Unique18 * Not 019 *20 * Fields21 * -------------------------22 *23 * readonly static integer sentinel24 *25 * readonly static thistype first26 * readonly static thistype last27 *28 * readonly thistype next29 * readonly thistype prev30 *31 * Methods32 * -------------------------33 *34 * static method push takes thistype node returns nothing35 * static method enqueue takes thistype node returns nothing36 *37 * static method pop takes nothing returns nothing38 * static method dequeue takes nothing returns nothing39 *40 * method remove takes nothing returns nothing41 *42 * static method clear takes nothing returns nothing43 *44 ************************************************************************************/45 module StaticUniqueList46 debug private boolean isNode
47
48 private thistype _next
49 method operator next takes nothing returns thistype
50 debug call ThrowError(this == 0, "StaticUniqueList", "next", "thistype", this, "Attempted To Go Out Of Bounds.")
51 debug call ThrowError(not isNode, "StaticUniqueList", "next", "thistype", this, "Attempted To Read Invalid Node.")
52
53 return _next54 endmethod55
56 private thistype _prev
57 method operator prev takes nothing returns thistype
58 debug call ThrowError(this == 0, "StaticUniqueList", "prev", "thistype", this, "Attempted To Go Out Of Bounds.")
59 debug call ThrowError(not isNode, "StaticUniqueList", "prev", "thistype", this, "Attempted To Read Invalid Node.")
60
61 return _prev62 endmethod63
64 static method operator first takes nothing returns thistype
65 return thistype(0)._next
66 endmethod67 static method operator last takes nothing returns thistype
68 return thistype(0)._prev
69 endmethod70
71 private static method setFirst takes thistype node returns nothing
72 set thistype(0)._next = node
73 endmethod74
75 private static method setLast takes thistype node returns nothing
76 set thistype(0)._prev = node
77 endmethod78
79 static constant integer sentinel = 0
80
81 static method push takes thistype node returns nothing
82 debug call ThrowError(node == 0, "StaticUniqueList", "push", "thistype", 0, "Attempted To Push Null Node.")
83 debug call ThrowError(node.isNode, "StaticUniqueList", "push", "thistype", 0, "Attempted To Push Owned Node (" + I2S(node) + ").")
84
85 debug set node.isNode = true
86
87 set first._prev = node
88 set node._next = first
89 call setFirst(node)
90
91 set node._prev = 0
92 endmethod93 static method enqueue takes thistype node returns nothing
94 debug call ThrowError(node == 0, "StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Null Node.")
95 debug call ThrowError(node.isNode, "StaticUniqueList", "enqueue", "thistype", 0, "Attempted To Enqueue Owned Node (" + I2S(node) + ").")
96
97 debug set node.isNode = true
98
99 set last._next = node
100 set node._prev = last
101 call setLast(node)
102
103 set node._next = 0
104 endmethod105 static method pop takes nothing returns nothing
106 debug call ThrowError(first == 0, "StaticUniqueList", "pop", "thistype", 0, "Attempted To Pop Empty List.")
107
108 debug set first.isNode = false
109
110 call setFirst(first._next)
111 set first._prev = 0
112 endmethod113 static method dequeue takes nothing returns nothing
114 debug call ThrowError(last == 0, "StaticUniqueList", "dequeue", "thistype", 0, "Attempted To Dequeue Empty List.")
115
116 debug set last.isNode = false
117
118 call setLast(last._prev)
119 set last._next = 0
120 endmethod121 method remove takes nothing returns nothing
122 debug call ThrowError(this == 0, "StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Null Node.")
123 debug call ThrowError(not isNode, "StaticUniqueList", "remove", "thistype", 0, "Attempted To Remove Invalid Node (" + I2S(this) + ").")
124
125 debug set isNode = false
126
127 set _prev._next = _next
128 set _next._prev = _prev
129 endmethod130 static method clear takes nothing returns nothing
131 static if DEBUG_MODE then
132 local thistype node = first
133
134 loop135 exitwhen node == 0
136 set node.isNode = false
137 set node = node._next
138 endloop139 endif140
141 call setFirst(0)
142 call setLast(0)
143 endmethod144 endmodule145 endlibrary