Cleanup code
This commit is contained in:
parent
e33c846314
commit
cde05c1d7d
|
|
@ -42,7 +42,6 @@ internal class ConstraintsProcessing(
|
|||
val trace: EvaluationTrace = EvaluationTrace.NULL,
|
||||
val profiler: Profiler? = null ) : MatchJournal by journal
|
||||
{
|
||||
fun getFrontState(): DispatchingFrontState = dispatchingFront.state()
|
||||
|
||||
fun engage(controller: Controller) {
|
||||
logicalState.setController(controller)
|
||||
|
|
@ -72,9 +71,8 @@ internal class ConstraintsProcessing(
|
|||
}
|
||||
|
||||
val matches = dispatchingFront.matches().toList()
|
||||
val currentMatches = matches
|
||||
|
||||
val outStatus = processMatches(controller, active, currentMatches, inStatus)
|
||||
val outStatus = processMatches(controller, active, matches, inStatus)
|
||||
|
||||
// TODO: should be isAlive()
|
||||
if (active.stored) {
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ internal class ControllerImpl (
|
|||
val itemOk = when (item) {
|
||||
is Constraint -> activateConstraint(item, newParent, occCreator, context)
|
||||
is Predicate -> tellPredicate(item, context)
|
||||
else -> throw IllegalArgumentException("unknown item ${item}")
|
||||
else -> throw IllegalArgumentException("unknown item $item")
|
||||
}
|
||||
|
||||
if (itemOk) {
|
||||
|
|
@ -303,7 +303,7 @@ internal class ControllerImpl (
|
|||
logicalContext: LogicalContext,
|
||||
rule: Rule? = null,
|
||||
trace: EvaluationTrace = EvaluationTrace.NULL) :
|
||||
this(inStatus, false, logicalContext, rule, trace) { }
|
||||
this(inStatus, false, logicalContext, rule, trace)
|
||||
|
||||
fun currentStatus(): FeedbackStatus = status
|
||||
|
||||
|
|
|
|||
|
|
@ -60,19 +60,10 @@ abstract class FeedbackStatus(val feedback : Feedback?) {
|
|||
override fun recover(): FeedbackStatus = NORMAL(feedback)
|
||||
}
|
||||
|
||||
class ABORTED(status: FeedbackStatus, val reason: Feedback) : FeedbackStatus(compose(status.feedback, reason)) {
|
||||
class ABORTED(status: FeedbackStatus, reason: Feedback) : FeedbackStatus(compose(status.feedback, reason)) {
|
||||
override val operational = false
|
||||
override fun recover(): FeedbackStatus = NORMAL(CompositeFeedback.dropLast(feedback))
|
||||
}
|
||||
}
|
||||
|
||||
internal fun compose(left: Feedback?, right: Feedback?) = CompositeFeedback.of(left, right)
|
||||
|
||||
data class ReportMessage(val severity: Severity, val message: String)
|
||||
|
||||
enum class Severity(val level: Int) {
|
||||
INFO(0),
|
||||
WARNING(1),
|
||||
ERROR(2),
|
||||
FATAL(3)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,5 +204,5 @@ internal class LogicalImpl<T> : MutableLogical<T> {
|
|||
|
||||
}
|
||||
|
||||
class DefaultMetaLogical<V> (val name: String) : MetaLogical<V>(name, Object::class.java as Class<V>) {}
|
||||
class DefaultMetaLogical<V> (val name: String) : MetaLogical<V>(name, Object::class.java as Class<V>)
|
||||
|
||||
|
|
|
|||
|
|
@ -63,13 +63,6 @@ interface MatchJournal : EvidenceSource {
|
|||
* will return the count of all [Occurrence]s.
|
||||
*/
|
||||
fun currentPos(): Pos
|
||||
|
||||
/**
|
||||
* Returns internal [ChunkIterator] that allows to remove future [Chunk]s.
|
||||
*/
|
||||
@Deprecated("Obsolete TBR")
|
||||
val cursor: ChunkIterator
|
||||
get() = TODO()
|
||||
|
||||
/**
|
||||
* Erase journal between [currentPos] (erased) and [pastPos] (not erased).
|
||||
|
|
@ -102,8 +95,7 @@ interface MatchJournal : EvidenceSource {
|
|||
* Immutable snapshot of [MatchJournal].
|
||||
* FOR TESTS ONLY
|
||||
*/
|
||||
data class View(val chunks: List<Chunk>, val evidenceSeed: Evidence) {
|
||||
}
|
||||
data class View(val chunks: List<Chunk>, val evidenceSeed: Evidence)
|
||||
|
||||
/**
|
||||
* [MatchJournal] operates on [Chunk]s -- basic [Justified] entities.
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ internal open class MatchJournalImpl(
|
|||
|
||||
private val justifications = match.collectJustifications(evidence)
|
||||
|
||||
override fun toString() = "(id=$evidence, ${justifications()}, ${match.rule().uniqueTag().toString()}, $entries)"
|
||||
override fun toString() = "(id=$evidence, ${justifications()}, ${match.rule().uniqueTag()}, $entries)"
|
||||
}
|
||||
|
||||
private class OccChunkImpl(override val occ: Occurrence) : ChunkImpl(), Justified by occ, OccChunk {
|
||||
|
|
@ -123,21 +123,6 @@ internal open class MatchJournalImpl(
|
|||
ancestorChunksStack.push(nextChunk)
|
||||
}
|
||||
|
||||
private fun collectJustificationsFrom(match: RuleMatch) {
|
||||
val parent: MatchChunk = parentChunk()
|
||||
|
||||
val moreJustified = match.allHeads().filter {
|
||||
// Filter to avoid justifying parent by its child!
|
||||
!it.justifiedBy(parent)
|
||||
}.toList()
|
||||
|
||||
if (moreJustified.isNotEmpty()) {
|
||||
__cursor.applyToPast(parent.toPos()) { child ->
|
||||
child.addJustifications(moreJustified)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun logActivation(occ: Occurrence) {
|
||||
resetParentChunk(occ)
|
||||
__cursor.addChunk(OccChunkImpl(occ))
|
||||
|
|
@ -304,26 +289,6 @@ internal open class MatchJournalImpl(
|
|||
indexChunk(chunk)
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk in journal in direct order ([from] -> [current])
|
||||
* while applying [action] to each visited [Chunk]
|
||||
* (not including [from], but including [__current]).
|
||||
* No journal state is changed, except by [action] effects
|
||||
* (i.e. no reset or replay of occurrences is performed).
|
||||
*/
|
||||
inline fun applyToPast(from: Pos, action: (Chunk) -> Unit) {
|
||||
val returnTo = __current
|
||||
// there's always at least initial chunk
|
||||
do {
|
||||
__current = iter.previous()
|
||||
} while (!(this at from))
|
||||
|
||||
do {
|
||||
__current = iter.next()
|
||||
action(__current)
|
||||
} while (!(this at returnTo))
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk in journal in inverse order ([pastPos] <- [current]), excluding [pastPos]
|
||||
* while applying [action] to each [Chunk] and removing it.
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup?,
|
|||
|
||||
}
|
||||
|
||||
inner class InitialNode() : ReteNode() {
|
||||
inner class InitialNode : ReteNode() {
|
||||
|
||||
override fun fillSignature(signature: Signature) {}
|
||||
|
||||
|
|
@ -379,7 +379,7 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup?,
|
|||
*/
|
||||
inner class Generation private constructor (prev: Generation?) {
|
||||
|
||||
val layers: MutableList<Layer> = prev?.layers ?: ArrayList<Layer>(4)
|
||||
val layers: MutableList<Layer> = prev?.layers ?: ArrayList(4)
|
||||
|
||||
lateinit var nodesIt: MutableIterator<ReteNode>
|
||||
|
||||
|
|
@ -452,14 +452,6 @@ internal class ReteRuleMatcherImpl(private var ruleLookup: RuleLookup?,
|
|||
return nextGeneration().reset()
|
||||
}
|
||||
|
||||
private fun clearInvalidNodes(): Generation {
|
||||
while (nodesIt.hasNext()) {
|
||||
val n = nodesIt.next()
|
||||
if (n.isInvalid()) nodesIt.remove()
|
||||
}
|
||||
return this.reset()
|
||||
}
|
||||
|
||||
fun nextGeneration(): Generation = Generation(this)
|
||||
|
||||
fun calcMatches(): Collection<RuleMatchImpl> {
|
||||
|
|
@ -632,9 +624,7 @@ class UnionFindLinkedList<T> : Iterable<T> {
|
|||
|
||||
}
|
||||
|
||||
inner class DataJoint(val value: T) : Joint() {
|
||||
|
||||
}
|
||||
inner class DataJoint(val value: T) : Joint()
|
||||
|
||||
var head = Joint()
|
||||
var tail = head
|
||||
|
|
|
|||
Loading…
Reference in New Issue