Skip to main content

SubtreeSize

Struct SubtreeSize 

Source
pub struct SubtreeSize<S = usize>(/* private fields */);
Expand description

Augmentation that tracks the number of nodes in each subtree.

This enables O(log n) rank queries (find the k-th smallest element) and select operations when combined with custom traversal.

§Examples

use augmented_rbtree::{AugmentedRBTree, augmentations::SubtreeSize};

let mut tree = AugmentedRBTree::<i32, &str, SubtreeSize>::new();
tree.insert(3, "c");
tree.insert(1, "a");
tree.insert(2, "b");

assert_eq!(tree.root_stats(), Some(&3));
assert_eq!(tree.len(), 3);

Trait Implementations§

Source§

impl<K, V, S> Augment<K, V> for SubtreeSize<S>
where S: Add<Output = S> + From<usize> + Copy,

Source§

type Stats = S

The type of data that will be stored in the augmented tree.
Source§

fn compute( _key: &K, _value: &V, left: Option<(&K, &V, &S)>, right: Option<(&K, &V, &S)>, ) -> S

Computes the augmented data for a node given its key, value, and the augmented data of its left and right children.
Source§

impl<S: Debug> Debug for SubtreeSize<S>

Source§

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

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

impl<S: Default> Default for SubtreeSize<S>

Source§

fn default() -> SubtreeSize<S>

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

Auto Trait Implementations§

§

impl<S> Freeze for SubtreeSize<S>

§

impl<S> RefUnwindSafe for SubtreeSize<S>
where S: RefUnwindSafe,

§

impl<S> Send for SubtreeSize<S>
where S: Send,

§

impl<S> Sync for SubtreeSize<S>
where S: Sync,

§

impl<S> Unpin for SubtreeSize<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for SubtreeSize<S>

§

impl<S> UnwindSafe for SubtreeSize<S>
where S: 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.