pub struct RangeTree<T: RangeTreeKey> { /* private fields */ }Expand description
A b+tree stores range segment of [start, start+size)
Implementations§
Source§impl<T: RangeTreeKey> RangeTree<T>
impl<T: RangeTreeKey> RangeTree<T>
pub fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn get_space(&self) -> T
pub fn len(&self) -> usize
Sourcepub fn add(&mut self, start: T, size: T) -> Result<(), (T, T)>
pub fn add(&mut self, start: T, size: T) -> Result<(), (T, T)>
Add range segment, merge with adjacent ranges, assuming no intersections.
Returns Ok(()) if there are no intersection;
otherwise returns the overlapping range as Err((existing_start, existing_size)).
This equals to add + add_find_overlap in v0.1
pub fn add_with<O>(
&mut self,
start: T,
size: T,
ops: &mut O,
) -> Result<(), (T, T)>where
O: RangeTreeOps<T>,
Sourcepub fn add_abs(&mut self, start: T, end: T) -> Result<(), (T, T)>
pub fn add_abs(&mut self, start: T, end: T) -> Result<(), (T, T)>
Add to the tree with [start, end)
Returns Ok(()) if there are no intersection;
otherwise returns the overlapping range as Err((existing_start, existing_size)).
This equals to add_abs in v0.1
Sourcepub fn add_loosely(&mut self, start: T, size: T)
pub fn add_loosely(&mut self, start: T, size: T)
Add range which may have multiple intersections with existing range, ensuring union result stores in the tree
Sourcepub fn remove(&mut self, start: T, size: T) -> Result<(), Option<(T, T)>>
pub fn remove(&mut self, start: T, size: T) -> Result<(), Option<(T, T)>>
Valid and remove specify range start:size
§Return value
- Only return Ok(()) when there’s existing range equal to or contain the removal range in the tree,
- return Err(None) when not found,
- return Err(Some(start, size)) when a range intersect with the removal range, or when the removal range larger than existing range.
Sourcepub fn remove_with<O>(
&mut self,
start: T,
size: T,
ops: &mut O,
) -> Result<(), Option<(T, T)>>where
O: RangeTreeOps<T>,
pub fn remove_with<O>(
&mut self,
start: T,
size: T,
ops: &mut O,
) -> Result<(), Option<(T, T)>>where
O: RangeTreeOps<T>,
Valid and remove specify range start:size
§Return value
- Only return Ok(()) when there’s existing range equal to or contain the removal range in the tree,
- return Err(None) when not found,
- return Err(Some(start, size)) when a range intersect with the removal range, or when the removal range larger than existing range.
Sourcepub fn remove_loosely(&mut self, start: T, size: T) -> bool
pub fn remove_loosely(&mut self, start: T, size: T) -> bool
Remove all the intersection ranges in the tree
Unlike the strict behavior of RangeTree::remove(), this function allows the removal range start:size to to be larger than the existing range.
Equals to remove_and_split in v0.1
return true if overlapping range found and removed. return false if overlapping range not found.
#[inline]
Sourcepub fn range<'a, R: RangeBounds<T>>(&'a self, r: R) -> RangeIter<'a, T> ⓘ
pub fn range<'a, R: RangeBounds<T>>(&'a self, r: R) -> RangeIter<'a, T> ⓘ
return only when segment overlaps with start..end
§NOTE
Be aware the first range may have _start < start, and the last range may have _start + _size > end