Skip to main content

BTree

Struct BTree 

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

B+ Tree implementation

Implementations§

Source§

impl BTree

Source

pub fn new(pager: Arc<Pager>) -> BTree

Create a new B+ tree using the given pager

Source

pub fn with_root(pager: Arc<Pager>, root_page_id: u32) -> BTree

Create a B+ tree with an existing root

Source

pub fn root_page_id(&self) -> u32

Get the root page ID

Source

pub fn is_empty(&self) -> bool

Check if tree is empty

Source

pub fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>, BTreeError>

Get value for a key

Source

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

Insert a key-value pair

Source

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

Source

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.

Source

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.

Source

pub fn delete(&self, key: &[u8]) -> Result<bool, BTreeError>

Delete a key

Source

pub fn cursor_first(&self) -> Result<BTreeCursor, BTreeError>

Create a cursor starting at the first entry

Source

pub fn cursor_seek(&self, key: &[u8]) -> Result<BTreeCursor, BTreeError>

Create a cursor starting at or after the given key

Source

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)

Source

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more