diff options
-rw-r--r-- | src/main/scala/forge/Evaluator.scala | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main/scala/forge/Evaluator.scala b/src/main/scala/forge/Evaluator.scala index d19b8aa3..85bd5ac6 100644 --- a/src/main/scala/forge/Evaluator.scala +++ b/src/main/scala/forge/Evaluator.scala @@ -159,16 +159,28 @@ object Evaluator{ } } } + + val targetOrdering = topoSortedTargets.values.items.zipWithIndex.toMap val output = new MutableMultiBiMap[Int, Target[_]] - for(target <- topoSortedTargets.values.items){ - for(targetGroup <- grouping.lookupValueOpt(target)){ - val shifted = grouping.removeAll(targetGroup) - output.addAll(output.keys().length, shifted.reverse) - } + + // Sort groups amongst themselves, and sort the contents of each group + // before aggregating it into the final output + for(g <- grouping.values().toArray.sortBy(g => targetOrdering(g.items(0)))){ + output.addAll(output.keys.length, g.toArray.sortBy(targetOrdering)) } output } + def checkTopological(targets: OSet[Target[_]]) = { + val seen = mutable.Set.empty[Target[_]] + for(t <- targets.items.reverseIterator){ + seen.add(t) + for(upstream <- t.inputs){ + assert(!seen(upstream)) + } + } + } + /** * Takes the given targets, finds all the targets they transitively depend * on, and sort them topologically. Fails if there are dependency cycles |