minerva 0.2.0

Causal ordering for distributed systems
use super::page::Page;

/// Gossips the whole order state from `from` to `into`.
pub fn gossip_order(from: &Page, into: &mut Page) {
    let delta = from.order.owed_to(into.order_context());
    let _ = into.order.absorb(from.station(), &delta);
}

/// Gossips the whole field state from `from` to `into`.
pub fn gossip_fields(from: &Page, into: &mut Page) {
    let delta = from.fields.owed_to(into.fields_context());
    let _ = into.fields.absorb(from.station(), &delta);
}

/// Gossips the whole paragraph state from `from` to `into`, carrying char
/// payloads (the out-of-band payload channel, the editor precedent).
pub fn gossip_para(from: &Page, into: &mut Page) {
    let delta = from.para.owed_to(into.para_context());
    let _ = into.para.absorb(from.station(), &delta);
    for (dot, ch) in from.chars() {
        let _ = into.chars.entry(*dot).or_insert(*ch);
    }
}

/// Gossips the whole table state from `from` to `into`.
pub fn gossip_table(from: &Page, into: &mut Page) {
    let delta = from.table.owed_to(into.table_context());
    let _ = into.table.absorb(from.station(), &delta);
}

/// Gossips all four pairs: the quiescing sweep. Deliberately *not* atomic
/// (four deltas, four merges); the coherence scripts deliver the pairs
/// selectively to open exactly the windows this sweep closes.
pub fn gossip_page(from: &Page, into: &mut Page) {
    gossip_order(from, into);
    gossip_fields(from, into);
    gossip_para(from, into);
    gossip_table(from, into);
}