SumTree

Struct SumTree 

Source
pub struct SumTree<T: Item>(/* private fields */);
Expand description

A B+ tree in which each leaf node contains Items of type T and a Summarys for each Item. Each internal node contains a Summary of the items in its subtree.

The maximum number of items per node is TREE_BASE * 2.

Any Dimension supported by the Summary type can be used to seek to a specific location in the tree.

Implementations§

Source§

impl<T: Item> SumTree<T>

Source

pub fn new(cx: <T::Summary as Summary>::Context<'_>) -> Self

Source

pub fn from_summary(summary: T::Summary) -> Self

Useful in cases where the item type has a non-trivial context type, but the zero value of the summary type doesn’t depend on that context.

Source

pub fn from_item(item: T, cx: <T::Summary as Summary>::Context<'_>) -> Self

Source

pub fn from_iter<I: IntoIterator<Item = T>>( iter: I, cx: <T::Summary as Summary>::Context<'_>, ) -> Self

Source

pub fn from_par_iter<I, Iter>( iter: I, cx: <T::Summary as Summary>::Context<'_>, ) -> Self
where I: IntoParallelIterator<Iter = Iter>, Iter: IndexedParallelIterator<Item = T>, T: Send + Sync, T::Summary: Send + Sync, for<'a> <T::Summary as Summary>::Context<'a>: Sync,

Source

pub fn items<'a>(&'a self, cx: <T::Summary as Summary>::Context<'a>) -> Vec<T>

Source

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

Source

pub fn cursor<'a, 'b, S>( &'a self, cx: <T::Summary as Summary>::Context<'b>, ) -> Cursor<'a, 'b, T, S>
where S: Dimension<'a, T::Summary>,

Source

pub fn filter<'a, 'b, F, U>( &'a self, cx: <T::Summary as Summary>::Context<'b>, filter_node: F, ) -> FilterCursor<'a, 'b, F, T, U>
where F: FnMut(&T::Summary) -> bool, U: Dimension<'a, T::Summary>,

Note: If the summary type requires a non () context, then the filter cursor that is returned cannot be used with Rust’s iterators.

Source

pub fn first(&self) -> Option<&T>

Source

pub fn last(&self) -> Option<&T>

Source

pub fn update_last( &mut self, f: impl FnOnce(&mut T), cx: <T::Summary as Summary>::Context<'_>, )

Source

pub fn extent<'a, D: Dimension<'a, T::Summary>>( &'a self, cx: <T::Summary as Summary>::Context<'_>, ) -> D

Source

pub fn summary(&self) -> &T::Summary

Source

pub fn is_empty(&self) -> bool

Source

pub fn extend<I>(&mut self, iter: I, cx: <T::Summary as Summary>::Context<'_>)
where I: IntoIterator<Item = T>,

Source

pub fn par_extend<I, Iter>( &mut self, iter: I, cx: <T::Summary as Summary>::Context<'_>, )
where I: IntoParallelIterator<Iter = Iter>, Iter: IndexedParallelIterator<Item = T>, T: Send + Sync, T::Summary: Send + Sync, for<'a> <T::Summary as Summary>::Context<'a>: Sync,

Source

pub fn push(&mut self, item: T, cx: <T::Summary as Summary>::Context<'_>)

Source

pub fn append(&mut self, other: Self, cx: <T::Summary as Summary>::Context<'_>)

Source§

impl<T: KeyedItem> SumTree<T>

Source

pub fn insert_or_replace<'a, 'b>( &'a mut self, item: T, cx: <T::Summary as Summary>::Context<'b>, ) -> Option<T>

Source

pub fn remove( &mut self, key: &T::Key, cx: <T::Summary as Summary>::Context<'_>, ) -> Option<T>

Source

pub fn edit( &mut self, edits: Vec<Edit<T>>, cx: <T::Summary as Summary>::Context<'_>, ) -> Vec<T>

Source

pub fn get<'a>( &'a self, key: &T::Key, cx: <T::Summary as Summary>::Context<'a>, ) -> Option<&'a T>

Trait Implementations§

Source§

impl<T: Clone + Item> Clone for SumTree<T>

Source§

fn clone(&self) -> SumTree<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for SumTree<T>
where T: Debug + Item, T::Summary: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, S> Default for SumTree<T>
where T: Item<Summary = S>, S: for<'a> Summary<Context<'a> = ()>,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Item + PartialEq> PartialEq for SumTree<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Item + Eq> Eq for SumTree<T>

Auto Trait Implementations§

§

impl<T> Freeze for SumTree<T>

§

impl<T> RefUnwindSafe for SumTree<T>

§

impl<T> Send for SumTree<T>
where <T as Item>::Summary: Sync + Send, T: Sync + Send,

§

impl<T> Sync for SumTree<T>
where <T as Item>::Summary: Sync + Send, T: Sync + Send,

§

impl<T> Unpin for SumTree<T>

§

impl<T> UnwindSafe for SumTree<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.