Fixed the close over methods and member vars bug, but there's something remaining causing the safe_recursive_delete not to work. Gotta save progress and do other stuff

This commit is contained in:
Nathan Braswell
2015-06-27 18:06:02 -04:00
parent 8feb9819b8
commit c50c977a9e
20 changed files with 370 additions and 40 deletions

View File

@@ -1,4 +1,4 @@
import io:*
import set
__if_comp__ __C__ simple_passthrough """
#include <stdlib.h>
@@ -93,4 +93,15 @@ fun maybe_destruct<T(Object)>(it:T*):void {
it->destruct()
}
// a function that allows the safe deletion of recursive and complicated data structures
fun safe_recursive_delete<T>(first: T*, addingFunc: fun(T*): set::set<T*>) {
var toDelete = set::set<T*>()
var next = set::set(first)
while (toDelete != next) {
toDelete = next
toDelete.for_each( fun(it: T*) next.add(addingFunc(it)); )
}
toDelete.for_each( fun(it: T*) delete(it); )
}