mirror of
https://github.com/loro-dev/loro.git
synced 2025-02-11 14:53:12 +00:00
fix: refine rangemap interface
This commit is contained in:
parent
594b60dafb
commit
1933fe6a56
1 changed files with 20 additions and 0 deletions
|
@ -323,6 +323,9 @@ impl<
|
||||||
self.tree.delete_range(start, end);
|
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]
|
#[inline]
|
||||||
pub fn get_range(&self, start: Index, end: Index) -> impl Iterator<Item = &Value> {
|
pub fn get_range(&self, start: Index, end: Index) -> impl Iterator<Item = &Value> {
|
||||||
self.tree
|
self.tree
|
||||||
|
@ -330,6 +333,10 @@ impl<
|
||||||
.map(|x| &x.as_tree_ref().value)
|
.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
|
/// TODO: need double check this method
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn get_range_with_index(
|
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]
|
#[inline]
|
||||||
pub fn get_mut(&mut self, index: Index) -> Option<&mut Value> {
|
pub fn get_mut(&mut self, index: Index) -> Option<&mut Value> {
|
||||||
let cursor = self.tree.get_mut(index);
|
let cursor = self.tree.get_mut(index);
|
||||||
|
|
Loading…
Reference in a new issue