mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-10-06 05:12:03 +08:00
26 lines
717 B
Rust
26 lines
717 B
Rust
//! Byte boundaries used while partitioning source files into retrievable chunks.
|
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
pub struct ChunkBoundary {
|
|
pub start: usize,
|
|
pub end: usize,
|
|
}
|
|
|
|
pub(crate) fn merge_adjacent(boundaries: Vec<ChunkBoundary>, desired: usize) -> Vec<ChunkBoundary> {
|
|
let mut input = boundaries.into_iter();
|
|
let Some(mut current) = input.next() else {
|
|
return Vec::new();
|
|
};
|
|
let mut output = Vec::new();
|
|
for next in input {
|
|
if next.end.saturating_sub(current.start) <= desired {
|
|
current.end = next.end;
|
|
} else {
|
|
output.push(current);
|
|
current = next;
|
|
}
|
|
}
|
|
output.push(current);
|
|
output
|
|
}
|