From e3e481e09149a10edca591202554c2cb6faff78b Mon Sep 17 00:00:00 2001 From: ragnar Date: Tue, 3 Dec 2024 14:53:19 +0100 Subject: [PATCH] remove now unused causal queue after it was mutilated. RIP. --- .../src/main/scala/probench/data/Data.scala | 2 +- .../lattices/CausalQueueBench.scala | 44 ------------- .../datatypes/contextual/CausalQueue.scala | 64 ------------------- .../test/scala/test/rdts/DataGenerator.scala | 13 +--- .../LatticePropertyChecks.scala | 2 +- 5 files changed, 3 insertions(+), 122 deletions(-) delete mode 100644 Modules/RDTs/src/main/scala/rdts/datatypes/contextual/CausalQueue.scala diff --git a/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/data/Data.scala b/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/data/Data.scala index b3f6f1975..7c6f9c863 100644 --- a/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/data/Data.scala +++ b/Modules/Examples/Protocol Benchmarks/src/main/scala/probench/data/Data.scala @@ -1,7 +1,7 @@ package probench.data import rdts.base.{Bottom, Lattice, Uid} -import rdts.datatypes.contextual.{CausalQueue, ReplicatedSet} +import rdts.datatypes.contextual.{ReplicatedSet} import rdts.dotted.{Dotted, Obrem} import rdts.time.Dot diff --git a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala index 9461fc10a..77fce735c 100644 --- a/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala +++ b/Modules/Microbenchmarks/src/main/scala/benchmarks/lattices/CausalQueueBench.scala @@ -1,55 +1,11 @@ package benchmarks.lattices import org.openjdk.jmh.annotations.* -import rdts.base.LocalUid.asId import rdts.datatypes.alternatives.rga.Sequence import rdts.datatypes.alternatives.rga.Sequence.{RGA, RGAOps} -import rdts.datatypes.contextual.CausalQueue -import rdts.dotted.Dotted import java.util.concurrent.TimeUnit -@BenchmarkMode(Array(Mode.AverageTime)) -@OutputTimeUnit(TimeUnit.MILLISECONDS) -@Warmup(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS) -@Measurement(iterations = 3, time = 1000, timeUnit = TimeUnit.MILLISECONDS) -@Fork(3) -@Threads(1) -@State(Scope.Thread) -class CausalQueueBench { - - @Param(Array("100", "1000", "10000", "100000")) - var size: Int = scala.compiletime.uninitialized - - @Param(Array("10000")) - var operations: Int = scala.compiletime.uninitialized - - var lca: Dotted[CausalQueue[Int]] = scala.compiletime.uninitialized - - @Setup - def setup(): Unit = { - lca = (1 to size).foldLeft(Dotted(CausalQueue.empty[Int])) { (q, e) => q.mod(_.enqueue(using "lca".asId)(e)) } - } - - def make(base: Dotted[CausalQueue[Int]], ops: Int, prefix: String) = { - val s = ops / 2 - val added = (1 to s).foldLeft(base) { (acc, v) => acc `merge` acc.mod(_.enqueue(using prefix.asId)(v)) } - (1 to s).foldLeft(added) { (acc, _) => acc `merge` acc.mod(_.dequeue()) } - } - - @Benchmark - def create(): Dotted[CausalQueue[Int]] = make(lca, operations, "") - - @Benchmark - def createAndMerge(): Dotted[CausalQueue[Int]] = { - val left = make(lca, operations, "left") - val right = make(lca, operations, "right") - - val res = left `merge` right - res - } - -} @BenchmarkMode(Array(Mode.AverageTime)) @OutputTimeUnit(TimeUnit.MILLISECONDS) diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/CausalQueue.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/CausalQueue.scala deleted file mode 100644 index 8a96ff5de..000000000 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/contextual/CausalQueue.scala +++ /dev/null @@ -1,64 +0,0 @@ -package rdts.datatypes.contextual - -import rdts.base.{Bottom, Lattice, LocalUid} -import rdts.datatypes.contextual.CausalQueue.QueueElement -import rdts.dotted.{Dotted, HasDots} -import rdts.time.{Dot, Dots, VectorClock} - -import scala.collection.immutable.Queue - -case class CausalQueue[T](values: Queue[QueueElement[T]], clock: VectorClock) { - - type Delta = Dotted[CausalQueue[T]] - - def enqueue(using LocalUid)(e: T)(using context: Dots): Delta = - val time = clock.merge(clock.inc(LocalUid.replicaId)) - val dot = time.dotOf(LocalUid.replicaId) - Dotted(CausalQueue(Queue(QueueElement(e, dot, time)), time), Dots.single(dot)) - - def head: T = - val QueueElement(e, _, _) = values.head - e - - def dequeue(): Delta = - val QueueElement(_, dot, _) = values.head - Dotted(CausalQueue.empty, Dots.single(dot)) - - def removeBy(p: T => Boolean): Delta = - val toRemove = values.filter(e => p(e.value)).map(_.dot) - Dotted(CausalQueue.empty, Dots.from(toRemove)) - - def elements: Queue[T] = - values.map(_.value) - -} - -object CausalQueue: - case class QueueElement[+T](value: T, dot: Dot, order: VectorClock) - - given elementLattice[T]: Lattice[QueueElement[T]] with { - override def merge(left: QueueElement[T], right: QueueElement[T]): QueueElement[T] = - if left.order < right.order then right else left - } - - def empty[T]: CausalQueue[T] = CausalQueue(Queue(), VectorClock.zero) - - given hasDots[A]: HasDots[CausalQueue[A]] with { - extension (value: CausalQueue[A]) - override def dots: Dots = Dots.from(value.values.view.map(_.dot)) - - override def removeDots(dots: Dots): Option[CausalQueue[A]] = - Some(CausalQueue(value.values.filter(qe => !dots.contains(qe.dot)), value.clock)) - } - - given bottomInstance[T]: Bottom[CausalQueue[T]] = Bottom.derived - - given lattice[A]: Lattice[CausalQueue[A]] with { - override def merge(left: CausalQueue[A], right: CausalQueue[A]): CausalQueue[A] = - CausalQueue( - (left.values concat right.values) - .sortBy { qe => qe.order }(using Ordering.fromLessThan(VectorClock.vectorClockOrdering.lt)).distinct, - left.clock.merge(right.clock) - ) - - } diff --git a/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala b/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala index f1d888d5a..57377a7ad 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/DataGenerator.scala @@ -6,7 +6,6 @@ import rdts.datatypes.* import rdts.datatypes.GrowOnlyList.Node import rdts.datatypes.alternatives.{MultiValueRegister, ObserveRemoveSet} import rdts.datatypes.contextual.* -import rdts.datatypes.contextual.CausalQueue.QueueElement import rdts.datatypes.experiments.AutomergyOpGraphLWW.OpGraph import rdts.datatypes.experiments.{CausalDelta, CausalStore} import rdts.dotted.* @@ -83,17 +82,7 @@ object DataGenerator { val map = Gen.listOf(pairgen).map(vs => MultiValueRegister(vs.toMap)) Arbitrary(map) - given arbCausalQueue[A: Arbitrary]: Arbitrary[CausalQueue[A]] = - Arbitrary { - Gen.listOf( - Gen.zip(uniqueDot, Arbitrary.arbitrary[A]) - ).map { list => - val queue = Queue.from(list.map((dot, value) => { - QueueElement(value, dot, VectorClock(Map(dot.place -> dot.time))) - })) - CausalQueue(queue, VectorClock(queue.map(it => it.dot.place -> it.dot.time).toMap)) - } - } + val genDot: Gen[Dot] = for diff --git a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala index b21f1d580..e6e320b82 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/baseproperties/LatticePropertyChecks.scala @@ -6,7 +6,7 @@ import org.scalacheck.Prop.* import org.scalacheck.{Arbitrary, Shrink} import rdts.base.{Bottom, BottomOpt, Lattice, Decompose} import rdts.datatypes.alternatives.{MultiValueRegister, ObserveRemoveSet} -import rdts.datatypes.contextual.{CausalQueue, ReplicatedList} +import rdts.datatypes.contextual.{ReplicatedList} import rdts.datatypes.experiments.AutomergyOpGraphLWW.OpGraph import rdts.datatypes.experiments.CausalStore import rdts.datatypes.{GrowOnlyCounter, GrowOnlyList, GrowOnlyMap, LastWriterWins, PosNegCounter, TwoPhaseSet, contextual}