Struct breez_sdk_liquid::lightning::util::indexed_map::IndexedMap

pub struct IndexedMap<K, V>
where K: Hash + Ord,
{ /* 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>
where K: Clone + Hash + Ord,

pub fn new() -> IndexedMap<K, V>

Constructs a new, empty map

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

Fetches the element with the given key, if one exists.

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

Returns true if an element with the given key exists in the map.

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>

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>

Returns an Entry for the given key in the map, allowing access to the value.

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)>

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)>

Returns an iterator which iterates over the keys and mutable references to values in a random order.

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.

pub fn len(&self) -> usize

Returns the number of key/value pairs in the map

pub fn is_empty(&self) -> bool

Returns true if there are no elements in the map

Trait Implementations§

§

impl<K, V> Clone for IndexedMap<K, V>
where K: Clone + Hash + Ord, V: Clone,

§

fn clone(&self) -> IndexedMap<K, V>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<K, V> Debug for IndexedMap<K, V>
where K: Debug + Hash + Ord, V: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<K, V> PartialEq for IndexedMap<K, V>
where K: Hash + Ord + PartialEq, V: PartialEq,

§

fn eq(&self, other: &IndexedMap<K, V>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<K, V> Eq for IndexedMap<K, V>
where K: Eq + Hash + Ord, V: Eq,

Auto Trait Implementations§

§

impl<K, V> Freeze for IndexedMap<K, V>

§

impl<K, V> RefUnwindSafe for IndexedMap<K, V>

§

impl<K, V> Send for IndexedMap<K, V>
where K: Send, V: Send,

§

impl<K, V> Sync for IndexedMap<K, V>
where K: Sync, V: Sync,

§

impl<K, V> Unpin for IndexedMap<K, V>
where K: Unpin, V: Unpin,

§

impl<K, V> UnwindSafe for IndexedMap<K, V>
where K: UnwindSafe, V: 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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

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

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where 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 T
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

§

impl<T> TaskRetFutTrait for T
where T: Send,