commonMain.it.unibo.tuprolog.solve.channel.impl.AbstractChannelStore.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solve-jvm Show documentation
Show all versions of solve-jvm Show documentation
Resolution-agnostic API for logic solvers
package it.unibo.tuprolog.solve.channel.impl
import it.unibo.tuprolog.core.Term
import it.unibo.tuprolog.solve.channel.Channel
import it.unibo.tuprolog.solve.channel.ChannelStore
import it.unibo.tuprolog.unify.Unificator.Companion.matches
abstract class AbstractChannelStore, Self : ChannelStore>(
protected val channels: Map,
) : ChannelStore, Map by channels {
override fun toString(): String =
channels.entries.joinToString(
separator = ", ",
prefix = "${this::class.simpleName}(",
postfix = ")",
) {
"${it.key}->${it.value}"
}
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
other as AbstractChannelStore<*, *, *>
if (channels != other.channels) return false
return true
}
override fun hashCode(): Int {
return channels.hashCode()
}
override fun findByTerm(streamTerm: Term): Sequence =
values.asSequence().filter { it.streamTerm matches streamTerm }
override fun aliasesOf(channel: C): Sequence =
entries.asSequence().filter { (_, v) -> v == channel }.map { it.key }.filterNot { it == ChannelStore.CURRENT }
}