Introduce an abstraction layer of type aliases for persistent collections.
This commit is contained in:
parent
04164e1039
commit
8ce96ec41e
|
|
@ -16,11 +16,11 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core
|
||||
|
||||
import com.github.andrewoma.dexx.collection.Maps
|
||||
import com.github.andrewoma.dexx.collection.Map as PersMap
|
||||
import jetbrains.mps.logic.reactor.evaluation.ConstraintOccurrence
|
||||
import jetbrains.mps.logic.reactor.logical.MetaLogical
|
||||
import jetbrains.mps.logic.reactor.program.Constraint
|
||||
import jetbrains.mps.logic.reactor.util.Maps
|
||||
import jetbrains.mps.logic.reactor.util.PersMap
|
||||
|
||||
/**
|
||||
* Abstracts an algorithm for recursive matching of a [Constraint] and a [ConstraintOccurrence]
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import jetbrains.mps.logic.reactor.program.IncrementalProgramSpec
|
|||
import jetbrains.mps.logic.reactor.program.Predicate
|
||||
import jetbrains.mps.logic.reactor.util.Profiler
|
||||
import jetbrains.mps.logic.reactor.util.profile
|
||||
import com.github.andrewoma.dexx.collection.Map as PersMap
|
||||
|
||||
internal class ControllerImpl (
|
||||
val supervisor: Supervisor,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core.internal
|
||||
|
||||
import com.github.andrewoma.dexx.collection.Maps
|
||||
import jetbrains.mps.logic.reactor.core.OccurrenceMatcher
|
||||
import jetbrains.mps.logic.reactor.core.Subst
|
||||
import jetbrains.mps.logic.reactor.core.emptySubst
|
||||
|
|
@ -26,7 +25,6 @@ import jetbrains.mps.logic.reactor.logical.LogicalOwner
|
|||
import jetbrains.mps.logic.reactor.logical.MetaLogical
|
||||
import jetbrains.mps.logic.reactor.program.Constraint
|
||||
import jetbrains.mps.unification.Term
|
||||
import java.util.*
|
||||
|
||||
internal class OccurrenceMatcherImpl(val contextSubst: Subst? = null) : OccurrenceMatcher {
|
||||
|
||||
|
|
|
|||
|
|
@ -16,17 +16,12 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core.internal
|
||||
|
||||
import com.github.andrewoma.dexx.collection.Sets
|
||||
import gnu.trove.list.TIntList
|
||||
import gnu.trove.list.array.TIntArrayList
|
||||
import gnu.trove.set.hash.TIntHashSet
|
||||
import jetbrains.mps.logic.reactor.core.*
|
||||
import jetbrains.mps.logic.reactor.program.Constraint
|
||||
import jetbrains.mps.logic.reactor.program.Rule
|
||||
import jetbrains.mps.logic.reactor.util.*
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
import com.github.andrewoma.dexx.collection.Set as PersSet
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,12 +16,7 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.core.internal
|
||||
|
||||
import com.github.andrewoma.dexx.collection.ConsList
|
||||
import com.github.andrewoma.dexx.collection.Map as PersMap
|
||||
import com.github.andrewoma.dexx.collection.Maps
|
||||
import jetbrains.mps.logic.reactor.core.*
|
||||
import jetbrains.mps.logic.reactor.core.Dispatcher.DispatchingFront
|
||||
import jetbrains.mps.logic.reactor.evaluation.RuleMatch
|
||||
import jetbrains.mps.logic.reactor.logical.Logical
|
||||
import jetbrains.mps.logic.reactor.util.*
|
||||
|
||||
|
|
@ -41,7 +36,7 @@ import jetbrains.mps.logic.reactor.util.*
|
|||
|
||||
internal class StateFrame constructor() : LogicalObserver
|
||||
{
|
||||
private var observers: PersMap<Id<Logical<*>>, ConsList<LogicalObserver>> = Maps.of()
|
||||
private var observers: PersMap<Id<Logical<*>>, PersList<LogicalObserver>> = Maps.of()
|
||||
|
||||
constructor(prototype: StateFrame) : this() {
|
||||
this.observers = prototype.observers
|
||||
|
|
@ -55,7 +50,7 @@ internal class StateFrame constructor() : LogicalObserver
|
|||
fun addForwardingObserver(logical: Logical<*>, observer: LogicalObserver) {
|
||||
val logicalId = Id(logical)
|
||||
this.observers = observers.put(logicalId,
|
||||
observers[logicalId]?.prepend(observer) ?: cons(observer))
|
||||
observers[logicalId]?.prepend(observer) ?: Lists.of(observer))
|
||||
}
|
||||
|
||||
fun removeForwardingObserver(logical: Logical<*>, observer: LogicalObserver) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2014-2019 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package jetbrains.mps.logic.reactor.util
|
||||
|
||||
import com.github.andrewoma.dexx.collection.ConsList as DexxCollectionConsList
|
||||
import com.github.andrewoma.dexx.collection.Map as DexxCollectionMap
|
||||
import com.github.andrewoma.dexx.collection.Maps as DexxCollectionMaps
|
||||
import com.github.andrewoma.dexx.collection.Set as DexxCollectionSet
|
||||
import com.github.andrewoma.dexx.collection.Sets as DexxCollectionSets
|
||||
|
||||
/**
|
||||
* Definition of types used as persistent collections.
|
||||
*
|
||||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
typealias PersList<T> = DexxCollectionConsList<T>
|
||||
|
||||
typealias PersMap<K, V> = DexxCollectionMap<K, V>
|
||||
|
||||
typealias PersSet<T> = DexxCollectionSet<T>
|
||||
|
||||
interface Lists {
|
||||
companion object {
|
||||
fun <T> of() = DexxCollectionConsList.empty<T>()
|
||||
fun <T> of(t: T) = DexxCollectionConsList.empty<T>().append(t)
|
||||
}
|
||||
}
|
||||
|
||||
interface Maps {
|
||||
companion object {
|
||||
fun <K,V> of() = DexxCollectionMaps.of<K,V>()
|
||||
fun <K,V> of(k: K, v: V) = DexxCollectionMaps.of<K,V>(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
interface Sets {
|
||||
companion object {
|
||||
fun <T> of() = DexxCollectionSets.of<T>()
|
||||
fun <T> of(t: T) = DexxCollectionSets.of<T>(t)
|
||||
fun <T> copyOf(it: Iterable<T>) = DexxCollectionSets.copyOf<T>(it)
|
||||
}
|
||||
}
|
||||
|
|
@ -22,34 +22,6 @@ import com.github.andrewoma.dexx.collection.ConsList
|
|||
* @author Fedor Isakov
|
||||
*/
|
||||
|
||||
|
||||
fun <E> emptyConsList(): ConsList<E> = ConsList.empty()
|
||||
|
||||
fun <E> cons(e: E): ConsList<E> = emptyConsList<E>().append(e)
|
||||
|
||||
fun <E> consListOf(vararg args: E): ConsList<E> {
|
||||
val builder = ConsList.factory<E>().newBuilder()
|
||||
for (e in args) {
|
||||
builder.add(e)
|
||||
}
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun <E> Sequence<E>.prependTo(toList: ConsList<E>): ConsList<E> =
|
||||
fold(toList) { list, e -> list.prepend(e) }
|
||||
|
||||
fun <E> Sequence<E>.toConsList(): ConsList<E> {
|
||||
val builder = ConsList.factory<E>().newBuilder()
|
||||
val var2 = iterator()
|
||||
|
||||
while (var2.hasNext()) {
|
||||
val e = var2.next()
|
||||
builder.add(e)
|
||||
}
|
||||
|
||||
return builder.build()
|
||||
}
|
||||
|
||||
fun <E> ConsList<E>.removeAt(idx: Int): ConsList<E> {
|
||||
if (idx < 0) throw IllegalArgumentException("index < 0")
|
||||
val left = this.take(idx)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.github.andrewoma.dexx.collection.DerivedKeyHashMap
|
|||
import com.github.andrewoma.dexx.collection.KeyFunction
|
||||
import com.github.andrewoma.dexx.collection.internal.base.AbstractSet
|
||||
|
||||
@Deprecated("obsolete, avoid using in new code")
|
||||
class IdHashSet<E> : AbstractSet<E> {
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -16,9 +16,6 @@
|
|||
|
||||
package jetbrains.mps.logic.reactor.util
|
||||
|
||||
import com.github.andrewoma.dexx.collection.ConsList
|
||||
import com.github.andrewoma.dexx.collection.Map as PersMap
|
||||
import com.github.andrewoma.dexx.collection.Maps
|
||||
import jetbrains.mps.unification.Term
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
|
@ -84,7 +81,7 @@ class PersistentTermTrie<T>() : TermTrie<T> {
|
|||
|
||||
private fun putValue(matchTerm: Term, value: T): PathNode<T> {
|
||||
val seen = IdentityHashMap<Term, Term>()
|
||||
var nodeStack: ConsList<PathNode<T>> = cons(root)
|
||||
var nodeStack: PersList<PathNode<T>> = Lists.of(root)
|
||||
val termList = arrayListOf(matchTerm)
|
||||
|
||||
while (!termList.isEmpty()) {
|
||||
|
|
@ -108,7 +105,7 @@ class PersistentTermTrie<T>() : TermTrie<T> {
|
|||
|
||||
private fun removeValue(matchTerm: Term, value: T): PathNode<T> {
|
||||
val seen = IdentityHashMap<Term, Term>()
|
||||
var nodeStack: ConsList<PathNode<T>> = cons(root)
|
||||
var nodeStack: PersList<PathNode<T>> = Lists.of(root)
|
||||
val termStack = arrayListOf(matchTerm)
|
||||
|
||||
while (!termStack.isEmpty()) {
|
||||
|
|
@ -146,7 +143,7 @@ class PersistentTermTrie<T>() : TermTrie<T> {
|
|||
*/
|
||||
private fun visitMatching(pattern: Term, visitor: (T) -> Unit) {
|
||||
val seen = IdentityHashMap<Term, Term>()
|
||||
val visitStack = arrayListOf(root to cons(pattern))
|
||||
val visitStack = arrayListOf(root to Lists.of(pattern))
|
||||
|
||||
while (!visitStack.isEmpty()) {
|
||||
val (node, patternTerms) = visitStack.pop()
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import com.github.andrewoma.dexx.collection.Maps
|
||||
import jetbrains.mps.logic.reactor.core.*
|
||||
import jetbrains.mps.logic.reactor.core.internal.createOccurrenceMatcher
|
||||
import jetbrains.mps.logic.reactor.core.internal.logical
|
||||
import jetbrains.mps.logic.reactor.program.ConstraintSymbol
|
||||
import jetbrains.mps.logic.reactor.program.ConstraintSymbol.symbol
|
||||
import jetbrains.mps.logic.reactor.util.Maps
|
||||
import jetbrains.mps.unification.Term
|
||||
import jetbrains.mps.unification.test.MockTerm.*
|
||||
import jetbrains.mps.unification.test.MockTermsParser.*
|
||||
|
|
|
|||
Loading…
Reference in New Issue