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

commonMain.it.unibo.tuprolog.bdd.impl.AnyVisitor.kt Maven / Gradle / Ivy

Go to download

Multi-platform library for representing and manipulating Binary Decision Diagrams

There is a newer version: 1.0.4
Show newest version
package it.unibo.tuprolog.bdd.impl

import it.unibo.tuprolog.bdd.BinaryDecisionDiagram
import it.unibo.tuprolog.bdd.BinaryDecisionDiagramVisitor

/**
 * Checks weather at least one node in a [BinaryDecisionDiagram] makes
 * a certain predicate succeed.
 *
 * @author Jason Dellaluce
 */
internal class AnyVisitor>(
    private val predicate: (T) -> Boolean
) : BinaryDecisionDiagramVisitor {

    override fun visit(
        node: BinaryDecisionDiagram.Terminal
    ): Boolean = false

    override fun visit(node: BinaryDecisionDiagram.Variable): Boolean {
        var result = predicate(node.value)
        if (!result) {
            result = node.low.accept(this)
        }
        if (!result) {
            result = node.high.accept(this)
        }
        return result
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy