Struct breez_sdk_core::lightning::util::indexed_map::IndexedMap
pub struct IndexedMap<K, V>{ /* private fields */ }
Expand description
A map which can be iterated in a deterministic order.
This would traditionally be accomplished by simply using a BTreeMap
, however B-Trees
generally have very slow lookups. Because we use a nodes+channels map while finding routes
across the network graph, our network graph backing map must be as performant as possible.
However, because peers expect to sync the network graph from us (and we need to support that
without holding a lock on the graph for the duration of the sync or dumping the entire graph
into our outbound message queue), we need an iterable map with a consistent iteration order we
can jump to a starting point on.
Thus, we have a custom data structure here - its API mimics that of Rust’s BTreeMap
, but is
actually backed by a HashMap
, with some additional tracking to ensure we can iterate over
keys in the order defined by Ord
.
This is not exported to bindings users as bindings provide alternate accessors rather than exposing maps directly.
Implementations§
§impl<K, V> IndexedMap<K, V>
impl<K, V> IndexedMap<K, V>
pub fn new() -> IndexedMap<K, V>
pub fn new() -> IndexedMap<K, V>
Constructs a new, empty map
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
pub fn get_mut(&mut self, key: &K) -> Option<&mut V>
Fetches a mutable reference to the element with the given key
, if one exists.
pub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Returns true if an element with the given key
exists in the map.
pub fn remove(&mut self, key: &K) -> Option<V>
pub fn remove(&mut self, key: &K) -> Option<V>
Removes the element with the given key
, returning it, if one exists.
pub fn insert(&mut self, key: K, value: V) -> Option<V>
pub fn insert(&mut self, key: K, value: V) -> Option<V>
Inserts the given key
/value
pair into the map, returning the element that was
previously stored at the given key
, if one exists.
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
pub fn entry(&mut self, key: K) -> Entry<'_, K, V>
Returns an Entry
for the given key
in the map, allowing access to the value.
pub fn unordered_keys(&self) -> impl Iterator<Item = &K>
pub fn unordered_keys(&self) -> impl Iterator<Item = &K>
Returns an iterator which iterates over the keys in the map, in a random order.
pub fn unordered_iter(&self) -> impl Iterator<Item = (&K, &V)>
pub fn unordered_iter(&self) -> impl Iterator<Item = (&K, &V)>
Returns an iterator which iterates over the key
/value
pairs in a random order.
pub fn unordered_iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
pub fn unordered_iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)>
Returns an iterator which iterates over the key
s and mutable references to value
s in a
random order.
pub fn range<R>(&mut self, range: R) -> Range<'_, K, V> ⓘwhere
R: RangeBounds<K>,
pub fn range<R>(&mut self, range: R) -> Range<'_, K, V> ⓘwhere
R: RangeBounds<K>,
Returns an iterator which iterates over the key
/value
pairs in a given range.
Trait Implementations§
§impl<K, V> Clone for IndexedMap<K, V>
impl<K, V> Clone for IndexedMap<K, V>
§fn clone(&self) -> IndexedMap<K, V>
fn clone(&self) -> IndexedMap<K, V>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<K, V> Debug for IndexedMap<K, V>
impl<K, V> Debug for IndexedMap<K, V>
§impl<K, V> PartialEq for IndexedMap<K, V>
impl<K, V> PartialEq for IndexedMap<K, V>
impl<K, V> Eq for IndexedMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for IndexedMap<K, V>
impl<K, V> RefUnwindSafe for IndexedMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for IndexedMap<K, V>
impl<K, V> Sync for IndexedMap<K, V>
impl<K, V> Unpin for IndexedMap<K, V>
impl<K, V> UnwindSafe for IndexedMap<K, V>where
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<T> Downcast for Twhere
T: AsAny + ?Sized,
impl<T> Downcast for Twhere
T: AsAny + ?Sized,
§fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
fn downcast_ref<T>(&self) -> Option<&T>where
T: AsAny,
Any
.§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: AsAny,
Any
.source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request