Skip to main content

contiguous_runs

Function contiguous_runs 

Source
pub fn contiguous_runs<T>(sorted: &[T]) -> Vec<Range<usize>>
where T: Copy + PartialEq + Add<Output = T> + One,
Expand description

The runs of sorted values each one more than the one before, as ranges of their positions: what music21’s groupContiguousIntegers groups.

use music21::common::numbertools::contiguous_runs;

assert_eq!(contiguous_runs(&[3, 4, 6, 7, 20]), [0..2, 2..4, 4..5]);