Skip to main content

align

Function align 

Source
pub fn align<'a, K: Eq + Hash>(old: &'a [K], new: &'a [K]) -> Vec<Step<'a, K>>
Expand description

Align two sequences of item ids: the longest run of ids both keep in the same order is Step::Both, the rest is removed or added. Between two kept ids, the removed ones come first.

Ids are expected to be unique within each sequence (a repeated id pairs once). Common leading and trailing runs are paired directly, so the usual local edit costs as much as the edit; the middle aligns in O(n log n) as the longest increasing run of new positions.