Files
kraken/stdlib/tree.krak

32 lines
836 B
Plaintext
Raw Normal View History

2015-08-06 02:42:40 -04:00
import mem
2018-05-22 19:43:54 -04:00
import vec
2015-08-06 02:42:40 -04:00
obj tree<T> (Object) {
var data: T
2018-05-22 19:43:54 -04:00
var children: vec::vec<*tree<T>>
2015-08-06 02:42:40 -04:00
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 operator==<U>(other: ref tree<U>):bool {
return data == other.data
}
2015-08-06 02:42:40 -04:00
fun destruct() {
mem::maybe_destruct(&data)
children.destruct()
}
}