pub struct ListByRelayIds<H: HasRelayIds>{
rsa_map: HashMap<RsaIdentity, SmallVec<[usize; 4]>>,
ed25519_map: HashMap<Ed25519Identity, SmallVec<[usize; 4]>>,
values: Slab<H>,
}
Expand description
A list of objects that can be accessed by relay identity.
Multiple objects in the list can have a given relay identity.
§Invariants
Every object in the list must have at least one recognized relay identity; if it does not, it cannot be inserted.
This list may panic or give incorrect results if the values can change their keys through interior mutability.
§General information
A list of elements of type H
whose members can be accessed by multiple keys.
The keys are:
rsa
(RsaIdentity
) (Option)ed25519
(Ed25519Identity
) (Option)
Each element has a value for each required key, and up to one value for each optional key. There can be many elements for a given key value.
§Requirements
Key types must have consistent Hash
and Eq
implementations, as they will be used as keys
in a HashMap
.
If all keys are optional, then every element inserted must have at least one non-None
key.
An element must not change its keys over time through interior mutability.
If any of these rules is violated, the consequences are unspecified, and could include panics or wrong answers (but not memory-unsafety).
Fields§
§rsa_map: HashMap<RsaIdentity, SmallVec<[usize; 4]>>
The $key fields here are a set of maps from each of the key values to the lists of the positions of values with the same key within the Slab.
Invariants:
- There is an entry K=>idx in the map
$key
if and only if values[idx].$accessor() == K. - Every value in
values
has at least one key. - A list should never be empty.
The map values (the lists) are effectively a set, but using an inline vec should have better cache performance than something like HashSet.
The SmallVec size of 4 was chosen arbitrarily under the assumption that a given key will have a small number of values on average. The exact constant probably won’t matter, but inlining most of the lists should be good even if some spill into separate memory allocations. It’s not worth exposing this level of internal detail to the macro caller unless there’s a reason we need to.
ed25519_map: HashMap<Ed25519Identity, SmallVec<[usize; 4]>>
§values: Slab<H>
A map from the indices to the values.
Implementations§
Source§impl<H: HasRelayIds> ListByRelayIds<H>
impl<H: HasRelayIds> ListByRelayIds<H>
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new ListByRelayIds
.
Sourcepub fn with_capacity(n: usize) -> Self
pub fn with_capacity(n: usize) -> Self
Construct a new ListByRelayIds
with a given capacity.
Sourcepub fn by_rsa<BorrowAsKey_>(
&self,
key: &BorrowAsKey_,
) -> ListByRelayIdsIter<'_, H> ⓘ
pub fn by_rsa<BorrowAsKey_>( &self, key: &BorrowAsKey_, ) -> ListByRelayIdsIter<'_, H> ⓘ
Return an iterator of the elements whose rsa
is key
.
The iteration order is arbitrary.
Sourcepub fn contains_rsa<BorrowAsKey_>(&mut self, key: &BorrowAsKey_) -> bool
pub fn contains_rsa<BorrowAsKey_>(&mut self, key: &BorrowAsKey_) -> bool
Return true
if this list contains an element whose rsa
is key
.
Sourcepub fn remove_by_rsa<BorrowAsKey_>(
&mut self,
key: &BorrowAsKey_,
filter: impl FnMut(&H) -> bool,
) -> Vec<H>
pub fn remove_by_rsa<BorrowAsKey_>( &mut self, key: &BorrowAsKey_, filter: impl FnMut(&H) -> bool, ) -> Vec<H>
Remove and return the elements whose rsa
is key
and where filter
returns true
.
Sourcepub fn by_ed25519<BorrowAsKey_>(
&self,
key: &BorrowAsKey_,
) -> ListByRelayIdsIter<'_, H> ⓘ
pub fn by_ed25519<BorrowAsKey_>( &self, key: &BorrowAsKey_, ) -> ListByRelayIdsIter<'_, H> ⓘ
Return an iterator of the elements whose ed25519
is key
.
The iteration order is arbitrary.
Sourcepub fn contains_ed25519<BorrowAsKey_>(&mut self, key: &BorrowAsKey_) -> bool
pub fn contains_ed25519<BorrowAsKey_>(&mut self, key: &BorrowAsKey_) -> bool
Return true
if this list contains an element whose ed25519
is key
.
Sourcepub fn remove_by_ed25519<BorrowAsKey_>(
&mut self,
key: &BorrowAsKey_,
filter: impl FnMut(&H) -> bool,
) -> Vec<H>
pub fn remove_by_ed25519<BorrowAsKey_>( &mut self, key: &BorrowAsKey_, filter: impl FnMut(&H) -> bool, ) -> Vec<H>
Remove and return the elements whose ed25519
is key
and where filter
returns true
.
fn remove_at(&mut self, idx: usize) -> Option<H>
Sourcepub fn values(&self) -> impl Iterator<Item = &H> + '_
pub fn values(&self) -> impl Iterator<Item = &H> + '_
Return an iterator over the elements in this container.
Sourcepub fn into_values(self) -> impl Iterator<Item = H>
pub fn into_values(self) -> impl Iterator<Item = H>
Consume this container and return an iterator of its values.
Sourcepub fn try_insert(&mut self, value: H) -> Result<(), Error>
pub fn try_insert(&mut self, value: H) -> Result<(), Error>
Try to insert value
.
Return Error::NoKeys
if all the keys are optional, and value
has no keys at all.
Sourcepub fn insert(&mut self, value: H)
pub fn insert(&mut self, value: H)
See try_insert
. Panicks on errors.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Return the number of elements for which this container has allocated storage.
Sourcepub fn retain<F>(&mut self, pred: F)
pub fn retain<F>(&mut self, pred: F)
Remove every element that does not satisfy the predicate pred
.
Sourcefn compact(&mut self)
fn compact(&mut self)
Re-index all the values in this map, so that the map can use a more compact representation.
This should be done infrequently; it’s expensive.
Sourcefn check_consistency(&self)
fn check_consistency(&self)
Assert that this list appears to be in an internally consistent state.
This method can be very expensive, and it should never fail unless your code has a bug.
§Panics
Panics if it finds bugs in this object, or constraint violations in its elements. See the (type documentation)Self for a list of constraints.
Source§impl<H: HasRelayIds> ListByRelayIds<H>
impl<H: HasRelayIds> ListByRelayIds<H>
Sourcepub fn by_id<'a, T>(&self, key: T) -> ListByRelayIdsIter<'_, H> ⓘwhere
T: Into<RelayIdRef<'a>>,
pub fn by_id<'a, T>(&self, key: T) -> ListByRelayIdsIter<'_, H> ⓘwhere
T: Into<RelayIdRef<'a>>,
Return an iterator of the values in this list that have the key key
.
Sourcepub fn by_all_ids<'a>(
&'a self,
key: &'a impl HasRelayIds,
) -> impl Iterator<Item = &'a H> + 'a
pub fn by_all_ids<'a>( &'a self, key: &'a impl HasRelayIds, ) -> impl Iterator<Item = &'a H> + 'a
Return the values in this list that have all the relay IDs that key
does.
Returns an empty iterator if key
has no relay IDs.
Sourcepub fn all_overlapping<T>(&self, key: &T) -> Vec<&H>where
T: HasRelayIds,
pub fn all_overlapping<T>(&self, key: &T) -> Vec<&H>where
T: HasRelayIds,
Return a reference to every element in this set that shares any ID with key
.
No element is returned more than once. Equality is compared using
ByAddress
.
Sourcepub fn all_subset<T>(&self, key: &T) -> Vec<&H>where
T: HasRelayIds,
pub fn all_subset<T>(&self, key: &T) -> Vec<&H>where
T: HasRelayIds,
Return a reference to every element in this list whose relay IDs are a subset of the relay
IDs that key
has.
No element is returned more than once. Equality is compared using
ByAddress
.
Sourcepub fn remove_by_id<'a, T>(
&mut self,
key: T,
filter: impl FnMut(&H) -> bool,
) -> Vec<H>where
T: Into<RelayIdRef<'a>>,
pub fn remove_by_id<'a, T>(
&mut self,
key: T,
filter: impl FnMut(&H) -> bool,
) -> Vec<H>where
T: Into<RelayIdRef<'a>>,
Return the values in this list that have the key key
and where filter
returns true
.
Sourcepub fn remove_exact<T>(&mut self, key: &T) -> Vec<H>where
T: HasRelayIds,
pub fn remove_exact<T>(&mut self, key: &T) -> Vec<H>where
T: HasRelayIds,
Remove and return the values in this list that have exactly the same relay IDs that key
does.
Sourcepub fn remove_by_all_ids<T>(&mut self, key: &T) -> Vec<H>where
T: HasRelayIds,
pub fn remove_by_all_ids<T>(&mut self, key: &T) -> Vec<H>where
T: HasRelayIds,
Remove and return the values in this list that have all the same relay IDs that key
does.
If key
has no relay IDs, then no values are removed.
Trait Implementations§
Source§impl<H: Clone + HasRelayIds> Clone for ListByRelayIds<H>
impl<H: Clone + HasRelayIds> Clone for ListByRelayIds<H>
Source§fn clone(&self) -> ListByRelayIds<H>
fn clone(&self) -> ListByRelayIds<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<H: Debug + HasRelayIds> Debug for ListByRelayIds<H>
impl<H: Debug + HasRelayIds> Debug for ListByRelayIds<H>
Source§impl<H: HasRelayIds> Default for ListByRelayIds<H>
impl<H: HasRelayIds> Default for ListByRelayIds<H>
Source§impl<H: HasRelayIds> FromIterator<H> for ListByRelayIds<H>
impl<H: HasRelayIds> FromIterator<H> for ListByRelayIds<H>
Source§fn from_iter<IntoIter_>(iter: IntoIter_) -> Selfwhere
IntoIter_: IntoIterator<Item = H>,
fn from_iter<IntoIter_>(iter: IntoIter_) -> Selfwhere
IntoIter_: IntoIterator<Item = H>,
Auto Trait Implementations§
impl<H> Freeze for ListByRelayIds<H>
impl<H> RefUnwindSafe for ListByRelayIds<H>
impl<H> Send for ListByRelayIds<H>
impl<H> Sync for ListByRelayIds<H>
impl<H> Unpin for ListByRelayIds<H>
impl<H> UnwindSafe for ListByRelayIds<H>
Blanket Implementations§
§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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more