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
impl BTreeIndex
Sourcepub fn range(
&self,
start: &[u8],
end: &[u8],
) -> Result<Vec<(Vec<u8>, Vec<u64>)>>
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.
Trait Implementations§
Source§impl Clone for BTreeIndex
impl Clone for BTreeIndex
Source§fn clone(&self) -> BTreeIndex
fn clone(&self) -> BTreeIndex
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BTreeIndex
impl Debug for BTreeIndex
Source§impl Default for BTreeIndex
impl Default for BTreeIndex
Source§impl Index for BTreeIndex
impl Index for BTreeIndex
Source§fn insert(&mut self, key: &[u8], value: u64) -> Result<()>
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 remove(&mut self, key: &[u8]) -> Result<bool>
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 index_type(&self) -> IndexType
fn index_type(&self) -> IndexType
Returns the index type.
Auto Trait Implementations§
impl Freeze for BTreeIndex
impl RefUnwindSafe for BTreeIndex
impl Send for BTreeIndex
impl Sync for BTreeIndex
impl Unpin for BTreeIndex
impl UnwindSafe for BTreeIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more