X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Findexed_map.rs;h=39565f048c07a25f30a6749b5057a55a15278664;hb=bedc2c64fcfe5fa5f85ded630e9ed2eb3c3651eb;hp=3d45172517db3e706dcbf4884dd75923c872c8a5;hpb=62a88f97de725c366665a34c8183747024970fa6;p=rust-lightning diff --git a/lightning/src/util/indexed_map.rs b/lightning/src/util/indexed_map.rs index 3d451725..39565f04 100644 --- a/lightning/src/util/indexed_map.rs +++ b/lightning/src/util/indexed_map.rs @@ -21,6 +21,8 @@ use core::ops::{Bound, RangeBounds}; /// 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. +/// /// [`BTreeMap`]: alloc::collections::BTreeMap #[derive(Clone, Debug, Eq)] pub struct IndexedMap { @@ -37,6 +39,14 @@ impl IndexedMap { } } + /// Constructs a new, empty map with the given capacity pre-allocated + pub fn with_capacity(capacity: usize) -> Self { + Self { + map: HashMap::with_capacity(capacity), + keys: Vec::with_capacity(capacity), + } + } + #[inline(always)] /// Fetches the element with the given `key`, if one exists. pub fn get(&self, key: &K) -> Option<&V> { @@ -147,6 +157,8 @@ impl PartialEq for IndexedMap { } /// An iterator over a range of values in an [`IndexedMap`] +/// +/// This is not exported to bindings users as bindings provide alternate accessors rather than exposing maps directly. pub struct Range<'a, K: Hash + Ord, V> { inner_range: Iter<'a, K>, map: &'a HashMap, @@ -161,6 +173,8 @@ impl<'a, K: Hash + Ord, V: 'a> Iterator for Range<'a, K, V> { } /// An [`Entry`] for a key which currently has no value +/// +/// This is not exported to bindings users as bindings provide alternate accessors rather than exposing maps directly. pub struct VacantEntry<'a, K: Hash + Ord, V> { #[cfg(feature = "hashbrown")] underlying_entry: hash_map::VacantEntry<'a, K, V, hash_map::DefaultHashBuilder>, @@ -171,6 +185,8 @@ pub struct VacantEntry<'a, K: Hash + Ord, V> { } /// An [`Entry`] for an existing key-value pair +/// +/// This is not exported to bindings users as bindings provide alternate accessors rather than exposing maps directly. pub struct OccupiedEntry<'a, K: Hash + Ord, V> { #[cfg(feature = "hashbrown")] underlying_entry: hash_map::OccupiedEntry<'a, K, V, hash_map::DefaultHashBuilder>, @@ -181,6 +197,8 @@ pub struct OccupiedEntry<'a, K: Hash + Ord, V> { /// A mutable reference to a position in the map. This can be used to reference, add, or update the /// value at a fixed key. +/// +/// This is not exported to bindings users as bindings provide alternate accessors rather than exposing maps directly. pub enum Entry<'a, K: Hash + Ord, V> { /// A mutable reference to a position within the map where there is no value. Vacant(VacantEntry<'a, K, V>),