pub struct PrefixSetMut { /* private fields */ }Expand description
A container for efficiently storing and checking for the presence of key prefixes.
This data structure stores a set of Nibbles and provides methods to insert
new elements and check whether any existing element has a given prefix.
Internally, this implementation stores keys in an unsorted Vec<Nibbles> together with an
all flag. The all flag indicates that every entry should be considered changed and that
individual keys can be ignored.
Sorting and deduplication do not happen during insertion or membership checks on this mutable
structure. Instead, keys are sorted and deduplicated when converting into the immutable
PrefixSet via freeze(). The immutable PrefixSet provides contains and relies on the
sorted and unique keys produced by freeze(); it does not perform additional sorting or
deduplication.
This guarantees that a PrefixSet constructed from a PrefixSetMut is always sorted and
deduplicated.
§Examples
use reth_trie_common::{prefix_set::PrefixSetMut, Nibbles};
let mut prefix_set_mut = PrefixSetMut::default();
prefix_set_mut.insert(Nibbles::from_nibbles_unchecked(&[0xa, 0xb]));
prefix_set_mut.insert(Nibbles::from_nibbles_unchecked(&[0xa, 0xb, 0xc]));
let mut prefix_set = prefix_set_mut.freeze();
assert!(prefix_set.contains(&Nibbles::from_nibbles_unchecked([0xa, 0xb])));
assert!(prefix_set.contains(&Nibbles::from_nibbles_unchecked([0xa, 0xb, 0xc])));Implementations§
Source§impl PrefixSetMut
impl PrefixSetMut
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create PrefixSetMut with pre-allocated capacity.
Sourcepub const fn all() -> Self
pub const fn all() -> Self
Create PrefixSetMut that considers all key changed.
Sourcepub fn extend_ref(&mut self, other: &Self)
pub fn extend_ref(&mut self, other: &Self)
Extend prefix set with contents of another prefix set by reference.
Sourcepub fn append(&mut self, other: &mut Self)
pub fn append(&mut self, other: &mut Self)
Appends prefix set keys from another mutable prefix set, leaving it empty.
Sourcepub fn extend_keys<I>(&mut self, keys: I)where
I: IntoIterator<Item = Nibbles>,
pub fn extend_keys<I>(&mut self, keys: I)where
I: IntoIterator<Item = Nibbles>,
Extend prefix set keys with contents of provided iterator.
Trait Implementations§
Source§impl Clone for PrefixSetMut
impl Clone for PrefixSetMut
Source§impl Debug for PrefixSetMut
impl Debug for PrefixSetMut
Source§impl Default for PrefixSetMut
impl Default for PrefixSetMut
impl Eq for PrefixSetMut
Source§impl<I> From<I> for PrefixSetMutwhere
I: IntoIterator<Item = Nibbles>,
impl<I> From<I> for PrefixSetMutwhere
I: IntoIterator<Item = Nibbles>,
Source§impl<'a> IntoIterator for &'a PrefixSetMut
impl<'a> IntoIterator for &'a PrefixSetMut
Source§impl PartialEq for PrefixSetMut
impl PartialEq for PrefixSetMut
impl StructuralPartialEq for PrefixSetMut
Auto Trait Implementations§
impl Freeze for PrefixSetMut
impl RefUnwindSafe for PrefixSetMut
impl Send for PrefixSetMut
impl Sync for PrefixSetMut
impl Unpin for PrefixSetMut
impl UnsafeUnpin for PrefixSetMut
impl UnwindSafe for PrefixSetMut
Blanket Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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<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<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> 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 moreimpl<T> MaybeDebug for Twhere
T: Debug,
§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘwhere
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes