77 lines
1.7 KiB
Plaintext
77 lines
1.7 KiB
Plaintext
import vector
|
|
import serialize
|
|
import util
|
|
|
|
|
|
fun stack<T>():stack<T> {
|
|
var out.construct():stack<T>
|
|
return out
|
|
}
|
|
fun stack<T>(in:T):stack<T> {
|
|
var out.construct():stack<T>
|
|
out.push(in)
|
|
return out
|
|
}
|
|
|
|
obj stack<T> (Object, Serializable) {
|
|
var data: vector::vector<T>
|
|
fun construct(): *stack<T> {
|
|
data.construct()
|
|
return this
|
|
}
|
|
fun copy_construct(other: *stack<T>) {
|
|
data.copy_construct(&other->data)
|
|
}
|
|
fun destruct() {
|
|
data.destruct()
|
|
}
|
|
fun operator=(other: ref stack<T>) {
|
|
data = other.data
|
|
}
|
|
fun serialize(): vector::vector<char> {
|
|
return serialize::serialize(data)
|
|
}
|
|
fun unserialize(it: ref vector::vector<char>, pos: int): int {
|
|
/*construct()*/
|
|
/*util::unpack(data, pos) = serialize::unserialize<vector::vector<T>>(it, pos)*/
|
|
return data.unserialize(it, pos)
|
|
}
|
|
fun push(it: ref T) {
|
|
data.addEnd(it)
|
|
}
|
|
fun pop(): T {
|
|
var toRet = data[data.size-1]
|
|
data.remove(data.size-1)
|
|
return toRet
|
|
}
|
|
fun clear() {
|
|
data.clear()
|
|
}
|
|
fun top(): ref T {
|
|
return data[data.size-1]
|
|
}
|
|
fun from_top(num: int): ref T {
|
|
return data[(data.size-1)-num]
|
|
}
|
|
fun size(): int {
|
|
return data.size
|
|
}
|
|
fun empty():bool {
|
|
return data.size == 0
|
|
}
|
|
fun for_each(func: fun(ref T):void) {
|
|
data.for_each(func)
|
|
}
|
|
fun for_each(func: fun(T):void) {
|
|
data.for_each(func)
|
|
}
|
|
fun for_each_reverse(func: fun(ref T):void) {
|
|
data.for_each_reverse(func)
|
|
}
|
|
fun for_each_reverse(func: fun(T):void) {
|
|
data.for_each_reverse(func)
|
|
}
|
|
fun reverse_vector(): vector::vector<T>
|
|
return data.reverse()
|
|
}
|