Swiftpack.co - bluk/CRDT as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by bluk.
bluk/CRDT v0.3.0
Convergent and Commutative Replicated Data Types implementation in Swift
⭐️ 26
🕓 4 years ago
.package(url: "https://github.com/bluk/CRDT.git", from: "v0.3.0")

CRDT

A Swift package to help build Convergent and Commutative Replicated Data Types.

CRDTs are useful for synchronizing data which eventually converges to a consistent state. CRDTs can be useful when nodes/replicas may not be able to directly communicate with each other. CRDTs can be used instead of an always active foreground synchronization protocol.

Usage

Swift Package Manager

Add this package to your Package.swift dependencies and target's dependencies:

import PackageDescription

let package = Package(
    name: "Example",
    dependencies: [
        .package(
            url: "https://github.com/bluk/CRDT",
            from: "0.1.0"
        ),
    ],
    targets: [
        .target(
            name: "YourProject",
            dependencies: ["CRDT"]
        )
    ]
)

Code

import Foundation

import CRDT

// First system
let actorA = UUID()
var a = GCounter<UUID>()

a.incrementCounter(for: actorA)
// a.value == 1

// Second system
let actorB = UUID()
var b = GCounter<UUID>()

b.incrementCounter(for: actorB)
// b.value == 1

try b.merge(a)
// b.value == 2

a.incrementCounter(for: actorA)
a.incrementCounter(for: actorA)
// a.value == 3

try b.merge(a)
// b.value == 4

See the tests for more examples.

Related Links

CRDT Papers

Other Projects

See other projects which have implementations for CRDTs:

License

Apache-2.0 License

GitHub

link
Stars: 26
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Related Packages

Release Notes

4 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics