pub struct LexiconInterner { /* private fields */ }Expand description
Collision-aware string interner — the lexicon collision backstop (task #22).
The plain build-time map (HashMap<u64, String> in external_sort) silently
OVERWRITES on a handle collision (two distinct strings hashing to the same 60-bit
token), losing data with no signal. This interner DETECTS the collision at intern
time — O(1), off the resolution hot path — and KEEPS BOTH values, so a collision
becomes loud + recoverable rather than silent corruption. Resolution stays
single-value and fast for the (overwhelmingly common) collision-free handles; only
a flagged handle pays a comparison over its small bucket (length-gated by str eq),
from memory. This is a host-side structure (HashMap/String), separate from the
42 MB SlgArena — its allocations are one-time intern cost, not per-resolution.
Implementations§
Source§impl LexiconInterner
impl LexiconInterner
pub fn new() -> Self
Sourcepub fn intern_str(&mut self, value: &str) -> Intern
pub fn intern_str(&mut self, value: &str) -> Intern
Intern (generate_60bit_token(value), value). Returns the collision outcome.
Sourcepub fn intern(&mut self, handle: u64, value: &str) -> Intern
pub fn intern(&mut self, handle: u64, value: &str) -> Intern
Intern an explicit (handle, value) pair — the handle need not be
generate_60bit_token(value) (e.g. did:q42 / Webizen handles). Detects a
same-handle / different-value collision and preserves both values.
Sourcepub fn is_collision(&self, handle: u64) -> bool
pub fn is_collision(&self, handle: u64) -> bool
Whether handle has more than one distinct interned value (a collision).
Sourcepub fn resolve(&self, handle: u64) -> Option<&str>
pub fn resolve(&self, handle: u64) -> Option<&str>
Resolve handle -> value with collision awareness. Collision-free (common): the
single value, no comparison. Collided (rare): None — there is no single answer,
so the caller disambiguates with the query value via Self::resolve_value
rather than receiving a silently-wrong one.
Trait Implementations§
Source§impl Default for LexiconInterner
impl Default for LexiconInterner
Source§fn default() -> LexiconInterner
fn default() -> LexiconInterner
Auto Trait Implementations§
impl Freeze for LexiconInterner
impl RefUnwindSafe for LexiconInterner
impl Send for LexiconInterner
impl Sync for LexiconInterner
impl Unpin for LexiconInterner
impl UnsafeUnpin for LexiconInterner
impl UnwindSafe for LexiconInterner
Blanket Implementations§
§impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
impl<S, A> Aggregate<Result<S, Error>> for Awhere
A: Aggregate<S>,
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<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