Skip to main content

apply

Function apply 

Source
pub fn apply<C, T>(target: &mut C, delta: BagDelta<T>)
where C: IntoIterator<Item = T> + Extend<T> + TryIndex<T, Output = T>,
Expand description

Applies a membership diff to target in place.

Each removal is a single lookup rather than a scan, so this costs the same as diff does. Membership is preserved but position is not — additions land wherever the collection decides to put them. Use ordered where that matters.

A removal that target does not have is ignored, which makes applying the same delta twice harmless.

use delta_struct::bag::{apply, diff};
use std::collections::BTreeSet;

let set = |items: Vec<i32>| items.into_iter().collect::<BTreeSet<i32>>();

let delta = diff(set(vec![1, 2, 3]), set(vec![2, 3, 4]));
let mut target = set(vec![1, 2, 3]);
apply(&mut target, delta);
assert_eq!(target, set(vec![2, 3, 4]));