pub struct BTree { /* private fields */ }Expand description
B+ Tree implementation
Implementations§
Source§impl BTree
impl BTree
Sourcepub fn with_root(pager: Arc<Pager>, root_page_id: u32) -> BTree
pub fn with_root(pager: Arc<Pager>, root_page_id: u32) -> BTree
Create a B+ tree with an existing root
Sourcepub fn root_page_id(&self) -> u32
pub fn root_page_id(&self) -> u32
Get the root page ID
Sourcepub fn insert(&self, key: &[u8], value: &[u8]) -> Result<(), BTreeError>
pub fn insert(&self, key: &[u8], value: &[u8]) -> Result<(), BTreeError>
Insert a key-value pair
Sourcepub fn upsert(&self, key: &[u8], value: &[u8]) -> Result<(), BTreeError>
pub fn upsert(&self, key: &[u8], value: &[u8]) -> Result<(), BTreeError>
Insert or update a key. If the key already exists and the new value has the same length as the old, the value bytes are overwritten in place — no structural changes, no rebalance, one leaf page write.
Falls back to delete + insert when the key is missing or the
new value has a different length. Callers like
persist_entities_to_pager that re-serialize a mutated entity
with a fixed-width schema almost always hit the fast path,
eliminating the BTree::delete + rebalance cost that previously
dominated UPDATE workloads (~50% of bulk_update CPU).
Sourcepub fn upsert_batch_sorted(
&self,
items: &[(Vec<u8>, Vec<u8>)],
) -> Result<(), BTreeError>
pub fn upsert_batch_sorted( &self, items: &[(Vec<u8>, Vec<u8>)], ) -> Result<(), BTreeError>
Batch upsert for sorted keys landing in a small set of leaves.
Walks to each leaf once, applies every same-or-shrink in-place
overwrite that belongs there, writes the page once, then moves
on. Keys that miss or whose new value grows fall back to the
generic single-key upsert path — correctness identical,
structural re-layout handled there.
Callers pass lex-sorted (key, value) pairs. For the entity
UPDATE path, IDs are big-endian so u64 ordering = lex ordering.
Sourcepub fn bulk_insert_sorted(
&self,
items: &[(Vec<u8>, Vec<u8>)],
) -> Result<(), BTreeError>
pub fn bulk_insert_sorted( &self, items: &[(Vec<u8>, Vec<u8>)], ) -> Result<(), BTreeError>
Bulk insert for sorted key-value pairs.
Optimized for monotonically increasing keys (e.g. entity IDs):
- Walks to the target leaf ONCE, then appends many entries before re-walking.
- Writes each leaf only once per batch (amortized over many inserts).
Falls back to per-entity insert on splits.
Sourcepub fn cursor_first(&self) -> Result<BTreeCursor, BTreeError>
pub fn cursor_first(&self) -> Result<BTreeCursor, BTreeError>
Create a cursor starting at the first entry
Sourcepub fn cursor_seek(&self, key: &[u8]) -> Result<BTreeCursor, BTreeError>
pub fn cursor_seek(&self, key: &[u8]) -> Result<BTreeCursor, BTreeError>
Create a cursor starting at or after the given key
Sourcepub fn range(
&self,
start_key: &[u8],
end_key: &[u8],
) -> Result<Vec<(Vec<u8>, Vec<u8>)>, BTreeError>
pub fn range( &self, start_key: &[u8], end_key: &[u8], ) -> Result<Vec<(Vec<u8>, Vec<u8>)>, BTreeError>
Range scan from start_key to end_key (inclusive)
Sourcepub fn count(&self) -> Result<usize, BTreeError>
pub fn count(&self) -> Result<usize, BTreeError>
Count entries in the tree
Auto Trait Implementations§
impl !Freeze for BTree
impl RefUnwindSafe for BTree
impl Send for BTree
impl Sync for BTree
impl Unpin for BTree
impl UnsafeUnpin for BTree
impl UnwindSafe for BTree
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request