Add in support for top-level-declarations in k and erroring out if no progress is made in poset. A bug I encountered during devleopment of this reminds me of the need to deal with cycles in the poset in the future - probabally by not adding a close dependency if doing so would make a close dependency cycle? This might not actually be fully legitimate

This commit is contained in:
Nathan Braswell
2018-09-18 00:37:16 -04:00
parent cf4a006958
commit 2d9f5dc6fe
2 changed files with 27 additions and 16 deletions

View File

@@ -63,20 +63,26 @@ obj poset<T> (Object) {
opened = set<T>()
closed = set<T>()
while closed.size() != size() {
var changed = false
// intentionally not refs, as it can change out from under us
open_deps.for_each(fun(v: T, ods: set<T>) {
if !closed.contains(v) && closed.contains(ods) {
if !opened.contains(v) {
changed = true
f(v)
if closed.contains(open_deps[v]) {
opened.add(v)
}
}
if closed.contains(open_deps[v]) && closed.contains(close_deps[v]) {
changed = true
closed.add(v)
}
}
})
if (changed == false) {
error("Poset has not changed!")
}
}
}
fun get_sorted(): vec<T> {