use crate::chunk::AtomChunk;
use crate::column::Presence;
use crate::symbol::SymbolId;
use std::ops::Range;
pub(super) fn range_or_empty(range: Option<Range<u32>>) -> Range<u32> {
match range {
Some(range) => range,
None => 0..0,
}
}
pub(super) fn recorded_value<T>(entry: (T, Presence)) -> Option<T> {
let (value, presence) = entry;
presence.is_present().then_some(value)
}
pub(super) fn find_named(chunks: &[AtomChunk], range: Range<u32>, wanted: SymbolId) -> Option<u32> {
let mut cursor = chunks.partition_point(|chunk| chunk.atoms().end <= range.start);
for position in range {
loop {
let chunk = chunks.get(cursor)?;
let atoms = chunk.atoms();
if position >= atoms.end {
cursor += 1;
continue;
}
if position < atoms.start {
return None;
}
if chunk.atom_name(position - atoms.start) == Some(wanted) {
return Some(position);
}
break;
}
}
None
}
#[cfg(test)]
#[path = "handle_helpers_tests.rs"]
mod tests;