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:
@@ -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); )
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user