pub fn rle_from_value_runs<T: Clone + PartialEq>(
runs: Vec<(Range<usize>, T)>,
) -> (Vec<T>, Vec<(Range<usize>, u32)>)Expand description
Converts normalized value-bearing runs into a deduplicated table and a run list, coalescing adjacent runs that carry the same value.
§Input
runs: a vector of(start..end, value)pairs that is already normalized:- sorted by
(start, end)in ascending order, - non-empty (
start < end), - non-overlapping (touching is allowed).
- sorted by
§Behavior
- Builds
tableby global deduplication of values in first-appearance order. The same logical value appearing in disjoint places will share a single entry intable. - Produces
outas a list of(start..end, id), whereidindexes intotable. - If two consecutive input runs are touching (
prev.end == next.start) and their values are==, they are coalesced into a single output run referencing the sameid.
§Output invariants
outis sorted bystartand non-overlapping; touching runs have differentids.- Each
(r, id)inoutsatisfiesid < table.len(). tablepreserves first-appearance order of distinct values across the entire input.- The union of ranges in
outequals the union of ranges in the inputruns.
§Preconditions
This function assumes the input runs is normalized as described
above; it does not revalidate or resort the input. Supplying
unsorted or overlapping ranges results in unspecified behavior.
§Example
// Input runs (already sorted & non-overlapping):
// [(0..2, A), (2..5, A), (5..6, B), (8..10, A)]
// After coalescing equal-adjacent:
// [(0..5, A), (5..6, B), (8..10, A)]
// table = [A, B]
// out = [(0..5, 0), (5..6, 1), (8..10, 0)]