Serilization and caching the table works!

This commit is contained in:
Nathan Braswell
2015-08-26 03:45:34 -04:00
parent b67d5e85fe
commit d72cbdcedb
16 changed files with 276 additions and 25 deletions

View File

@@ -1,4 +1,6 @@
import vector
import serialize
import util
fun stack<T>():stack<T> {
@@ -11,7 +13,7 @@ fun stack<T>(in:T):stack<T> {
return out
}
obj stack<T> (Object) {
obj stack<T> (Object, Serializable) {
var data: vector::vector<T>
fun construct(): *stack<T> {
data.construct()
@@ -26,6 +28,15 @@ obj stack<T> (Object) {
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 {
var temp = vector::vector<T>()
util::unpack(temp, pos) = serialize::unserialize<vector::vector<T>>(it, pos)
data.copy_construct(&temp)
return pos
}
fun push(it: ref T) {
data.addEnd(it)
}