Skip to content

CRDT which holds a vector clock sorted array of operations, supporting append, merge and serialization.

License

Notifications You must be signed in to change notification settings

schwmi/OperationLog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OperationLog

… is a CRDT which holds a vector clock sorted array of operations, and a provides snapshots as representation of applied/reduced operations. It supports methods for merging two logs and for appending new operations. Furthermore, containerized operations from one log can be inserted in bunch into another related log. By doing so - given the common order which is guaranteed by the vector clock - state can be synced between multiple OperationLog instances.

Usage

For using the log you have to implement the LogOperation and Snapshot protocol. Snapshot is the type into which LogOperations are reduced into. e.g. if the snapshot representation is a string, the suitable operation could contain types for adding and removing characters. Both protocol implementations should be structs.

Create a new log

let stringSnapshot = StringSnapshot("") // StringSnapshot is an implementation of the `Snapshot` protocol
let log = OperationLog(logID: "XYZ", actorID: "A", initialSnapshot: stringSnapshot)

Append operations

[…]
let addCharacterOperation = CharacterOperation(kind: .append, character: "A") // CharacterOperation implements `LogOperation` protocol
log.append(addCharacterOperation)

Merging Logs

[…]
logA.merge(logB) // merges logB's content into logA

Serialize / Deserialize a log

[…]
let logData = try log.serialize()
let deserializedLog = try OperationLog(actorID: "A", data: logData)

About

CRDT which holds a vector clock sorted array of operations, supporting append, merge and serialization.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages