Skip to content
Permalink
Browse files

Refactoring Causal CRDTs

(Takes more of an OO approach, rather than an FP with tons of ad hoc typeclasses)
  • Loading branch information...
mboogerd committed Oct 17, 2017
1 parent c28b322 commit bee67ce107d36419795b929355eb22832e1f2cd1
Showing with 1,309 additions and 1,450 deletions.
  1. +2 −2 README.md
  2. +0 −21 crdt/src/main/scala/io/demograph/crdt/CrdtApp.scala
  3. +6 −4 crdt/src/main/scala/io/demograph/crdt/{syntax/package.scala → Session.scala}
  4. +0 −239 crdt/src/main/scala/io/demograph/crdt/VersionVector.scala
  5. +3 −2 crdt/src/main/scala/io/demograph/crdt/delta/causal/Causal.scala
  6. +15 −35 crdt/src/main/scala/io/demograph/crdt/delta/causal/CausalCRDT.scala
  7. +81 −19 crdt/src/main/scala/io/demograph/crdt/delta/causal/CausalContext.scala
  8. +33 −48 crdt/src/main/scala/io/demograph/crdt/delta/causal/CausalInstances.scala
  9. +11 −3 crdt/src/main/scala/io/demograph/crdt/delta/{CompressedDots.scala → causal/package.scala}
  10. +4 −2 crdt/src/main/scala/io/demograph/crdt/delta/dot/CompactDotSet.scala
  11. +12 −10 crdt/src/main/scala/io/demograph/crdt/delta/dot/DotFun.scala
  12. +0 −51 crdt/src/main/scala/io/demograph/crdt/delta/dot/DotInstances.scala
  13. +6 −6 crdt/src/main/scala/io/demograph/crdt/delta/dot/DotMap.scala
  14. +8 −8 crdt/src/main/scala/io/demograph/crdt/delta/dot/DotSet.scala
  15. +4 −6 crdt/src/main/scala/io/demograph/crdt/delta/dot/DotStore.scala
  16. +37 −0 crdt/src/main/scala/io/demograph/crdt/delta/dot/Dotted.scala
  17. +0 −37 crdt/src/main/scala/io/demograph/crdt/delta/graph/GraphInstances.scala
  18. +0 −87 crdt/src/main/scala/io/demograph/crdt/delta/graph/RWGraph.scala
  19. +0 −24 crdt/src/main/scala/io/demograph/crdt/delta/graph/RWHyperGraph.scala
  20. +0 −53 crdt/src/main/scala/io/demograph/crdt/delta/map/ORMap.scala
  21. +0 −50 crdt/src/main/scala/io/demograph/crdt/delta/register/MVRegister.scala
  22. +0 −86 crdt/src/main/scala/io/demograph/crdt/delta/set/AWSet.scala
  23. +0 −41 crdt/src/main/scala/io/demograph/crdt/delta/set/CRDTSetInstances.scala
  24. +0 −66 crdt/src/main/scala/io/demograph/crdt/delta/set/RWSet.scala
  25. +75 −0 crdt/src/main/scala/io/demograph/crdt/implicits/AWSetImplicits.scala
  26. +9 −1 crdt/src/main/scala/io/demograph/crdt/implicits/AllImplicits.scala
  27. +0 −58 crdt/src/main/scala/io/demograph/crdt/implicits/CausalCRDTImplicits.scala
  28. +8 −7 crdt/src/main/scala/io/demograph/crdt/implicits/CausalImplicits.scala
  29. +35 −5 crdt/src/main/scala/io/demograph/crdt/implicits/DotImplicits.scala
  30. +45 −0 crdt/src/main/scala/io/demograph/crdt/implicits/EWFlagImplicits.scala
  31. +45 −0 crdt/src/main/scala/io/demograph/crdt/implicits/MVRegisterImplicits.scala
  32. +54 −0 crdt/src/main/scala/io/demograph/crdt/implicits/ORMapImplicits.scala
  33. +80 −0 crdt/src/main/scala/io/demograph/crdt/implicits/RWSetImplicits.scala
  34. +12 −6 crdt/src/main/scala/io/demograph/crdt/{syntax/JoinSyntax.scala → implicits/ShimImplicits.scala}
  35. +10 −1 crdt/src/main/scala/io/demograph/crdt/implicits/package.scala
  36. +41 −0 crdt/src/main/scala/io/demograph/crdt/instances/AWSet.scala
  37. +15 −11 crdt/src/main/scala/io/demograph/crdt/{delta/flag → instances}/EWFlag.scala
  38. +51 −0 crdt/src/main/scala/io/demograph/crdt/instances/MVRegister.scala
  39. +21 −8 crdt/src/main/scala/io/demograph/crdt/{delta/map/ORMapInstances.scala → instances/ORMap.scala}
  40. +82 −0 crdt/src/main/scala/io/demograph/crdt/instances/RWGraph.scala
  41. +38 −0 crdt/src/main/scala/io/demograph/crdt/instances/RWSet.scala
  42. +63 −0 crdt/src/main/scala/io/demograph/crdt/instances/SetCRDT.scala
  43. +0 −21 crdt/src/main/scala/io/demograph/crdt/syntax/AllSyntax.scala
  44. +0 −101 crdt/src/main/scala/io/demograph/crdt/syntax/SemilatticeSyntax.scala
  45. +10 −4 crdt/src/main/scala/io/demograph/crdt/{syntax/DeltaSyntax.scala → util/Empty.scala}
  46. +12 −15 crdt/src/test/scala/io/demograph/crdt/TestSpec.scala
  47. +36 −39 crdt/src/test/scala/io/demograph/crdt/delta/AWSetTest.scala
  48. +0 −47 crdt/src/test/scala/io/demograph/crdt/delta/CRDTImplicits.scala
  49. +11 −11 ...la/io/demograph/crdt/delta/set/CRDTSet.scala → test/scala/io/demograph/crdt/delta/CRDTSpec.scala}
  50. +50 −59 crdt/src/test/scala/io/demograph/crdt/delta/ORMapTest.scala
  51. +59 −60 crdt/src/test/scala/io/demograph/crdt/delta/RWGraphTest.scala
  52. +2 −6 crdt/src/test/scala/io/demograph/crdt/delta/dot/CompactDotSetTest.scala
  53. +5 −7 crdt/src/test/scala/io/demograph/crdt/gen/AWSetGen.scala
  54. +37 −38 crdt/src/test/scala/io/demograph/crdt/gen/History.scala
  55. +61 −0 crdt/src/test/scala/io/demograph/crdt/util/CRDTTestImplicits.scala
  56. +10 −11 ...elta/flag/EWFlagInstances.scala → test/scala/io/demograph/crdt/util/CompactDotSetImplicits.scala}
  57. +60 −0 crdt/src/test/scala/io/demograph/crdt/util/EventStoreImplicits.scala
  58. +11 −34 crdt/src/test/scala/io/demograph/crdt/util/ScalaTestImplicits.scala
  59. +38 −0 crdt/src/test/scala/io/demograph/crdt/util/package.scala
  60. +1 −0 project/DependenciesConf.scala
@@ -93,6 +93,6 @@ as the Reader signals its demand. As long as there is demand, all writes
(to the given key) are propagated opportunistically. The very first
element produced will reflect the entire state up to the point that
demand was first signaled; no optimization takes place in the form of
splitting it up in bite-size chunks (if you are creating a `Set` that
fills your entire memory, that `Set` will be passed to the Reader).
splitting it up in bite-size chunks (if you are creating a `SetCRDT` that
fills your entire memory, that `SetCRDT` will be passed to the Reader).

This file was deleted.

Oops, something went wrong.
@@ -16,11 +16,13 @@

package io.demograph.crdt

import simulacrum.typeclass

/**
*
*/
package object syntax {
object all extends AllSyntax
object joinSyntax extends JoinSyntax
object semilatticeSyntax extends SemilatticeSyntax
// $COVERAGE-OFF$ Generated typeclasses do not require test-coverage
@typeclass trait Session[H] {
def localhost: H
}
// $COVERAGE-ON$

This file was deleted.

Oops, something went wrong.
@@ -17,10 +17,11 @@
package io.demograph.crdt.delta.causal

import algebra.lattice.BoundedJoinSemilattice
import io.demograph.crdt.delta.dot.DotStore

/**
* A Causal type is the product of a DotStore and a CausalContext. We are more lenient than the paper in not
* requiring it actually being a DotStore instance. This eases the creation of derived Causal instances, such as
* using a product of two DotStores as the dotStore instance.
* using a product of two DotStores as the eventStore instance.
*/
trait Causal[I, DS] extends BoundedJoinSemilattice[(DS, CausalContext[I])]
trait Causal[E, DS <: DotStore[E]] extends BoundedJoinSemilattice[(DS, CausalContext[E])]
@@ -16,43 +16,23 @@

package io.demograph.crdt.delta.causal

import algebra.lattice.BoundedJoinSemilattice
import io.demograph.crdt.delta.dot.DotStore

trait CausalCRDT[I, DS, T] {

/**
* Retrieves the instance performing the role of dot-store.
* @param t
* @return
*/
def dotStore(t: T): DS

/**
* Returns the CausalContext for this Causal CRDT
* @param t
* @return
*/
def context(t: T): CausalContext[I]

/**
* Allows the creation of a new instance of T, given a dotStore and causalContext.
* @param dotStore
* @param context
* @return
*/
def instance(dotStore: DS, context: CausalContext[I]): T
}
case class CausalCRDT[E, ES <: DotStore[E]](eventStore: ES, context: CausalContext[E])

object CausalCRDT {

class CausalCRDTBJSL[I, DS, T](implicit causal: Causal[I, DS], crdt: CausalCRDT[I, DS, T]) extends BoundedJoinSemilattice[T] {
override def zero: T = crdt.instance(causal.zero._1, causal.zero._2)

override def join(lhs: T, rhs: T): T = {
val joined: (DS, CausalContext[I]) = causal.join(
(crdt.dotStore(lhs), crdt.context(lhs)),
(crdt.dotStore(rhs), crdt.context(rhs)))
crdt.instance(joined._1, joined._2)
}
}
// A generic representation of a Causal CRDT. This is just the datastructure without any particular operations attached to it
// final case class Generic[E, ES <: DotStore[E]](eventStore: ES, context: CausalContext[E]) extends CausalCRDT[E, ES]

// class CausalCRDTBJSL[E, DS, T](implicit causal: Causal[E, DS], crdt: CausalCRDT[E, DS, T]) extends BoundedJoinSemilattice[T] {
// override def zero: T = crdt.instance(causal.zero._1, causal.zero._2)
//
// override def join(lhs: T, rhs: T): T = {
// val joined: (DS, CausalContext[E]) = causal.join(
// (crdt.eventStore(lhs), crdt.context(lhs)),
// (crdt.eventStore(rhs), crdt.context(rhs)))
// crdt.instance(joined._1, joined._2)
// }
// }
}
Oops, something went wrong.

0 comments on commit bee67ce

Please sign in to comment.
You can’t perform that action at this time.