use crate::{
db::direction::Direction,
db::index::{entry::RawIndexEntry, envelope_is_empty, key::RawIndexKey, store::IndexStore},
error::InternalError,
};
use std::ops::Bound;
impl IndexStore {
pub(in crate::db) fn visit_raw_entries_in_range<F>(
&self,
bounds: (&Bound<RawIndexKey>, &Bound<RawIndexKey>),
direction: Direction,
mut visit: F,
) -> Result<(), InternalError>
where
F: FnMut(&RawIndexKey, &RawIndexEntry) -> Result<bool, InternalError>,
{
if envelope_is_empty(bounds.0, bounds.1) {
return Ok(());
}
match direction {
Direction::Asc => {
for entry in self.map.range((bounds.0.clone(), bounds.1.clone())) {
if visit(entry.key(), &entry.value())? {
return Ok(());
}
}
}
Direction::Desc => {
for entry in self.map.range((bounds.0.clone(), bounds.1.clone())).rev() {
if visit(entry.key(), &entry.value())? {
return Ok(());
}
}
}
}
Ok(())
}
}