Skip to main content

RangeTree

Struct RangeTree 

Source
pub struct RangeTree<T: RangeTreeKey> { /* private fields */ }

Implementations§

Source§

impl<T: RangeTreeKey> RangeTree<T>

Source

pub fn new() -> Self

Source

pub fn is_empty(&self) -> bool

Source

pub fn get_space(&self) -> T

Source

pub fn len(&self) -> usize

Source

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

Source

pub fn add_with<O>( &mut self, start: T, size: T, ops: &mut O, ) -> Result<(), (T, T)>
where O: RangeTreeOps<T>,

Source

pub fn add_abs(&mut self, start: T, end: T) -> Result<(), (T, T)>

Source

pub fn add_loosely(&mut self, start: T, size: T)

Add range which may have multiple intersections with existing range, ensuring union result

Source

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.
Source

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.
Source

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]

Source

pub fn range<'a, R: RangeBounds<T>>(&'a self, r: R) -> RangeIter<'a, T>

return only when segment overlaps with [start, start+size]

Source

pub fn collect(&self) -> Vec<(T, T)>

Source

pub fn iter(&self) -> Iter<'_, T, T>

Source

pub fn validate(&self)

Source

pub fn memory_used(&self) -> usize

Trait Implementations§

Source§

impl<'a, T: RangeTreeKey> IntoIterator for &'a RangeTree<T>

Source§

type Item = (&'a T, &'a T)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T: RangeTreeKey> IntoIterator for RangeTree<T>

Source§

type Item = (T, T)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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>
where T: Sync + Send,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.