Skip to main content

BTreeMap

Struct BTreeMap 

Source
pub struct BTreeMap<M, C = Lexicographic> { /* private fields */ }
Expand description

A stable-memory B-tree, independent of DFINITY’s collection formats.

Exactly one live tree handle may own a memory region. The memory must not be mutated through aliases. Mutations stage touched pages, reserve capacity, then write them. Backing writes must either complete or trap in an atomic IC message; this is not a crash-safe filesystem database. See the package guide.

Implementations§

Source§

impl<M: Memory, C: Comparator> BTreeMap<M, C>

Source

pub fn create(memory: M, config: Config, order: C) -> Result<Self, Error>

Create a tree in an empty memory without overwriting an existing format.

§Errors

Rejects nonempty memory, invalid limits, and refused growth.

Source

pub fn open(memory: M, config: Config, order: C) -> Result<Self, Error>

Open a tree with its exact configuration and comparator identity.

Opening checks the header and root, not every page. Reads validate pages as visited; Self::validate performs a complete structural audit.

§Errors

Rejects unknown formats, incompatible limits/order, and observed corruption.

Source

pub const fn len(&self) -> u64

Number of live entries, persisted with each completed mutation.

Source

pub const fn is_empty(&self) -> bool

Whether the tree contains no entries.

Source

pub fn memory_bytes(&self) -> u64

Bytes reserved in the backing memory, including reusable free pages.

Source

pub fn into_memory(self) -> M

Release the sole handle and return its backing memory for later reopening.

Source

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

Read one value by key.

§Errors

Rejects malformed keys, oversized keys, and observed storage corruption.

Source

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

Test key membership without reading the value payload.

§Errors

Rejects invalid keys and observed key or tree-page corruption.

Source

pub fn insert( &mut self, key: &[u8], value: &[u8], ) -> Result<Option<Vec<u8>>, Error>

Insert or replace a value, returning the previous value if present.

§Errors

Rejects invalid keys, oversized inputs, corruption, or insufficient capacity before publishing changes. Memory traps follow the backing contract.

Source

pub fn remove(&mut self, key: &[u8]) -> Result<Option<Vec<u8>>, Error>

Remove a key, returning its previous value.

§Errors

Rejects malformed keys and observed corruption without publishing changes.

Source

pub fn range( &self, lower: Bound<&[u8]>, upper: Bound<&[u8]>, ) -> Result<Range<'_, M, C>, Error>

Iterate a bounded range in either direction without reading value payloads.

Bounds use the supplied comparator. Equal exclusive bounds yield an empty range. rev() and interleaved next/next_back are supported.

§Errors

Rejects invalid bounds; traversal errors are yielded by the iterator.

Source

pub fn iter(&self) -> Range<'_, M, C> ⓘ

Traverse all entries in comparator order, with lazy value reads.

Source

pub fn validate(&self) -> Result<(), Error>

Check every reachable page, key order, depth, occupancy, entry count and free-list ownership. This explicit audit is linear in allocated storage.

§Errors

Returns an error on corruption, invalid encoded keys or invalid ordering.

Trait Implementations§

Source§

impl<'a, M: Memory, C: Comparator> IntoIterator for &'a BTreeMap<M, C>

Source§

type Item = Result<Entry<'a, M, C>, Error>

The type of the elements being iterated over.
Source§

type IntoIter = Range<'a, M, C>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<M, C> Freeze for BTreeMap<M, C>
where M: Freeze, C: Freeze,

§

impl<M, C> RefUnwindSafe for BTreeMap<M, C>

§

impl<M, C> Send for BTreeMap<M, C>
where M: Send, C: Send,

§

impl<M, C> Sync for BTreeMap<M, C>
where M: Sync, C: Sync,

§

impl<M, C> Unpin for BTreeMap<M, C>
where M: Unpin, C: Unpin,

§

impl<M, C> UnsafeUnpin for BTreeMap<M, C>
where M: UnsafeUnpin, C: UnsafeUnpin,

§

impl<M, C> UnwindSafe for BTreeMap<M, C>
where M: UnwindSafe, C: 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.