pub struct Q42LexMmap<'a> { /* private fields */ }Expand description
Zero-allocation view over a memory-mapped .q42.lex slice (sorted hash index).
Implementations§
Source§impl<'a> Q42LexMmap<'a>
impl<'a> Q42LexMmap<'a>
Sourcepub fn from_bytes(data: &'a [u8]) -> Result<Self, LexError>
pub fn from_bytes(data: &'a [u8]) -> Result<Self, LexError>
Parse a Q42LEX byte slice (typically from mmap).
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Lexicon entry count.
Sourcepub fn lex_format_version(&self) -> u64
pub fn lex_format_version(&self) -> u64
The Q42LEX format version word (1 flat, 2 paged, 4 namespaced paged). Lets tooling gate migrations on the lexicon generation actually on disk instead of guessing from the volume version.
Sourcepub fn hash_at(&self, i: usize) -> Option<u64>
pub fn hash_at(&self, i: usize) -> Option<u64>
Hash at sorted ordinal i, independent of whether the lexicon is the
legacy flat layout or the paged v2 layout. Cold loaders use this rather
than reaching into an on-disk index with v1 assumptions.
Sourcepub fn lookup_hash(&self, hash: u64) -> Option<&'a str>
pub fn lookup_hash(&self, hash: u64) -> Option<&'a str>
Binary search for hash in the sorted index; returns the UTF-8 lexeme
slice for verbatim (0x01) entries only. v4 namespaced entries
return None — their bytes are not contiguous — so prefer
Self::lookup_parts, Self::lookup_owned, or
Self::resolve_term_into when the lexicon may be v4.
Sourcepub fn string_at(&self, i: usize) -> Option<&'a str>
pub fn string_at(&self, i: usize) -> Option<&'a str>
The lexeme string of the i-th index entry (0..entry_count), if it is a UTF-8 string entry
(not an embedded-triple / Webizen entry). Verbatim entries only — v4 namespaced entries
return None; use Self::string_parts_at. Enables iterating ALL lexicon strings without knowing
their hashes — e.g. to assemble a calibration corpus from a WordNet q42’s gloss text.
Sourcepub fn lookup_parts(&self, hash: u64) -> Option<(&'a str, &'a str)>
pub fn lookup_parts(&self, hash: u64) -> Option<(&'a str, &'a str)>
Resolve hash to its (namespace, local) parts without copying.
Verbatim entries return ("", full_term); v4 namespaced entries
return the two borrowed slices from the page’s namespace table and
entry payload. Reassemble with format!("{ns}{local}") or
Self::resolve_term_into — never assume either part is the whole
term.
Sourcepub fn string_parts_at(&self, i: usize) -> Option<(&'a str, &'a str)>
pub fn string_parts_at(&self, i: usize) -> Option<(&'a str, &'a str)>
The (namespace, local) parts of the i-th index entry
(0..entry_count), mirroring Self::string_at for both verbatim
and namespaced entries.
Sourcepub fn lookup_owned(&self, hash: u64) -> Option<String>
pub fn lookup_owned(&self, hash: u64) -> Option<String>
Cold-path convenience: the fully reassembled term for hash.
Sourcepub fn resolve_term_into(&self, hash: u64, out: &mut String) -> bool
pub fn resolve_term_into(&self, hash: u64, out: &mut String) -> bool
Zero-new-allocation reassembly into a caller-owned String
(cleared first). Returns false when hash is absent.
Sourcepub fn contains(&self, hash: u64) -> bool
pub fn contains(&self, hash: u64) -> bool
Presence check that also proves the entry decodes (parts resolve).
Sourcepub fn lookup_embedded_triple(&self, hash: u64) -> Option<[u64; 3]>
pub fn lookup_embedded_triple(&self, hash: u64) -> Option<[u64; 3]>
Binary search for hash in the sorted index; returns the embedded triple [subject, predicate, object].
Used by SPARQL-Star Virtual ID resolution: a Virtual ID is the FNV-1a hash of an embedded
triple, stored in the lexicon with tag LEX_TAG_EMBEDDED instead of LEX_TAG_STRING.
Sourcepub fn lookup_webizen_identity(&self, hash: u64) -> Option<&'a str>
pub fn lookup_webizen_identity(&self, hash: u64) -> Option<&'a str>
Binary search for hash; returns the authoritative Webizen identity string.
Trait Implementations§
Source§impl<'a> Clone for Q42LexMmap<'a>
impl<'a> Clone for Q42LexMmap<'a>
impl<'a> Copy for Q42LexMmap<'a>
Auto Trait Implementations§
impl<'a> Freeze for Q42LexMmap<'a>
impl<'a> RefUnwindSafe for Q42LexMmap<'a>
impl<'a> Send for Q42LexMmap<'a>
impl<'a> Sync for Q42LexMmap<'a>
impl<'a> Unpin for Q42LexMmap<'a>
impl<'a> UnsafeUnpin for Q42LexMmap<'a>
impl<'a> UnwindSafe for Q42LexMmap<'a>
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<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<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 more