pub struct BTreeMap<K, V, M>where
    K: BoundedStorable + Ord + Clone,
    V: BoundedStorable,
    M: Memory,{ /* private fields */ }
Expand description

A “stable” map based on a B-tree.

The implementation is based on the algorithm outlined in “Introduction to Algorithms” by Cormen et al.

Implementations§

source§

impl<K, V, M> BTreeMap<K, V, M>where K: BoundedStorable + Ord + Clone, V: BoundedStorable, M: Memory,

source

pub fn init(memory: M) -> Self

Initializes a BTreeMap.

If the memory provided already contains a BTreeMap, then that map is loaded. Otherwise, a new BTreeMap instance is created.

source

pub fn new(memory: M) -> Self

Creates a new instance a BTreeMap.

The given memory is assumed to be exclusively reserved for this data structure and that it starts at address zero. Typically memory will be an instance of RestrictedMemory.

When initialized, the data structure has the following memory layout:

| BTreeHeader | Allocator | … free memory for nodes |

See Allocator for more details on its own memory layout.

source

pub fn load(memory: M) -> Self

Loads the map from memory.

source

pub fn insert(&mut self, key: K, value: V) -> Option<V>

Inserts a key-value pair into the map.

The previous value of the key, if present, is returned.

PRECONDITION: key.to_bytes().len() <= Key::MAX_SIZE value.to_bytes().len() <= Value::MAX_SIZE

source

pub fn get(&self, key: &K) -> Option<V>

Returns the value associated with the given key if it exists.

source

pub fn contains_key(&self, key: &K) -> bool

Returns true if the key exists in the map, false otherwise.

source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

source

pub fn len(&self) -> u64

Returns the number of elements in the map.

source

pub fn into_memory(self) -> M

Returns the underlying memory.

source

pub fn clear(self) -> Self

Removes all elements from the map.

source

pub fn first_key_value(&self) -> Option<(K, V)>

Returns the first key-value pair in the map. The key in this pair is the minimum key in the map.

source

pub fn last_key_value(&self) -> Option<(K, V)>

Returns the last key-value pair in the map. The key in this pair is the maximum key in the map.

source

pub fn remove(&mut self, key: &K) -> Option<V>

Removes a key from the map, returning the previous value at the key if it exists.

source

pub fn iter(&self) -> Iter<'_, K, V, M>

Returns an iterator over the entries of the map, sorted by key.

source

pub fn range(&self, key_range: impl RangeBounds<K>) -> Iter<'_, K, V, M>

Returns an iterator over the entries in the map where keys belong to the specified range.

source

pub fn iter_upper_bound(&self, bound: &K) -> Iter<'_, K, V, M>

Returns an iterator pointing to the first element below the given bound. Returns an empty iterator if there are no keys below the given bound.

Auto Trait Implementations§

§

impl<K, V, M> RefUnwindSafe for BTreeMap<K, V, M>where K: RefUnwindSafe, M: RefUnwindSafe, V: RefUnwindSafe,

§

impl<K, V, M> Send for BTreeMap<K, V, M>where K: Send, M: Send, V: Send,

§

impl<K, V, M> Sync for BTreeMap<K, V, M>where K: Sync, M: Sync, V: Sync,

§

impl<K, V, M> Unpin for BTreeMap<K, V, M>where K: Unpin, M: Unpin, V: Unpin,

§

impl<K, V, M> UnwindSafe for BTreeMap<K, V, M>where K: UnwindSafe, M: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.