Last updated:
0 purchases
hlc
Dart Hybrid Logical Clock (HLC) #
This is a Dart port of the hybrid logical clock implementation described by Jared Forsyth in this article.
HLCs are a useful primitive for CRDT implementations.
Install #
In pubspec.yaml:
dependencies:
hlc: ^1.0.0
copied to clipboard
Usage #
Import the library:
import 'package:hlc/hlc.dart';
copied to clipboard
Initialize a local HLC with the current wall clock:
var hlc = HLC.now();
copied to clipboard
Perform a local action that requires advancing the local HLC:
hlc = hlc.increment();
copied to clipboard
Receive a remote HLC, applying it to the local one:
final remoteHlc = HLC.now(); // From somewhere in the network.
hlc = hlc.receive(remoteHlc);
copied to clipboard
Serialize/deserialize an HLC while maintaining its topological ordering:
final serialized = hlc.pack();
final deserialized = HLC.unpack(serialized);
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.