Rename for better readability: fringe -> front, matchRule -> ruleMatch.

This commit is contained in:
Fedor Isakov 2019-05-09 14:23:08 +02:00
parent 915bc1442a
commit d70bc2509d
7 changed files with 40 additions and 40 deletions

View File

@ -37,11 +37,11 @@ class Dispatcher (val ruleIndex: RuleIndex) {
}
/**
* Create new empty [DispatchFringe] ready to accept constraints.
* Create new empty [DispatchingFront] ready to accept constraints.
*/
fun fringe() = DispatchFringe()
fun front() = DispatchingFront()
inner class DispatchFringe {
inner class DispatchingFront {
private var ruletag2probe: PersMap<String, RuleMatchingProbe>
@ -54,7 +54,7 @@ class Dispatcher (val ruleIndex: RuleIndex) {
}
}
private constructor(pred: DispatchFringe, matching: Iterable<RuleMatchingProbe>) {
private constructor(pred: DispatchingFront, matching: Iterable<RuleMatchingProbe>) {
this.ruletag2probe = pred.ruletag2probe
matching.forEach { probe ->
this.ruletag2probe = ruletag2probe.put(probe.rule().tag(), probe)
@ -62,7 +62,7 @@ class Dispatcher (val ruleIndex: RuleIndex) {
}
}
private constructor(pred: DispatchFringe, consumedMatch: RuleMatchEx) {
private constructor(pred: DispatchingFront, consumedMatch: RuleMatchEx) {
this.ruletag2probe = pred.ruletag2probe
pred.ruletag2probe[consumedMatch.rule().tag()]?.let {
this.ruletag2probe = ruletag2probe.put(consumedMatch.rule().tag(), it.consume(consumedMatch))
@ -75,20 +75,20 @@ class Dispatcher (val ruleIndex: RuleIndex) {
fun matches() : Iterable<RuleMatchEx> = allMatches
/**
* Returns a new [DispatchFringe] instance that is "expanded" with matches corresponding to the
* Returns a new [DispatchingFront] instance that is "expanded" with matches corresponding to the
* specified active constraint occurrence.
*/
fun expand(activated: Occurrence) = DispatchFringe(this,
fun expand(activated: Occurrence) = DispatchingFront(this,
ruleIndex.forOccurrenceWithMask(activated).mapNotNull { (rule, mask) ->
ruletag2probe[rule.tag()]?.expand(activated, mask)
ruletag2probe[rule.tag()]?.expand(activated, mask)
})
/**
* Returns a new [DispatchFringe] instance that is "contracted": all matches corresponding to the
* Returns a new [DispatchingFront] instance that is "contracted": all matches corresponding to the
* specified discarded constraint occurrence are eliminated.
*/
fun contract(discarded: Occurrence) = DispatchFringe(this,
fun contract(discarded: Occurrence) = DispatchingFront(this,
ruleIndex.forOccurrence(discarded).mapNotNull { rule ->
ruletag2probe[rule.tag()]
}.map { probe ->
@ -99,7 +99,7 @@ class Dispatcher (val ruleIndex: RuleIndex) {
* Serves to indicate that the specified [RuleMatchEx] has been processed (consumed) and has to
* be excluded from any further "match" set returned by [matches].
*/
internal fun consume(matchRule: RuleMatchEx) = DispatchFringe(this, matchRule)
internal fun consume(ruleMatch: RuleMatchEx) = DispatchingFront(this, ruleMatch)
}

View File

@ -31,7 +31,7 @@ interface RuleMatchingProbe {
fun matches(): Collection<RuleMatchEx>
fun consume(matchRule: RuleMatchEx): RuleMatchingProbe
fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe
fun expand(occ: Occurrence): RuleMatchingProbe

View File

@ -40,7 +40,7 @@ internal class ControllerImpl (
private val session: EvaluationSession = EvaluationSession.current()
private var dispatchFringe = Dispatcher(ruleIndex).fringe()
private var dispatchFront = Dispatcher(ruleIndex).front()
// FIXME move to context
private val frameStack = FrameStack(storeView)
@ -87,10 +87,10 @@ internal class ControllerImpl (
trace.reactivate(active)
}
val activatedFringe = dispatchFringe.expand(active)
this.dispatchFringe = activatedFringe
val activatedFront = dispatchFront.expand(active)
this.dispatchFront = activatedFront
val outState = activatedFringe.matches().toList().fold(inState) { state, match ->
val outState = activatedFront.matches().toList().fold(inState) { state, match ->
// TODO: paranoid check. should be isAlive() instead
// FIXME: move this check elsewhere
if (state.operational && active.stored && match.allStored())
@ -139,11 +139,11 @@ internal class ControllerImpl (
}
}
this.dispatchFringe = dispatchFringe.consume(match)
this.dispatchFront = dispatchFront.consume(match)
trace.trigger(match)
match.forEachReplaced {occ ->
this.dispatchFringe = dispatchFringe.contract(occ)
this.dispatchFront = dispatchFront.contract(occ)
frameStack.current.store.discard(occ)
trace.discard(occ)
}

View File

@ -348,7 +348,7 @@ internal class ReteRuleMatcherImpl(val rule: Rule) : RuleMatcher {
override fun matches(): Collection<RuleMatchImpl> = generations.last().matches()
override fun consume(matchRule: RuleMatchEx): RuleMatchingProbe {
override fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}

View File

@ -43,12 +43,12 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
fun lookupRule(): Rule = ruleLookup.lookupRuleByTag(tag) ?: throw IllegalStateException("can't lookup rule by tag: '${tag}'")
override fun probe(): RuleMatchingProbe =
RuleMatchFringe(listOf(MatchNode(emptySubst())),
RuleMatchFront(listOf(MatchNode(emptySubst())),
Sets.of(),
Sets.of(),
0)
inner class RuleMatchFringe(private val nodes: List<MatchNode>,
inner class RuleMatchFront(private val nodes: List<MatchNode>,
private val seenOccurrences: PersSet<IdWrapper<Occurrence>>,
private val consumedSignatures: PersSet<ArrayList<IdWrapper<Occurrence>?>>,
private val genId: Int) : RuleMatchingProbe
@ -58,22 +58,22 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
override fun matches(): Collection<RuleMatchImpl> =
nodes
.filter { it is ActiveMatchNode && it.complete && it.genId == genId }
.map { (it as ActiveMatchNode).toMatchRule() }
.map { (it as ActiveMatchNode).toRuleMatch() }
override fun consume(matchRule: RuleMatchEx): RuleMatchingProbe =
RuleMatchFringe(nodes,
override fun consume(ruleMatch: RuleMatchEx): RuleMatchingProbe =
RuleMatchFront(nodes,
seenOccurrences,
consumedSignatures.add(matchRule.signature()),
consumedSignatures.add(ruleMatch.signature()),
genId)
override fun expand(occ: Occurrence): RuleMatchingProbe =
expand(occ, bitSetOfOnes(head.size))
/**
* Expands the fringe by creating new leaf nodes that match the occurrence.
* Expands the front by creating new leaf nodes that match the occurrence.
* Mask specifies possible slots for the occurrence.
*/
override fun expand(occ: Occurrence, mask: BitSet): RuleMatchFringe {
override fun expand(occ: Occurrence, mask: BitSet): RuleMatchFront {
val reactivated = seenOccurrences.contains(IdWrapper(occ))
val newSeen = if (reactivated) seenOccurrences else seenOccurrences.add(IdWrapper(occ))
val newNodes = ArrayList<MatchNode>(nodes)
@ -86,12 +86,12 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
.forEach { newNodes.add(it) }
}
return RuleMatchFringe(newNodes, newSeen, consumedSignatures, genId + 1)
return RuleMatchFront(newNodes, newSeen, consumedSignatures, genId + 1)
}
override fun contract(occ: Occurrence): RuleMatchFringe {
override fun contract(occ: Occurrence): RuleMatchFront {
val newNodes = nodes.mapNotNull { it.unrelatedOrNull(occ) }
return RuleMatchFringe(newNodes, seenOccurrences, consumedSignatures, genId + 1)
return RuleMatchFront(newNodes, seenOccurrences, consumedSignatures, genId + 1)
}
}
@ -171,7 +171,7 @@ internal class RuleMatcherImpl(private val ruleLookup: RuleLookup,
foldUntilNull(this) { acc, rn -> if (rn.occurrence === occ) null else acc }
fun toMatchRule(): RuleMatchImpl {
fun toRuleMatch(): RuleMatchImpl {
val matched: Array<Occurrence> =
fold(arrayOfNulls<Occurrence>(head.size)) { arr, rn ->
arr[rn.headIndex] = rn.occurrence; arr

View File

@ -36,15 +36,15 @@ public interface EvaluationTrace {
default void discard(ConstraintOccurrence occurrence) {}
default void trying(RuleMatch matchRule) {}
default void trying(RuleMatch ruleMatch) {}
default void reject(RuleMatch matchRule) {}
default void reject(RuleMatch ruleMatch) {}
default void trigger(RuleMatch matchRule) {}
default void trigger(RuleMatch ruleMatch) {}
default void retry(RuleMatch matchRule) {}
default void retry(RuleMatch ruleMatch) {}
default void finish(RuleMatch matchRule) {}
default void finish(RuleMatch ruleMatch) {}
default void tell(PredicateInvocation invocation) {}

View File

@ -545,7 +545,7 @@ class TestRuleMatcher {
constraint("qux")
))))
{
with(Dispatcher(RuleIndex(handlers)).fringe()) {
with(Dispatcher(RuleIndex(handlers)).front()) {
expand(occurrence("foo")) }.apply {
matches().count() shouldBe 0 }.run {
@ -587,7 +587,7 @@ class TestRuleMatcher {
constraint("qux")
))))
{
with(Dispatcher(RuleIndex(handlers)).fringe()) {
with(Dispatcher(RuleIndex(handlers)).front()) {
expand(occurrence("foo")) }.apply {
matches().count() shouldBe 0 }.run {
@ -656,7 +656,7 @@ class TestRuleMatcher {
constraint("qux")
))))
{
with(Dispatcher(RuleIndex(handlers)).fringe()) {
with(Dispatcher(RuleIndex(handlers)).front()) {
expand(occurrence("blin")) }.apply {
matches().count() shouldBe 0 }.run {
@ -706,7 +706,7 @@ class TestRuleMatcher {
constraint("qux")
))))
{
with(Dispatcher(RuleIndex(handlers)).fringe()) {
with(Dispatcher(RuleIndex(handlers)).front()) {
expand(occurrence("foo")) }.apply {
matches().count() shouldBe 0 }.run {
@ -759,7 +759,7 @@ class TestRuleMatcher {
))))
{
val bar = occurrence("bar")
with(Dispatcher(RuleIndex(handlers)).fringe()) {
with(Dispatcher(RuleIndex(handlers)).front()) {
expand(occurrence("foo")) }.apply {
matches().count() shouldBe 0 }.run {