info.scce.addlib.traverser.RecursiveIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of addlib Show documentation
Show all versions of addlib Show documentation
The Java Library for Algebraic Decision Diagrams, Code Generation, and Layouting
package info.scce.addlib.traverser;
import info.scce.addlib.dd.DD;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public abstract class RecursiveIterator> extends RecursiveTreeIterator {
private final Set completed;
public RecursiveIterator(D root) {
this(Collections.singletonList(root));
}
public RecursiveIterator(List roots) {
super(roots);
completed = new HashSet<>();
}
@Override
protected D processDD(D f, int i) {
/* Ensure to process each node only if not completed */
if (completed.contains(f)) {
popDD();
return null;
}
return processUnseenDD(f, i);
}
@Override
protected D popDD() {
/* Remember completed nodes */
D f = super.popDD();
completed.add(f);
return f;
}
protected abstract D processUnseenDD(D f, int i);
}