pub enum Node<K, V> {
    Internal(InternalNode<K, V>),
    Leaf(LeafNode<K, V>),
}
Expand description

B-tree node.

Variants§

§

Internal(InternalNode<K, V>)

Internal node.

§

Leaf(LeafNode<K, V>)

Leaf node.

Implementations§

source§

impl<K, V> Node<K, V>

source

pub fn binary( parent: Option<usize>, left_id: usize, median: Item<K, V>, right_id: usize ) -> Node<K, V>

source

pub fn leaf(parent: Option<usize>, item: Item<K, V>) -> Node<K, V>

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<usize>

source

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

source

pub fn item_count(&self) -> usize

source

pub fn child_count(&self) -> usize

source

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

source

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

source

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

source

pub fn get<Q>(&self, key: &Q) -> Result<Option<&V>, usize>where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Result<Option<&mut V>, usize>where K: Borrow<Q>, Q: Ord + ?Sized,

source

pub fn offset_of<Q>(&self, key: &Q) -> Result<Offset, (usize, Option<usize>)>where K: Borrow<Q>, Q: Ord + ?Sized,

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<&Item<K, V>>

source

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

source

pub fn insert_by_key( &mut self, key: K, value: V ) -> Result<(Offset, Option<V>), InsertionError<K, V>>where K: Ord,

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, Item<K, V>, Node<K, V>)

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, right_index: usize ) -> (usize, usize, usize, Item<K, V>, Balance)

source

pub fn append(&mut self, separator: Item<K, V>, other: Node<K, V>) -> Offset

Return the offset of the separator.

source

pub fn push_left(&mut self, item: Item<K, V>, opt_child_id: Option<usize>)

source

pub fn pop_left( &mut self ) -> Result<(Item<K, V>, Option<usize>), WouldUnderflow>

source

pub fn push_right( &mut self, item: Item<K, V>, opt_child_id: Option<usize> ) -> Offset

source

pub fn pop_right(&mut self) -> Result<PoppedItem<K, V>, WouldUnderflow>

source

pub fn leaf_remove( &mut self, offset: Offset ) -> Option<Result<Item<K, V>, usize>>

source

pub fn remove_rightmost_leaf(&mut self) -> Result<Item<K, V>, usize>

source

pub fn insert( &mut self, offset: Offset, item: Item<K, V>, opt_right_child_id: Option<usize> )

Put an item in a node.

It is assumed that the node will not overflow.

source

pub fn replace(&mut self, offset: Offset, item: Item<K, V>) -> Item<K, V>

source

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

source

pub fn children(&self) -> Children<'_, K, V>

source

pub fn children_with_separators(&self) -> ChildrenWithSeparators<'_, K, V>

source

pub fn validate(&self, parent: Option<usize>, min: Option<&K>, max: Option<&K>)where K: Ord,

Trait Implementations§

source§

impl<K: Clone, V: Clone> Clone for Node<K, V>

source§

fn clone(&self) -> Node<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for Node<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V> Send for Node<K, V>where K: Send, V: Send,

§

impl<K, V> Sync for Node<K, V>where K: Sync, V: Sync,

§

impl<K, V> Unpin for Node<K, V>where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for Node<K, V>where K: UnwindSafe + RefUnwindSafe, V: UnwindSafe + RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.