From 52fd54afce621a7ee358d061c2c89328108f7d73 Mon Sep 17 00:00:00 2001 From: Grigorii Kirgizov Date: Mon, 20 May 2019 18:53:20 +0300 Subject: [PATCH] Hide use of TIntSet from trove behind typealias; one usage in ConstraintOccurrence.java is left --- .../jetbrains/mps/logic/reactor/core/Occurrence.kt | 14 ++++++++++---- .../reactor/core/internal/StoreAwareJournal.kt | 8 +++++--- reactor/Test/test/RulesHelper.kt | 4 ++-- reactor/Test/test/TestStoreAwareJournal.kt | 8 ++++---- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt index 9c3c8315..c8222332 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/Occurrence.kt @@ -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) = 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, diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt index fab129e7..f1c03e37 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/internal/StoreAwareJournal.kt @@ -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 { data class View(val chunks: List, 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 diff --git a/reactor/Test/test/RulesHelper.kt b/reactor/Test/test/RulesHelper.kt index 59aaacbe..6d7ae677 100644 --- a/reactor/Test/test/RulesHelper.kt +++ b/reactor/Test/test/RulesHelper.kt @@ -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, vararg args: Any): Occurrence = justifiedOccurrence(id, TIntHashSet(justs), * args) +fun justifiedOccurrence(id: String, justs: Collection, vararg args: Any): Occurrence = justifiedOccurrence(id, justsFromCollection(justs), * args) fun sym0(id: String): ConstraintSymbol = ConstraintSymbol(id, 0) diff --git a/reactor/Test/test/TestStoreAwareJournal.kt b/reactor/Test/test/TestStoreAwareJournal.kt index d827510e..5d292efb 100644 --- a/reactor/Test/test/TestStoreAwareJournal.kt +++ b/reactor/Test/test/TestStoreAwareJournal.kt @@ -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) } } }