Skip to main content

BTreeMap

Struct BTreeMap 

Source
pub struct BTreeMap<K, V, Node = Vec<Pair<K, V>>>
where K: Send + Ord + Clone + 'static, V: Send + Clone + 'static, Node: NodeLike<Pair<K, V>>,
{ /* private fields */ }

Implementations§

Source§

impl<K, V, Node> BTreeMap<K, V, Node>
where K: Debug + Send + Ord + Clone + 'static, V: Debug + Send + Clone + 'static, Node: NodeLike<Pair<K, V>> + Send + 'static,

Source

pub fn new() -> Self

Makes a new, empty, persistent BTreeMap.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut map = BTreeMap::<usize, &str>::new();

// entries can now be inserted into the empty map
map.insert(1, "a");
Source

pub fn with_maximum_node_size(node_capacity: usize) -> Self

Makes a new, empty BTreeMap with the given maximum node size. Allocates one vec with the capacity set to be the specified node size.

§Examples
use indexset::concurrent::map::BTreeMap;

let map = BTreeMap::<i32, i32>::with_maximum_node_size(128);
Source

pub fn attach_node(&self, node: Node)

Adds full [Node] to this set. [Node] should be correct node with values sorted.

Source

pub fn attach_nodes(&self, nodes: impl IntoIterator<Item = Node>)

Attaches persisted [Node]s with one topology publication.

Source

pub fn snapshot_nodes(&self) -> Vec<Node>
where Node: Clone,

Returns detached, read-only snapshots of this map’s [Node]s.

Callers requiring one coherent logical generation must prevent concurrent mutation while collecting.

Source

pub fn export_topology(&self) -> Topology<Pair<K, V>>

Copies the exact node boundaries into a pointer-free checkpoint image.

Callers that need a single logical generation must externally prevent mutations for the duration of this method, or snapshot a temporary index reconstructed from an ordered redo log.

Source

pub fn from_topology( topology: Topology<Pair<K, V>>, ) -> Result<Self, TopologyError>

Reconstructs a B-tree from a validated pointer-free topology image.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns true if the map contains a value for the specified key.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut map = BTreeMap::<usize, &str>::new();
map.insert(1, "a");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);
Source

pub fn get<Q>(&self, key: &Q) -> Option<Ref<Pair<K, V>, Node>>
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized,

Returns a reference to a pair whose key corresponds to the input.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut map = BTreeMap::<usize, &str>::new();
map.insert(1, "a");
assert_eq!(map.get(&1).and_then(|e| Some(e.get().value)), Some("a"));
assert_eq!(map.get(&2).and_then(|e| Some(e.get().value)), None);
Source

pub fn lookup_for_select<Q>(&self, key: &Q) -> Option<V>
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized, V: Clone,

Returns an owned clone from the definitive point-lookup path.

The structural mapping is pinned until the selected node is locked, so both hits and misses are authoritative. Only the value is cloned; the key remains borrowed. This API requires V: Clone.

Source

pub fn lookup_for_select_optimistic<Q>(&self, key: &Q) -> Option<V>
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized, V: Clone,

Returns an owned clone from the optimistic one-node lookup only.

This is an explicit latency-first primitive for callers that can accept a transient false miss during concurrent structural reindexing. Most callers should use BTreeMap::lookup_for_select.

Source

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

Inserts a key-value pair into the map.

If the map did not have this key present, it will be inserted.

Otherwise, the value is updated.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut map = BTreeMap::<usize, &str>::new();
assert_eq!(map.insert(37, "a"), None);
assert_eq!(map.len() == 0, false);

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map.get(&37).and_then(|e| Some(e.get().value)), Some("c"));
Source

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

Source

pub fn insert_cdc( &self, key: K, value: V, ) -> (Option<V>, Vec<ChangeEvent<Pair<K, V>>>)

Inserts a key-value pair into the map and returns old value (if it was already in set) with ChangeEvent’s that describes this insert action.

Source

pub fn checked_insert_cdc( &self, key: K, value: V, ) -> Option<Vec<ChangeEvent<Pair<K, V>>>>

Source

pub fn remove<Q>(&self, key: &Q) -> Option<(K, V)>
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized,

Removes a key from the map, returning the key and the value if the key was previously in the map.

The key may be any borrowed form of the map’s key type, but the ordering on the borrowed form must match the ordering on the key type.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let map = BTreeMap::<usize, &str>::new();
map.insert(1, "a");
assert_eq!(map.remove(&1), Some((1, "a")));
assert_eq!(map.remove(&1), None);
Source

pub fn remove_cdc<Q>( &self, key: &Q, ) -> (Option<(K, V)>, Vec<ChangeEvent<Pair<K, V>>>)
where Pair<K, V>: Borrow<Q> + Ord, Q: Ord + ?Sized,

Removes a key from the map, returning the key and the value if the key was previously in the map and ChangeEvents describing changes caused by this action.

Source

pub fn len(&self) -> usize

Returns the number of elements in the map.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut a = BTreeMap::<usize, &str>::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);
Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut a = BTreeMap::<usize, &str>::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());
Source

pub fn capacity(&self) -> usize

Returns the total number of allocated slots across all internal nodes.

This represents the number of key-value pairs the map can hold without reallocating memory in its internal vectors.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut a = BTreeMap::<usize, &str>::with_maximum_node_size(16);

a.insert(1, "a");
a.insert(2, "b");

// Capacity remains the same until node is split or reallocated
assert_eq!(a.capacity(), 16);
Source

pub fn node_count(&self) -> usize

Returns the total number of nodes.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut a = BTreeMap::<usize, &str>::with_maximum_node_size(16);

a.insert(1, "a");
a.insert(2, "b");

assert_eq!(a.node_count(), 1);
Source

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

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

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;

let mut map = BTreeMap::<usize, &str>::new();
map.insert(3, "c");
map.insert(2, "b");
map.insert(1, "a");

for (key, value) in map.iter() {
    println!("{key}: {value}");
}

let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((first_key, first_value), (1, "a"));
Source

pub fn range<Q, R>(&self, range: R) -> Range<'_, K, V, Node>
where Pair<K, V>: Borrow<Q>, Q: Ord + ?Sized, R: RangeBounds<Q>,

Constructs a double-ended iterator over a sub-range of elements in the map. The simplest way is to use the range syntax min..max, thus range(min..max) will yield elements from min (inclusive) to max (exclusive). The range may also be entered as (Bound<T>, Bound<T>), so for example range((Excluded(4), Included(10))) will yield a left-exclusive, right-inclusive range from 4 to 10.

§Panics

Panics if range start > end. Panics if range start == end and both bounds are Excluded.

§Examples

Basic usage:

use indexset::concurrent::map::BTreeMap;
use std::ops::Bound::Included;

let mut map = BTreeMap::<i32, &str>::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");
for (key, value) in map.range::<i32, _>((Included(&4), Included(&8))) {
    println!("{key}: {value}");
}
assert_eq!(Some((5, "b")), map.range(4..).next());

Trait Implementations§

Source§

impl<K, V, Node> Debug for BTreeMap<K, V, Node>
where K: Send + Ord + Clone + 'static + Debug, V: Send + Clone + 'static + Debug, Node: NodeLike<Pair<K, V>> + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K, V, Node> Default for BTreeMap<K, V, Node>
where K: Send + Ord + Clone, V: Send + Clone + 'static, Node: NodeLike<Pair<K, V>> + Send + 'static,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<K, V, Node = Vec<Pair<K, V>>> !Freeze for BTreeMap<K, V, Node>

§

impl<K, V, Node = Vec<Pair<K, V>>> !RefUnwindSafe for BTreeMap<K, V, Node>

§

impl<K, V, Node = Vec<Pair<K, V>>> !UnwindSafe for BTreeMap<K, V, Node>

§

impl<K, V, Node> Send for BTreeMap<K, V, Node>
where BTreeSet<Pair<K, V>, Node>: Send,

§

impl<K, V, Node> Sync for BTreeMap<K, V, Node>
where BTreeSet<Pair<K, V>, Node>: Sync,

§

impl<K, V, Node> Unpin for BTreeMap<K, V, Node>
where BTreeSet<Pair<K, V>, Node>: Unpin,

§

impl<K, V, Node> UnsafeUnpin for BTreeMap<K, V, Node>
where BTreeSet<Pair<K, V>, Node>: UnsafeUnpin,

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.