pub struct BTreeMultiMap<K, V, Node = Vec<MultiPair<K, V>>, M = MultiPair<K, V>>where
K: Debug + Send + Ord + Clone + 'static,
V: Debug + Send + Clone + 'static,
M: MultiPairLike<K, V> + Debug + Clone + Send + 'static,
Node: NodeLike<M> + Send + 'static,{ /* private fields */ }Implementations§
Source§impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
Sourcepub fn new() -> Self
pub fn new() -> Self
Makes a new, empty, persistent BTreeMultiMap.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut map = BTreeMultiMap::<usize, &str>::new();
// entries can now be inserted into the empty map
map.insert(1, "a");Sourcepub fn with_maximum_node_size(node_capacity: usize) -> Self
pub fn with_maximum_node_size(node_capacity: usize) -> Self
Makes a new, empty BTreeMultiMap with the given maximum node size. Allocates one vec with
the capacity set to be the specified node size.
§Examples
use indexset::concurrent::multimap::BTreeMultiMap;
let map = BTreeMultiMap::<i32, i32>::with_maximum_node_size(128);Sourcepub fn attach_multi_node(&self, node: Node)
pub fn attach_multi_node(&self, node: Node)
Adds full [Node] to this multiset. [Node] should be correct node with
values sorted.
Sourcepub fn attach_multi_nodes(&self, nodes: impl IntoIterator<Item = Node>)
pub fn attach_multi_nodes(&self, nodes: impl IntoIterator<Item = Node>)
Attaches persisted [Node]s with one topology publication.
Sourcepub fn snapshot_nodes(&self) -> Vec<Node>where
Node: Clone,
pub fn snapshot_nodes(&self) -> Vec<Node>where
Node: Clone,
Returns detached, read-only snapshots of this multimap’s [Node]s.
Callers requiring one coherent logical generation must prevent concurrent mutation while collecting.
Sourcepub fn contains_key<Q>(&self, key: &Q) -> bool
pub fn contains_key<Q>(&self, key: &Q) -> bool
Returns true if the map contains at least one occurance of 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::multimap::BTreeMultiMap;
let mut map = BTreeMultiMap::<usize, &str>::new();
map.insert(1, "a");
map.insert(1, "b");
assert_eq!(map.contains_key(&1), true);
assert_eq!(map.contains_key(&2), false);Sourcepub fn get(&self, key: &K) -> Range<'_, K, V, Node, M> ⓘwhere
M: Borrow<K>,
pub fn get(&self, key: &K) -> Range<'_, K, V, Node, M> ⓘwhere
M: Borrow<K>,
Constructs a double-ended iterator over all key value pairs with the given key in the map.
use indexset::concurrent::multimap::BTreeMultiMap;
use indexset::BTreeSet;
let mut map = BTreeMultiMap::<usize, &str>::new();
map.insert(1, "b");
map.insert(1, "a");
map.insert(2, "c");
let all_with_key = map.get(&1).collect::<BTreeSet<_>>();
assert_eq!(all_with_key.len(), 2);
assert_eq!(all_with_key, vec![(1, "a"), (1, "b")].into_iter().collect::<BTreeSet<_>>());Sourcepub fn remove_some<Q>(&self, key: &Q) -> Option<(K, V)>
pub fn remove_some<Q>(&self, key: &Q) -> Option<(K, V)>
Removes some key from the map that matches the given key, 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::multimap::BTreeMultiMap;
let map = BTreeMultiMap::<usize, &str>::new();
map.insert(1, "b");
map.insert(1, "a");
let first_removed = map.remove_some(&1).unwrap();
let second_removed = map.remove_some(&1).unwrap();
let removals = vec![first_removed, second_removed];
assert!(removals.contains(&(1, "a")));
assert!(removals.contains(&(1, "b")));Sourcepub fn remove_some_cdc<Q>(
&self,
key: &Q,
) -> (Option<(K, V)>, Vec<ChangeEvent<M>>)
pub fn remove_some_cdc<Q>( &self, key: &Q, ) -> (Option<(K, V)>, Vec<ChangeEvent<M>>)
Removes some key from the map that matches the given key, returning the
key and the value if the key was previously in the map with
ChangeEvent’s describing this remove_some action.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the map.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut a = BTreeMultiMap::<usize, &str>::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the multimap contains no elements.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut a = BTreeMultiMap::<usize, &str>::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());Sourcepub fn capacity(&self) -> usize
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 multimap can hold without reallocating memory in its internal vectors.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut a = BTreeMultiMap::<usize, &str>::with_maximum_node_size(8);
a.insert(1, "a");
a.insert(1, "b");
// Capacity remains unchanged until reallocation occurs
assert_eq!(a.capacity(), 8);Sourcepub fn node_count(&self) -> usize
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);Sourcepub fn iter(&self) -> Iter<'_, K, V, Node, M> ⓘ
pub fn iter(&self) -> Iter<'_, K, V, Node, M> ⓘ
Gets an iterator over the entries of the map, sorted by key.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut map = BTreeMultiMap::<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"));Sourcepub fn range<R>(&self, range: R) -> Range<'_, K, V, Node, M> ⓘwhere
M: Borrow<K>,
R: RangeBounds<K>,
pub fn range<R>(&self, range: R) -> Range<'_, K, V, Node, M> ⓘwhere
M: Borrow<K>,
R: RangeBounds<K>,
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::multimap::BTreeMultiMap;
use std::ops::Bound::Included;
let mut map = BTreeMultiMap::<usize, &str>::new();
map.insert(3, "a");
map.insert(5, "b");
map.insert(8, "c");
for (key, value) in map.range((Included(&4), Included(&8))) {
println!("{key}: {value}");
}
assert_eq!(Some((5, "b")), map.range(4..).next());Source§impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
Sourcepub fn insert(&self, key: K, value: V) -> Option<V>
pub fn insert(&self, key: K, value: V) -> Option<V>
Inserts a key-value pair into the multi map.
The logical identity of an entry is the (key, value) pair: inserting
a pair that is already present (by the representation’s value
equality) replaces it in place and returns the old value, while a new
pair is added alongside the key’s other values.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let mut map = BTreeMultiMap::<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"), None);
assert_eq!(map.insert(37, "a"), Some("a"));
assert_eq!(map.len(), 3);Sourcepub fn insert_cdc(&self, key: K, value: V) -> (Option<V>, Vec<ChangeEvent<M>>)
pub fn insert_cdc(&self, key: K, value: V) -> (Option<V>, Vec<ChangeEvent<M>>)
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. See BTreeMultiMap::insert for the replace semantics.
Source§impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
impl<K, V, Node, M> BTreeMultiMap<K, V, Node, M>
Sourcepub fn remove(&self, key: &K, value: &V) -> Option<(K, V)>
pub fn remove(&self, key: &K, value: &V) -> Option<(K, V)>
Removes a specific key-value pair from the map returning the key and the value if the key was previously in the map.
§Examples
Basic usage:
use indexset::concurrent::multimap::BTreeMultiMap;
let map = BTreeMultiMap::<usize, &str>::new();
map.insert(1, "b");
map.insert(1, "a");
assert_eq!(map.remove(&1, &"a"), Some((1, "a")));
assert_eq!(map.remove(&1, &"b"), Some((1, "b")));Sourcepub fn remove_cdc(
&self,
key: &K,
value: &V,
) -> (Option<(K, V)>, Vec<ChangeEvent<M>>)
pub fn remove_cdc( &self, key: &K, value: &V, ) -> (Option<(K, V)>, Vec<ChangeEvent<M>>)
Removes a specific key-value pair from the map returning the key and the
value if the key was previously in the map with ChangeEvent’s
describing this remove_some action.