Node

Enum Node 

Source
pub enum Node<T, S: Storage<T>> {
    Internal(InternalNode<T, S>),
    Leaf(LeafNode<T, S>),
}
Expand description

B-tree node.

Variants§

§

Internal(InternalNode<T, S>)

Internal node.

§

Leaf(LeafNode<T, S>)

Leaf node.

Implementations§

Source§

impl<T, S: Storage<T>> Node<T, S>

Source

pub fn binary( parent: Option<S::Node>, left_id: S::Node, median: T, right_id: S::Node, ) -> Self

Source

pub fn leaf(parent: Option<S::Node>, item: T) -> Self

Source

pub fn balance(&self) -> Balance

Source

pub fn is_underflowing(&self) -> bool

Source

pub fn is_overflowing(&self) -> bool

Source

pub fn parent(&self) -> Option<S::Node>

Source

pub fn set_parent(&mut self, p: Option<S::Node>)

Source

pub fn item_count(&self) -> usize

Source

pub fn child_count(&self) -> usize

Source

pub fn child_index(&self, id: S::Node) -> Option<usize>

Source

pub fn child_id(&self, index: usize) -> S::Node

Source

pub fn child_id_opt(&self, index: usize) -> Option<S::Node>

Source

pub fn get<Q: ?Sized>( &self, cmp: impl Fn(&T, &Q) -> Ordering, key: &Q, ) -> Result<Option<&T>, S::Node>

Source

pub fn get_mut<Q: ?Sized>( &mut self, cmp: impl Fn(&T, &Q) -> Ordering, key: &Q, ) -> Result<Option<&mut T>, &mut S::Node>

Return the value associated to the given key, if any.

Return Err if thi key might be located in the returned child node.

Source

pub fn offset_of<Q: ?Sized>( &self, cmp: impl Fn(&T, &Q) -> Ordering, key: &Q, ) -> Result<Offset, (usize, Option<S::Node>)>

Find the offset of the item matching the given key.

If the key matches no item in this node, this funtion returns the index and id of the child that may match the key, or Err(None) if it is a leaf.

Source

pub fn item(&self, offset: Offset) -> Option<&T>

Source

pub fn item_mut(&mut self, offset: Offset) -> Option<&mut T>

Source

pub fn insert_by_key( &mut self, cmp: impl Fn(&T, &T) -> Ordering, item: T, ) -> Result<(Offset, Option<T>), InsertionError<T, S>>

Insert by key.

It is assumed that the node is not free. If it is a leaf node, there must be a free space in it for the inserted value.

Source

pub fn split(&mut self) -> (usize, T, Node<T, S>)

Split the node. Return the length of the node after split, the median item and the right node.

Source

pub fn merge( &mut self, left_index: usize, ) -> (usize, S::Node, S::Node, T, Balance)

Source

pub fn append(&mut self, separator: T, other: Node<T, S>) -> Offset

Return the offset of the separator.

Source

pub fn push_left(&mut self, item: T, opt_child_id: Option<S::Node>)

Source

pub fn pop_left(&mut self) -> Result<LeftItem<T, S>, WouldUnderflow>

Source

pub fn push_right(&mut self, item: T, opt_child_id: Option<S::Node>) -> Offset

Source

pub fn pop_right(&mut self) -> Result<RightItem<T, S>, WouldUnderflow>

Source

pub fn leaf_remove(&mut self, offset: Offset) -> Option<Result<T, S::Node>>

Source

pub fn remove_rightmost_leaf(&mut self) -> Result<T, S::Node>

Source

pub fn insert( &mut self, offset: Offset, item: T, opt_right_child_id: Option<S::Node>, )

Put an item in a node.

It is assumed that the node will not overflow.

Source

pub fn replace(&mut self, offset: Offset, item: T) -> T

Source

pub fn separators(&self, i: usize) -> (Option<&T>, Option<&T>)

Source

pub fn children(&self) -> Children<'_, T, S>

Source

pub fn children_with_separators(&self) -> ChildrenWithSeparators<'_, T, S>

Source

pub fn visit_from_leaves(&self, nodes: &S, f: impl FnMut(S::Node))

Source

pub fn visit_from_leaves_with(&self, nodes: &S, f: &mut impl FnMut(S::Node))

Source

pub fn visit_from_leaves_mut( &self, nodes: &mut S, f: impl FnMut(S::Node, &mut Self), )

Source

pub fn visit_from_leaves_mut_with( &self, nodes: &mut S, f: &mut impl FnMut(S::Node, &mut Self), )

Source

pub fn forget(&mut self)

Forget the node content, without running the items destructors.

The node’s children must be manually dropped.

Source

pub fn validate( &self, cmp: impl Fn(&T, &T) -> Ordering, parent: Option<S::Node>, min: Option<&T>, max: Option<&T>, )

Auto Trait Implementations§

§

impl<T, S> Freeze for Node<T, S>
where <S as Storage<T>>::Node: Freeze, T: Freeze,

§

impl<T, S> RefUnwindSafe for Node<T, S>
where <S as Storage<T>>::Node: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, S> Send for Node<T, S>
where <S as Storage<T>>::Node: Send, T: Send,

§

impl<T, S> Sync for Node<T, S>
where <S as Storage<T>>::Node: Sync, T: Sync,

§

impl<T, S> Unpin for Node<T, S>
where <S as Storage<T>>::Node: Unpin, T: Unpin,

§

impl<T, S> UnwindSafe for Node<T, S>
where <S as Storage<T>>::Node: UnwindSafe, 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.