commonMain.it.unibo.tuprolog.collections.rete.custom.AbstractReteNode.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of theory-jvm Show documentation
Show all versions of theory-jvm Show documentation
In-memory storage and indexing facilities for ordered and unordered knowledge bases composed by logic clauses
package it.unibo.tuprolog.collections.rete.custom
import it.unibo.tuprolog.collections.rete.custom.clause.IndexedClause
import it.unibo.tuprolog.core.Clause
import it.unibo.tuprolog.unify.Unificator
internal abstract class AbstractReteNode(override val unificator: Unificator) : ReteNode {
fun removeAllLazily(
source: MutableList,
clause: Clause,
): Sequence =
sequence {
val iter = source.iterator()
while (iter.hasNext()) {
val it = iter.next()
if (unificator.match(it.innerClause, clause)) {
it.invalidateAllCaches()
iter.remove()
yield(it)
}
}
}
}