BTreeIndex

Struct BTreeIndex 

Source
pub struct BTreeIndex { /* private fields */ }
Expand description

B-Tree based index for ordered key lookups and range queries.

This index maintains keys in sorted order, enabling:

  • Exact key lookups
  • Range queries (e.g., all keys between “a” and “z”)
  • Prefix scans (e.g., all keys starting with “user:”)
  • Ordered iteration

§Performance

  • Insert: O(log n)
  • Lookup: O(log n)
  • Range query: O(log n + k) where k is the number of results

§Example

use rustlite_core::index::{BTreeIndex, Index};

let mut index = BTreeIndex::new();
index.insert(b"apple", 1).unwrap();
index.insert(b"banana", 2).unwrap();
index.insert(b"cherry", 3).unwrap();

// Exact lookup
assert_eq!(index.find(b"banana").unwrap(), vec![2]);

// Range query
let range = index.range(b"apple", b"cherry").unwrap();
assert_eq!(range.len(), 3);

Implementations§

Source§

impl BTreeIndex

Source

pub fn new() -> Self

Create a new empty B-Tree index.

Source

pub fn range( &self, start: &[u8], end: &[u8], ) -> Result<Vec<(Vec<u8>, Vec<u64>)>>

Range query: find all entries where key is in [start, end] inclusive.

Returns a vector of (key, values) pairs in sorted order.

Source

pub fn prefix_scan(&self, prefix: &[u8]) -> Result<Vec<(Vec<u8>, Vec<u64>)>>

Prefix scan: find all entries where key starts with the given prefix.

Returns a vector of (key, values) pairs in sorted order.

Source

pub fn min_key(&self) -> Option<&[u8]>

Get the minimum key in the index, if any.

Source

pub fn max_key(&self) -> Option<&[u8]>

Get the maximum key in the index, if any.

Source

pub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u64])>

Iterate over all entries in sorted order.

Trait Implementations§

Source§

impl Clone for BTreeIndex

Source§

fn clone(&self) -> BTreeIndex

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 Debug for BTreeIndex

Source§

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

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

impl Default for BTreeIndex

Source§

fn default() -> Self

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

impl Index for BTreeIndex

Source§

fn insert(&mut self, key: &[u8], value: u64) -> Result<()>

Insert a key-value pair into the index. The value is typically a pointer/offset to the actual data.
Source§

fn find(&self, key: &[u8]) -> Result<Vec<u64>>

Find all values matching the exact key.
Source§

fn remove(&mut self, key: &[u8]) -> Result<bool>

Remove all entries for a key from the index. Returns true if any entries were removed.
Source§

fn len(&self) -> usize

Returns the number of entries in the index.
Source§

fn clear(&mut self)

Clear all entries from the index.
Source§

fn index_type(&self) -> IndexType

Returns the index type.
Source§

fn is_empty(&self) -> bool

Returns true if the index is empty.

Auto Trait Implementations§

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