braid_core/antimatter/algorithm/
prune.rs1use super::super::antimatter::AntimatterCrdt;
2use super::super::crdt_trait::PrunableCrdt;
3use super::super::utils;
4use std::collections::HashMap;
5
6pub fn prune<T: PrunableCrdt + Clone>(crdt: &mut AntimatterCrdt<T>, just_checking: bool) -> bool {
7 prune_with_time(crdt, just_checking, utils::get_time())
8}
9
10pub fn prune_with_time<T: PrunableCrdt + Clone>(
11 crdt: &mut AntimatterCrdt<T>,
12 just_checking: bool,
13 _now: u64,
14) -> bool {
15 let mut changed = false;
16
17 let mut to_prune = Vec::new();
20 for v in crdt.acked_boundary.iter() {
21 if let Some(parents) = crdt.t.get(v) {
22 for p in parents {
23 if !crdt.acked_boundary.contains(p) {
24 to_prune.push(p.clone());
25 }
26 }
27 }
28 }
29
30 if !just_checking {
31 for v in to_prune {
32 if crdt.t.remove(&v).is_some() {
33 crdt.crdt.prune(&v);
34 changed = true;
35 }
36 }
37 } else {
38 changed = !to_prune.is_empty();
39 }
40
41 changed
42}