minerva 0.2.0

Causal ordering for distributed systems
//! Scenario tests: the composed editor exercised through realistic sessions.
//!
//! Each expected order is derived from the semantics, not from running the code
//! twice. Rank determinism comes from `src/metis/tests/support.rs`: each
//! replica's clock uses a fresh [`TickCounter`](crate::kairos::TickCounter), so
//! the `k`-th rank mints at physical `k - 1`, logical `0`, and the replica's
//! station id. [`Rhapsody::order`](crate::metis::Rhapsody::order) walks siblings
//! by descending rank, then dot.

use crate::metis::Dot;

use super::editor::Replica;

mod cursors;
mod gc;
mod text;
mod wire;

/// Types a left-to-right run and returns the final dot as the running cursor.
fn type_run(replica: &mut Replica, text: &str, mut anchor: Option<Dot>) -> Option<Dot> {
    for ch in text.chars() {
        let dot = replica.insert(ch, anchor);
        anchor = Some(dot);
    }
    anchor
}

/// Mutable access to two distinct replicas for a gossip step.
fn split_two(replicas: &mut [Replica], from: usize, into: usize) -> (&Replica, &mut Replica) {
    assert_ne!(from, into);
    if from < into {
        let (left, right) = replicas.split_at_mut(into);
        (&left[from], &mut right[0])
    } else {
        let (left, right) = replicas.split_at_mut(from);
        (&right[0], &mut left[into])
    }
}