Hide use of TIntSet from trove behind typealias; one usage in ConstraintOccurrence.java is left

This commit is contained in:
Grigorii Kirgizov 2019-05-20 18:53:20 +03:00
parent f8b7ac1d50
commit 52fd54afce
4 changed files with 21 additions and 13 deletions

View File

@ -17,6 +17,7 @@
package jetbrains.mps.logic.reactor.core
import gnu.trove.set.TIntSet
import gnu.trove.set.hash.TIntHashSet
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
import jetbrains.mps.logic.reactor.logical.Logical
@ -24,6 +25,11 @@ import jetbrains.mps.logic.reactor.logical.LogicalContext
import jetbrains.mps.logic.reactor.logical.MetaLogical
import jetbrains.mps.logic.reactor.program.Constraint
typealias Justs = TIntSet
fun justsOf(vararg elements: Int) = TIntHashSet(elements)
fun justsFromCollection(collection: Collection<Int>) = TIntHashSet(collection)
/**
* Data class representing a single constraint occurrence.
*
@ -33,7 +39,7 @@ data class Occurrence (val controller: Controller,
val constraint: Constraint,
val logicalContext: LogicalContext,
val arguments: List<*>,
val justifications: TIntSet?):
val justifications: Justs?):
ConstraintOccurrence,
LogicalObserver
{
@ -52,7 +58,7 @@ data class Occurrence (val controller: Controller,
override fun logicalContext(): LogicalContext = logicalContext
override fun justifications(): TIntSet? = justifications
override fun justifications(): Justs? = justifications
override fun valueUpdated(logical: Logical<*>) {
if (alive) {
@ -90,13 +96,13 @@ data class Occurrence (val controller: Controller,
fun Constraint.occurrence(controller: Controller,
arguments: List<*>,
justifications: TIntSet?,
justifications: Justs?,
logicalContext: LogicalContext): Occurrence =
Occurrence(controller, this, logicalContext, arguments, justifications)
fun Constraint.occurrence(controller: Controller,
arguments: List<*>,
justifications: TIntSet?): Occurrence =
justifications: Justs?): Occurrence =
Occurrence(controller, this, noLogicalContext, arguments, justifications)
fun Constraint.occurrence(controller: Controller,

View File

@ -19,7 +19,9 @@ package jetbrains.mps.logic.reactor.core.internal
import gnu.trove.set.TIntSet
import gnu.trove.set.hash.TIntHashSet
import jetbrains.mps.logic.reactor.core.Dispatcher
import jetbrains.mps.logic.reactor.core.Justs
import jetbrains.mps.logic.reactor.core.Occurrence
import jetbrains.mps.logic.reactor.core.justsOf
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
import jetbrains.mps.logic.reactor.evaluation.RuleMatch
import jetbrains.mps.logic.reactor.evaluation.StoreView
@ -45,7 +47,7 @@ interface MatchJournal : MutableIterable<MatchJournal.Chunk> {
data class View(val chunks: List<Chunk>, val nextChunkId: Int)
data class Chunk(val match: RuleMatch, val id: Int, val justifications: TIntSet) : Pos {
data class Chunk(val match: RuleMatch, val id: Int, val justifications: Justs) : Pos {
data class Entry(val occ: Occurrence, val isDiscarded: Boolean = false) {
override fun toString() = (if (isDiscarded) '-' else '+') + occ.toString()
}
@ -237,8 +239,8 @@ internal class StoreAwareJournalImpl(val state: ProcessingStateImpl, view: Match
}
}
private fun RuleMatch.headJustifications(): TIntSet {
val res: TIntSet = TIntHashSet()
private fun RuleMatch.headJustifications(): Justs {
val res: Justs = justsOf()
this.matchHeadKept().forEach { it.justifications()?.let { res.addAll(it) } }
this.matchHeadReplaced().forEach { it.justifications()?.let { res.addAll(it) } }
return res

View File

@ -123,9 +123,9 @@ fun equals(left: Any, right: Any): ConjBuilder.() -> Unit = {
fun occurrence(id: String, vararg args: Any): Occurrence =
MockConstraint(ConstraintSymbol.symbol(id, args.size)).occurrence(MockController(), listOf(* args))
fun justifiedOccurrence(id: String, justs: TIntSet, vararg args: Any): Occurrence =
fun justifiedOccurrence(id: String, justs: Justs, vararg args: Any): Occurrence =
MockConstraint(ConstraintSymbol.symbol(id, args.size), true).occurrence(MockController(), listOf(* args), justs)
fun justifiedOccurrence(id: String, justs: Set<Int>, vararg args: Any): Occurrence = justifiedOccurrence(id, TIntHashSet(justs), * args)
fun justifiedOccurrence(id: String, justs: Collection<Int>, vararg args: Any): Occurrence = justifiedOccurrence(id, justsFromCollection(justs), * args)
fun sym0(id: String): ConstraintSymbol =
ConstraintSymbol(id, 0)

View File

@ -75,7 +75,7 @@ class TestStoreAwareJournal {
hist.logMatch(this)
rule().tag() shouldBe "rule1"
hist.justs() shouldBe TIntHashSet(setOf(0))
hist.justs() shouldBe justsOf(0)
val fooOcc = justifiedOccurrence("foo", hist.justs())
hist.logActivation(fooOcc)
d = d.expand(fooOcc)
@ -89,7 +89,7 @@ class TestStoreAwareJournal {
hist.logMatch(this)
rule().tag() shouldBe "rule2"
hist.justs() shouldBe TIntHashSet(setOf(0,1))
hist.justs() shouldBe justsOf(0,1)
val barOcc = justifiedOccurrence("bar", hist.justs())
hist.logActivation(barOcc)
d = d.expand(barOcc)
@ -103,7 +103,7 @@ class TestStoreAwareJournal {
hist.logMatch(this)
rule().tag() shouldBe "rule3"
hist.justs() shouldBe TIntHashSet(setOf(0,2))
hist.justs() shouldBe justsOf(0,2)
val quxOcc = justifiedOccurrence("qux", hist.justs())
hist.logActivation(quxOcc)
d = d.expand(quxOcc)
@ -115,7 +115,7 @@ class TestStoreAwareJournal {
hist.logMatch(this)
rule().tag() shouldBe "rule4"
}
hist.justs() shouldBe TIntHashSet(setOf(0,1,2,3))
hist.justs() shouldBe justsOf(0,1,2,3)
}
}
}