use lctree::{LinkCutTree, Path};
#[derive(Copy, Clone)]
pub struct FindXor {
pub xor: u64,
}
impl Path for FindXor {
fn default(weight: f64, _: usize) -> Self {
FindXor { xor: weight as u64 }
}
fn aggregate(&mut self, other: Self) {
self.xor ^= other.xor;
}
}
#[test]
pub fn custom_path_aggregation() {
let mut lctree: LinkCutTree<FindXor> = LinkCutTree::new();
let a = lctree.make_tree(9.);
let b = lctree.make_tree(1.);
let c = lctree.make_tree(8.);
let d = lctree.make_tree(10.);
let e = lctree.make_tree(2.);
let f = lctree.make_tree(4.);
lctree.link(b, a);
lctree.link(c, b);
lctree.link(d, b);
lctree.link(e, a);
lctree.link(f, e);
let result = lctree.path(c, f);
assert_eq!(result.xor, 8 ^ 1 ^ 9 ^ 2 ^ 4);
}