more work

This commit is contained in:
Nathan Braswell
2015-08-06 02:42:40 -04:00
parent dec9b7d0bd
commit 1f119af8ad
9 changed files with 284 additions and 21 deletions

28
stdlib/tree.krak Normal file
View File

@@ -0,0 +1,28 @@
import mem
import vector
obj tree<T> (Object) {
var data: T
var children: vector::vector<*tree<T>>
fun construct(dataIn: T): *tree<T> {
mem::maybe_copy_construct(&data, &dataIn)
children.construct()
return this
}
// Some of these don't really make much sense considering this tree is all about
// heap allocated pointers. Best to have it for saftey, though
fun copy_construct(old: *tree<T>) {
mem::maybe_copy_construct(&data, &old->data)
children.copy_construct(&old->children)
}
// ditto
fun operator=(other: tree<T>):void {
destruct()
copy_construct(&other)
}
fun destruct() {
mem::maybe_destruct(&data)
children.destruct()
}
}