Skip to content

Commit

Permalink
Remove merged method requirement on CvRDT
Browse files Browse the repository at this point in the history
  • Loading branch information
bluk committed Sep 28, 2019
1 parent 48a63f6 commit b69d192
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 9 deletions.
9 changes: 0 additions & 9 deletions Sources/CRDT/CvRDT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,4 @@ public protocol CvRDT: PartialOrderable {
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
mutating func merge(_ other: Self) throws

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
func merged(_ other: Self) throws -> Self
}
7 changes: 7 additions & 0 deletions Sources/CRDT/VClock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ extension VClock: CvRDT {
}
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: VClock<Actor, Clock>) throws -> VClock<Actor, Clock> {
var copy = self
try copy.merge(other)
Expand Down
7 changes: 7 additions & 0 deletions Sources/CRDTCounters/GCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ extension GCounter: CvRDT {
try self.actorCounters.merge(other.actorCounters)
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: GCounter<Actor>) throws -> GCounter<Actor> {
var copy = self
try copy.merge(other)
Expand Down
7 changes: 7 additions & 0 deletions Sources/CRDTRegisters/LWWRegister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ extension LWWRegister: CvRDT {
try self.assign(value: other.value, timestamp: other.timestamp)
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: LWWRegister<Value, Timestamp>) throws -> LWWRegister<Value, Timestamp> {
var copy = self
try copy.merge(other)
Expand Down
7 changes: 7 additions & 0 deletions Sources/CRDTRegisters/MVRegister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ extension MVRegister: CvRDT {
self.values = keptSelfValues
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: MVRegister<Value, Actor, Clock>) throws -> MVRegister<Value, Actor, Clock> {
var copy = self
try copy.merge(other)
Expand Down
7 changes: 7 additions & 0 deletions Sources/CRDTSets/GSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ extension GSet: CvRDT {
self.formUnion(other)
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: GSet<Element>) throws -> GSet<Element> {
var copy = self
try copy.merge(other)
Expand Down
7 changes: 7 additions & 0 deletions Sources/CRDTSets/TwoPhaseSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ extension TwoPhaseSet: CvRDT {
self.removedElements.formUnion(other.removedElements)
}

/// An idempotent and commutative function which attempts to produce a new instance with the
/// other instance's state merged with this instance's state.
///
/// - Parameter other: The other instance
/// - Throws: Throws an error if the states could not be merged.
/// - Returns: A new instance which is the result of merging this instance's state with the
/// other instance's state.
public func merged(_ other: TwoPhaseSet<Element>) throws -> TwoPhaseSet<Element> {
var copy = self
try copy.merge(other)
Expand Down

0 comments on commit b69d192

Please sign in to comment.