Skip to main content

segments

Function segments 

Source
pub fn segments(idx: &[usize]) -> Vec<(usize, usize)>
Expand description

Group sorted indices into contiguous [start, end] runs (the display groups separated by -- in text output).

ยงExamples

use coding_tools::view::segments;

assert_eq!(segments(&[1, 2, 3]), vec![(1, 3)]);
assert_eq!(segments(&[1, 2, 5, 6]), vec![(1, 2), (5, 6)]);
assert_eq!(segments(&[]), vec![]);