pub struct RangeTree<T: RangeTreeKey> { /* private fields */ }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>,
pub fn add_abs(&mut self, start: T, end: T) -> Result<(), (T, T)>
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
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
the range start:size to remove allow 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, start+size]
pub fn collect(&self) -> Vec<(T, T)>
pub fn iter(&self) -> Iter<'_, T, T> ⓘ
pub fn validate(&self)
pub fn memory_used(&self) -> usize
Trait Implementations§
Source§impl<'a, T: RangeTreeKey> IntoIterator for &'a RangeTree<T>
impl<'a, T: RangeTreeKey> IntoIterator for &'a RangeTree<T>
Auto Trait Implementations§
impl<T> !Freeze for RangeTree<T>
impl<T> !RefUnwindSafe for RangeTree<T>
impl<T> Send for RangeTree<T>where
T: Send,
impl<T> Sync for RangeTree<T>
impl<T> Unpin for RangeTree<T>where
T: Unpin,
impl<T> UnsafeUnpin for RangeTree<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for RangeTree<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more