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
keyitself is not in the index. -
In the special case when there are keys in the trie for which our
keyis 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.