GSet ported to delta-CRDT (#22187)

This commit is contained in:
gosubpl 2017-01-26 14:26:25 +01:00
parent 5ffb08cd78
commit d470321051
5 changed files with 80 additions and 20 deletions

View file

@ -51,9 +51,13 @@ class TwoPhaseSetSerializer(val system: ExtendedActorSystem)
def twoPhaseSetFromBinary(bytes: Array[Byte]): TwoPhaseSet = {
val msg = TwoPhaseSetMessages.TwoPhaseSet.parseFrom(bytes)
TwoPhaseSet(
adds = GSet(msg.getAddsList.iterator.asScala.toSet),
removals = GSet(msg.getRemovalsList.iterator.asScala.toSet))
val addsSet = msg.getAddsList.iterator.asScala.toSet
val removalsSet = msg.getRemovalsList.iterator.asScala.toSet
val adds = addsSet.foldLeft(GSet.empty[String])((acc, el) => acc.add(el))
val removals = removalsSet.foldLeft(GSet.empty[String])((acc, el) => acc.add(el))
// GSet will accumulate deltas when adding elements,
// but those are not of interest in the result of the deserialization
TwoPhaseSet(adds.resetDelta, removals.resetDelta)
}
}
//#serializer