Skip to main content

expand_and_merge

Function expand_and_merge 

Source
pub fn expand_and_merge(hits: &[usize], ctx: usize, total: usize) -> Vec<usize>
Expand description

Expand each hit index by ctx lines and merge overlapping/adjacent windows into a sorted, de-duplicated list of line indices, clamped to total lines.

ยงExamples

use coding_tools::view::expand_and_merge;

// hits at 2 and 3 with 1 line of context overlap into a single run.
assert_eq!(expand_and_merge(&[2, 3], 1, 10), vec![1, 2, 3, 4]);
// distant hits stay separate.
assert_eq!(expand_and_merge(&[1, 8], 0, 10), vec![1, 8]);
// context clamps to the file bounds.
assert_eq!(expand_and_merge(&[0], 2, 3), vec![0, 1, 2]);