minerva 0.2.0

Causal ordering for distributed systems
extern crate alloc;

use super::super::support::dot;
use crate::metis::{Dot, DotMap, DotSet, Dotted};

mod exchange;
mod law_breaking;
mod write;

/// The observed-remove document shape the examples exercise: caller keys over
/// bare presence dots.
type Doc = DotMap<u8, DotSet>;

/// A one-dot set, for building write deltas declaratively.
fn dots(pairs: &[(u32, u64)]) -> DotSet {
    let mut set = DotSet::new();
    for &(station, counter) in pairs {
        assert!(set.insert(dot(station, counter)));
    }
    set
}

/// A pure-add weave under `key`: the fresh dot's content, superseding nothing.
fn add_under(key: u8) -> impl FnOnce(Dot) -> (Doc, DotSet) {
    move |assigned| {
        let store = DotMap::singleton(key, dots(&[(assigned.station(), assigned.counter())]));
        (store, DotSet::new())
    }
}

/// Rebuilds a delta from its own read-back parts and asserts the parts form a
/// covered pair: the coveredness guarantee, checked from the outside.
fn assert_covered(delta: &Dotted<Doc>) {
    let rebuilt = Dotted::try_new(delta.store().clone(), delta.context().clone());
    assert!(
        rebuilt.is_ok(),
        "the facade's delta is covered by construction"
    );
}