braid-core 0.1.4

Unified Braid Protocol implementation in Rust, including Braid-HTTP, Antimatter CRDT, and BraidFS.
Documentation
use super::super::antimatter::AntimatterCrdt;
use super::super::crdt_trait::PrunableCrdt;
use super::super::utils;
use std::collections::HashMap;

pub fn prune<T: PrunableCrdt + Clone>(crdt: &mut AntimatterCrdt<T>, just_checking: bool) -> bool {
    prune_with_time(crdt, just_checking, utils::get_time())
}

pub fn prune_with_time<T: PrunableCrdt + Clone>(
    crdt: &mut AntimatterCrdt<T>,
    just_checking: bool,
    _now: u64,
) -> bool {
    let mut changed = false;

    // Simplified pruning logic for the mock
    // In real antimatter, this would identify bubbles and collapse them
    let mut to_prune = Vec::new();
    for v in crdt.acked_boundary.iter() {
        if let Some(parents) = crdt.t.get(v) {
            for p in parents {
                if !crdt.acked_boundary.contains(p) {
                    to_prune.push(p.clone());
                }
            }
        }
    }

    if !just_checking {
        for v in to_prune {
            if crdt.t.remove(&v).is_some() {
                crdt.crdt.prune(&v);
                changed = true;
            }
        }
    } else {
        changed = !to_prune.is_empty();
    }

    changed
}