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

commonMain.it.unibo.tuprolog.collections.AbstractClauseCollection.kt Maven / Gradle / Ivy

Go to download

In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses

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

import it.unibo.tuprolog.collections.rete.custom.ReteTree
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.core.Directive
import it.unibo.tuprolog.core.Rule
import it.unibo.tuprolog.unify.Unificator

internal abstract class AbstractClauseCollection> protected constructor(
    protected val rete: ReteTree,
) : ClauseCollection {
    override val unificator: Unificator
        get() = rete.unificator

    protected abstract val self: Self

    override val size: Int
        get() = rete.size

    override val directives: Iterable
        get() = rete.directives.asIterable()

    override val rules: Iterable
        get() = rete.rules.asIterable()

    override fun isEmpty(): Boolean = rete.isEmpty

    override fun isNonEmpty(): Boolean = !isEmpty()

    override fun contains(element: Clause): Boolean = rete.get(element).any()

    @Suppress("RedundantAsSequence")
    override fun containsAll(elements: Iterable): Boolean = elements.asSequence().all { it in this }

    abstract override fun add(clause: Clause): Self

    abstract override fun addAll(clauses: Iterable): Self

    abstract override fun retrieve(clause: Clause): RetrieveResult

    abstract override fun retrieveAll(clause: Clause): RetrieveResult

    override fun iterator(): Iterator = rete.clauses.iterator()

    override fun toString(): String = "${this::class.simpleName}(${this.joinToString(", ")})"
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy