#timestamp #distributed #tree

treeclocks

Various Tree Clock data-structures and utilities

8 releases (4 breaking)

Uses new Rust 2024

new 0.5.1 Apr 15, 2025
0.5.0 Apr 15, 2025
0.4.2 Feb 23, 2025
0.3.0 Feb 22, 2025
0.1.0 Feb 21, 2025

#315 in Data structures

Download history 462/week @ 2025-02-20 64/week @ 2025-02-27 165/week @ 2025-04-10

165 downloads per month

MIT/Apache

31KB
760 lines

Tree Clocks

Various Tree Clock data structures including the original Interval Tree Clock data structure from the 2008 paper "Interval Tree Clocks: A Logical Clock for Dynamic Systems"[pdf] as well as extensions on the idea.

Features

  • Implementation of the IdTree and EventTree from the original paper
  • A higher-level ItcPair abstraction for ease of use
  • A new ItcIndex to go from EventTree to Set<IdTree>

Usage

Add to your Cargo.toml:

$ cargo add treeclocks

ItcPair

The ItcPair provides a higher-level abstraction around the IdTree and EventTree data-structures.

use treeclocks::ItcPair;

let mut n0 = ItcPair::new();
let mut n1 = n0.fork();
let mut n2 = n1.fork();

n0.event();
n0.event();
n2.event();

// Sync to update the `EventTree` without merging `IdTree`s
n1.sync(&n2.timestamp);

// Join to merge both `EventTree` and `IdTree`s
n0.join(n2);

assert!(n0.timestamp > n1.timestamp);

ItcMap

The ItcMap provides an in-memory key-value store with operations to keep the map in sync with minimal overhead in a distributed system.

use treeclocks::{IdTree, ItcMap};

let mut map_a = ItcMap::new();
let mut map_b = ItcMap::new();

let id_a = IdTree::new();
let (id_a, id_b) = id_a.fork();

map_a.insert(id_a.clone(), 207);
map_b.insert(id_b.clone(), 324);

let patch_for_b = map_a.diff(map_b.timestamp());
let patch_for_a = map_b.diff(map_a.timestamp());

map_a.apply(patch_for_a);
map_b.apply(patch_for_b);

assert_eq!(map_a, map_b)

License

Licensed under either of:

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~155KB