All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.scce.addlib.traverser.RecursiveIterator Maven / Gradle / Ivy

Go to download

The Java Library for Algebraic Decision Diagrams, Code Generation, and Layouting

There is a newer version: 3.1.0
Show newest version
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);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy