@@ -33,48 +33,48 @@ import Distributed
3333///
3434/// - SeeAlso: [Why Logical Clocks are Easy](https://queue.acm.org/detail.cfm?id=2917756)
3535/// - SeeAlso: [Version Vectors are not Vector Clocks](https://haslab.wordpress.com/2011/07/08/version-vectors-are-not-vector-clocks/)
36- public struct VersionVector : Equatable {
36+ internal struct VersionVector : Equatable {
3737 // TODO: should we disallow mixing ReplicaID types somehow?
3838
39- public typealias Version = UInt64
40- public typealias ReplicaVersion = ( replicaID: ReplicaID , version: Version ) // TODO: struct?
39+ typealias Version = UInt64
40+ typealias ReplicaVersion = ( replicaID: ReplicaID , version: Version ) // TODO: struct?
4141
4242 // Internal state is a dictionary of replicas and their corresponding version
4343 internal var state : [ ReplicaID : Version ] = [ : ]
4444
45- public static let empty : VersionVector = . init( )
45+ static let empty : VersionVector = . init( )
4646
47- public static func first( at replicaID: ReplicaID ) -> Self {
47+ static func first( at replicaID: ReplicaID ) -> Self {
4848 . init( ( replicaID, 1 ) )
4949 }
5050
5151 /// Creates an 'empty' version vector.
52- public init ( ) { }
52+ init ( ) { }
5353
54- public init ( _ versionVector: VersionVector ) {
54+ init ( _ versionVector: VersionVector ) {
5555 self . state. merge ( versionVector. state) { _, new in new }
5656 }
5757
58- public init ( _ replicaVersion: ReplicaVersion ) {
58+ init ( _ replicaVersion: ReplicaVersion ) {
5959 self . init ( [ replicaVersion] )
6060 }
6161
62- public init ( _ version: Version , at replicaID: ReplicaID ) {
62+ init ( _ version: Version , at replicaID: ReplicaID ) {
6363 self . init ( [ ( replicaID, version) ] )
6464 }
6565
66- public init ( _ replicaVersions: [ ReplicaVersion ] ) {
66+ init ( _ replicaVersions: [ ReplicaVersion ] ) {
6767 for rv in replicaVersions {
6868 precondition ( rv. version > 0 , " Version must be greater than 0 " )
6969 self . state [ rv. replicaID] = rv. version
7070 }
7171 }
7272
73- public var isEmpty : Bool {
73+ var isEmpty : Bool {
7474 self . state. isEmpty
7575 }
7676
77- public var isNotEmpty : Bool {
77+ var isNotEmpty : Bool {
7878 !self . isEmpty
7979 }
8080
@@ -83,7 +83,7 @@ public struct VersionVector: Equatable {
8383 /// - Parameter replicaID: The replica whose version is to be incremented.
8484 /// - Returns: The replica's version after the increment.
8585 @discardableResult
86- public mutating func increment( at replicaID: ReplicaID ) -> Version {
86+ mutating func increment( at replicaID: ReplicaID ) -> Version {
8787 if let current = self . state [ replicaID] {
8888 let nextVersion = current + 1
8989 self . state [ replicaID] = nextVersion
@@ -94,13 +94,13 @@ public struct VersionVector: Equatable {
9494 }
9595 }
9696
97- public mutating func merge( other: VersionVector ) {
97+ mutating func merge( other: VersionVector ) {
9898 // Take point-wise maximum
9999 self . state. merge ( other. state, uniquingKeysWith: max)
100100 }
101101
102102 /// Prune any trace of the passed in replica id.
103- public func pruneReplica( _ replicaID: ReplicaID ) -> Self {
103+ func pruneReplica( _ replicaID: ReplicaID ) -> Self {
104104 var s = self
105105 s. state. removeValue ( forKey: replicaID)
106106 return s
@@ -110,12 +110,12 @@ public struct VersionVector: Equatable {
110110 ///
111111 /// - Parameter replicaID: The replica whose version is being queried.
112112 /// - Returns: The replica's version or 0 if replica is unknown.
113- public subscript( replicaID: ReplicaID ) -> Version {
113+ subscript( replicaID: ReplicaID ) -> Version {
114114 self . state [ replicaID] ?? 0
115115 }
116116
117117 /// Lists all replica ids that this version vector contains.
118- public var replicaIDs : Dictionary < ReplicaID , Version > . Keys {
118+ var replicaIDs : Dictionary < ReplicaID , Version > . Keys {
119119 self . state. keys
120120 }
121121
@@ -124,7 +124,7 @@ public struct VersionVector: Equatable {
124124 /// - Parameter replicaID: The replica of interest
125125 /// - Parameter version: The version of interest
126126 /// - Returns: True if the replica's version in the `VersionVector` is greater than or equal to `version`. False otherwise.
127- public func contains( _ replicaID: ReplicaID , _ version: Version ) -> Bool {
127+ func contains( _ replicaID: ReplicaID , _ version: Version ) -> Bool {
128128 self [ replicaID] >= version
129129 }
130130
@@ -133,7 +133,7 @@ public struct VersionVector: Equatable {
133133 ///
134134 /// - Parameter that: The `VersionVector` to compare this `VersionVector` to.
135135 /// - Returns: The causal relation between this and the given `VersionVector`.
136- public func compareTo( _ that: VersionVector ) -> CausalRelation {
136+ func compareTo( _ that: VersionVector ) -> CausalRelation {
137137 if self < that {
138138 return . happenedBefore
139139 }
@@ -146,7 +146,7 @@ public struct VersionVector: Equatable {
146146 return . concurrent
147147 }
148148
149- public enum CausalRelation {
149+ enum CausalRelation {
150150 /// X < Y, meaning X → Y or X "happened before" Y
151151 case happenedBefore
152152 /// X > Y, meaning Y → X, or X "happened after" Y
@@ -159,7 +159,7 @@ public struct VersionVector: Equatable {
159159}
160160
161161extension VersionVector : Comparable {
162- public static func < ( lhs: VersionVector , rhs: VersionVector ) -> Bool {
162+ static func < ( lhs: VersionVector , rhs: VersionVector ) -> Bool {
163163 // If lhs is empty but rhs is not, then lhs can only be less than ("happened-before").
164164 // Return false if both lhs and rhs are empty since they are considered the same, not ordered.
165165 if lhs. isEmpty {
@@ -181,13 +181,13 @@ extension VersionVector: Comparable {
181181 return hasAtLeastOneStrictlyLessThan
182182 }
183183
184- public static func == ( lhs: VersionVector , rhs: VersionVector ) -> Bool {
184+ static func == ( lhs: VersionVector , rhs: VersionVector ) -> Bool {
185185 lhs. state == rhs. state
186186 }
187187}
188188
189189extension VersionVector : CustomStringConvertible , CustomPrettyStringConvertible {
190- public var description : String {
190+ var description : String {
191191 " \( self . state) "
192192 }
193193}
@@ -203,13 +203,13 @@ extension VersionVector: Codable {
203203///
204204/// `VersionDot` is in essence `VersionVector.ReplicaVersion` but since tuples cannot conform to protocols and `Version` needs
205205/// to be `Hashable` we have to define a type.
206- public struct VersionDot {
207- public typealias Version = UInt64
206+ internal struct VersionDot {
207+ typealias Version = UInt64
208208
209- public let replicaID : ReplicaID
210- public let version : Version
209+ let replicaID : ReplicaID
210+ let version : Version
211211
212- public init ( _ replicaID: ReplicaID , _ version: Version ) {
212+ init ( _ replicaID: ReplicaID , _ version: Version ) {
213213 self . replicaID = replicaID
214214 self . version = version
215215 }
@@ -219,7 +219,7 @@ extension VersionDot: Hashable {}
219219
220220extension VersionDot : Comparable {
221221 /// Lexical, NOT causal ordering of two dots.
222- public static func < ( lhs: VersionDot , rhs: VersionDot ) -> Bool {
222+ static func < ( lhs: VersionDot , rhs: VersionDot ) -> Bool {
223223 if lhs. replicaID == rhs. replicaID {
224224 return lhs. version < rhs. version
225225 } else {
@@ -229,7 +229,7 @@ extension VersionDot: Comparable {
229229}
230230
231231extension VersionDot : CustomStringConvertible {
232- public var description : String {
232+ var description : String {
233233 " Dot( \( self . replicaID) , \( self . version) ) "
234234 }
235235}
@@ -241,7 +241,7 @@ extension VersionDot: Codable {
241241// ==== ----------------------------------------------------------------------------------------------------------------
242242// MARK: Replica ID
243243
244- public struct ReplicaID : Hashable {
244+ internal struct ReplicaID : Hashable {
245245 internal enum Storage : Hashable {
246246 case actorID( ActorID )
247247 // case actorIdentity(ClusterSystem.ActorID)
@@ -283,19 +283,19 @@ public struct ReplicaID: Hashable {
283283 self . storage = representation
284284 }
285285
286- public static func actor < M: Codable > ( _ context: _ActorContext < M > ) -> ReplicaID {
286+ static func actor < M: Codable > ( _ context: _ActorContext < M > ) -> ReplicaID {
287287 . init( . actorID( context. id) )
288288 }
289289
290290 internal static func actorID( _ id: ActorID ) -> ReplicaID {
291291 . init( . actorID( id) )
292292 }
293293
294- public static func uniqueNode( _ uniqueNode: UniqueNode ) -> ReplicaID {
294+ static func uniqueNode( _ uniqueNode: UniqueNode ) -> ReplicaID {
295295 . init( . uniqueNode( uniqueNode) )
296296 }
297297
298- public static func uniqueNodeID( _ uniqueNode: UniqueNode ) -> ReplicaID {
298+ static func uniqueNodeID( _ uniqueNode: UniqueNode ) -> ReplicaID {
299299 . init( . uniqueNodeID( uniqueNode. nid) )
300300 }
301301
@@ -318,7 +318,7 @@ public struct ReplicaID: Hashable {
318318}
319319
320320extension ReplicaID : CustomStringConvertible {
321- public var description : String {
321+ var description : String {
322322 switch self . storage {
323323 case . actorID( let id) :
324324 return " actor: \( id) "
@@ -331,7 +331,7 @@ extension ReplicaID: CustomStringConvertible {
331331}
332332
333333extension ReplicaID : Comparable {
334- public static func < ( lhs: ReplicaID , rhs: ReplicaID ) -> Bool {
334+ static func < ( lhs: ReplicaID , rhs: ReplicaID ) -> Bool {
335335 switch ( lhs. storage, rhs. storage) {
336336 case ( . actorID( let l) , . actorID( let r) ) :
337337 return l < r
@@ -344,7 +344,7 @@ extension ReplicaID: Comparable {
344344 }
345345 }
346346
347- public static func == ( lhs: ReplicaID , rhs: ReplicaID ) -> Bool {
347+ static func == ( lhs: ReplicaID , rhs: ReplicaID ) -> Bool {
348348 switch ( lhs. storage, rhs. storage) {
349349 case ( . actorID( let l) , . actorID( let r) ) :
350350 return l == r
@@ -366,19 +366,19 @@ extension ReplicaID: Comparable {
366366}
367367
368368extension ReplicaID : Codable {
369- public enum DiscriminatorKeys : String , Codable {
369+ enum DiscriminatorKeys : String , Codable {
370370 case actorID = " a "
371371 case uniqueNode = " N "
372372 case uniqueNodeID = " n "
373373 }
374374
375- public enum CodingKeys : CodingKey {
375+ enum CodingKeys : CodingKey {
376376 case _case
377377
378378 case value
379379 }
380380
381- public init ( from decoder: Decoder ) throws {
381+ init ( from decoder: Decoder ) throws {
382382 let container = try decoder. container ( keyedBy: CodingKeys . self)
383383 switch try container. decode ( DiscriminatorKeys . self, forKey: . _case) {
384384 case . actorID:
@@ -390,7 +390,7 @@ extension ReplicaID: Codable {
390390 }
391391 }
392392
393- public func encode( to encoder: Encoder ) throws {
393+ func encode( to encoder: Encoder ) throws {
394394 var container = encoder. container ( keyedBy: CodingKeys . self)
395395 switch self . storage {
396396 case . actorID( let address) :
0 commit comments