pub struct IdIndex<K, P, const N: usize> { /* private fields */ }
Expand description
In-memory immutable index to do prefix lookup of key K
through P
.
In a nutshell, this is a mapping of K
-> P
-> S::Entry
where S: IdIndexSource<P>
. The source table S
isn’t owned by this index.
This index stores first N
bytes of each key K
associated with the
pointer P
. K
may be a heap-allocated object. P
is supposed to be
a cheap value type like u32
or usize
. As the index entry of type
([u8; N], P)
is small and has no indirect reference, constructing
the index should be faster than sorting the source (K, _)
pairs.
A key K
must be at least N
bytes long.
Implementations§
Source§impl<K, P, const N: usize> IdIndex<K, P, N>
impl<K, P, const N: usize> IdIndex<K, P, N>
pub fn builder() -> IdIndexBuilder<K, P, N>
pub fn with_capacity(capacity: usize) -> IdIndexBuilder<K, P, N>
Sourcepub fn resolve_prefix_with<B, S, U>(
&self,
source: S,
prefix: &HexPrefix,
entry_mapper: impl FnMut(S::Entry) -> U,
) -> PrefixResolution<(K, B)>
pub fn resolve_prefix_with<B, S, U>( &self, source: S, prefix: &HexPrefix, entry_mapper: impl FnMut(S::Entry) -> U, ) -> PrefixResolution<(K, B)>
Looks up entries with the given prefix, and collects values if matched entries have unambiguous keys.
Sourcepub fn resolve_prefix_to_key<S>(
&self,
source: S,
prefix: &HexPrefix,
) -> PrefixResolution<K>
pub fn resolve_prefix_to_key<S>( &self, source: S, prefix: &HexPrefix, ) -> PrefixResolution<K>
Looks up unambiguous key with the given prefix.
Sourcepub fn lookup_exact<'i, 'q, S>(
&'i self,
source: S,
key: &'q K,
) -> Option<IdIndexLookup<'i, 'q, K, P, S, N>>
pub fn lookup_exact<'i, 'q, S>( &'i self, source: S, key: &'q K, ) -> Option<IdIndexLookup<'i, 'q, K, P, S, N>>
Looks up entry for the key. Returns accessor to neighbors.
Sourcepub fn shortest_unique_prefix_len<S>(&self, source: S, key: &K) -> usize
pub fn shortest_unique_prefix_len<S>(&self, source: S, key: &K) -> usize
This function returns the shortest length of a prefix of key
that
disambiguates it from every other key in the index.
The length to be returned is a number of hexadecimal digits.
This has some properties that we do not currently make much use of:
-
The algorithm works even if
key
itself is not in the index. -
In the special case when there are keys in the trie for which our
key
is an exact prefix, returnskey.len() + 1
. Conceptually, in order to disambiguate, you need every letter of the key and the additional fact that it’s the entire key). This case is extremely unlikely for hashes with 12+ hexadecimal characters.
Trait Implementations§
Auto Trait Implementations§
impl<K, P, const N: usize> Freeze for IdIndex<K, P, N>
impl<K, P, const N: usize> RefUnwindSafe for IdIndex<K, P, N>where
K: RefUnwindSafe,
P: RefUnwindSafe,
impl<K, P, const N: usize> Send for IdIndex<K, P, N>
impl<K, P, const N: usize> Sync for IdIndex<K, P, N>
impl<K, P, const N: usize> Unpin for IdIndex<K, P, N>
impl<K, P, const N: usize> UnwindSafe for IdIndex<K, P, N>where
K: UnwindSafe,
P: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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