fix: refine rangemap interface

This commit is contained in:
Zixuan Chen 2022-12-07 11:03:10 +08:00
parent 594b60dafb
commit 1933fe6a56

View file

@ -323,6 +323,9 @@ impl<
self.tree.delete_range(start, end);
}
/// Return the values overlap with the given range
///
/// Note that the returned values may exceed the given range
#[inline]
pub fn get_range(&self, start: Index, end: Index) -> impl Iterator<Item = &Value> {
self.tree
@ -330,6 +333,10 @@ impl<
.map(|x| &x.as_tree_ref().value)
}
/// Return the values overlap with the given range and their indexes
///
/// Note that the returned values may exceed the given range
///
/// TODO: need double check this method
#[inline]
pub fn get_range_with_index(
@ -343,6 +350,19 @@ impl<
})
}
/// Return the values contained by the given range, the returned values are sliced by the given range
#[inline]
pub fn get_range_sliced(
&self,
start: Index,
end: Index,
) -> impl Iterator<Item = (Index, Value)> + '_ {
self.tree.iter_range(start, Some(end)).map(|x| {
let sliced = x.get_sliced();
(sliced.index, sliced.value)
})
}
#[inline]
pub fn get_mut(&mut self, index: Index) -> Option<&mut Value> {
let cursor = self.tree.get_mut(index);