Skip to main content

BPlusIndex

Struct BPlusIndex 

Source
pub struct BPlusIndex<K, V> { /* private fields */ }
Expand description

An arena-backed B+Tree sorted multimap.

Entries are (K, V) pairs sorted lexicographically. The pair is the unique identity: inserting the same (K, V) twice is a no-op, but inserting (K, V1) and (K, V2) stores both.

Nodes are stored in contiguous Vecs and referenced by u32 indices. Freed nodes are recycled via an internal free list.

Implementations§

Source§

impl<K: Ord + Clone, V: Ord + Clone> BPlusIndex<K, V>

Source

pub fn new() -> Self

Creates a new empty index.

Source

pub fn len(&self) -> usize

Returns the number of entries in the index.

Source

pub fn is_empty(&self) -> bool

Returns true if the index contains no entries.

Source

pub fn insert(&mut self, key: K, val: V)

Inserts a (key, val) pair into the index.

If the exact (key, val) pair already exists, this is a no-op. Multiple values for the same key are allowed.

Source

pub fn delete(&mut self, key: &K, val: &V) -> bool

Removes the exact (key, val) pair from the index.

Returns true if the entry was found and removed, false otherwise.

Source

pub fn update(&mut self, old_key: &K, new_key: K, val: V)

Re-indexes an entry by deleting (old_key, val) and inserting (new_key, val).

This is a convenience for the common case where the indexed field of a row changes but the row identifier (the value) stays the same.

Source

pub fn lookup_unique(&self, key: &K) -> Option<&V>

Returns a reference to the first value associated with key, or None.

For unique indexes this is the only value. For non-unique indexes this returns the smallest V for the given K.

Time: O(log n).

Source

pub fn lookup_range<'a>(&'a self, key: &'a K) -> LookupRange<'a, K, V>

Returns an iterator over all values associated with key.

Values are yielded in ascending V order. The iterator follows the leaf chain, so it works correctly even when entries for one key span multiple leaves.

Time: O(log n) for the initial descent, then O(k) for k results.

Source

pub fn range<R: RangeBounds<K>>(&self, bounds: R) -> RangeIter<'_, K, V>

Returns an iterator over all entries (&K, &V) whose keys fall within the given range bounds.

Supports all standard range syntax: a..b, a..=b, a.., ..b, ...

Time: O(log n) for the initial descent, then O(k) for k results.

Source

pub fn iter(&self) -> RangeIter<'_, K, V>

Returns an iterator over all entries in ascending order.

Time: O(n).

Trait Implementations§

Source§

impl<K: Ord + Clone, V: Ord + Clone> Default for BPlusIndex<K, V>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K, V> Freeze for BPlusIndex<K, V>

§

impl<K, V> RefUnwindSafe for BPlusIndex<K, V>

§

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

§

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

§

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

§

impl<K, V> UnsafeUnpin for BPlusIndex<K, V>

§

impl<K, V> UnwindSafe for BPlusIndex<K, V>
where K: UnwindSafe, V: 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.