pub struct TermDict { /* private fields */ }Expand description
Bidirectional intern table for one SPARQL query.
The dense shelf owns each term once: catalog hash-lookup for intern, shelf
position for TermId → EncodedTerm. A Mutex allows parallel UNION arms
to intern on &TermDict across .await.
Implementations§
Source§impl TermDict
impl TermDict
Shared dict for a crate-external std::sync::Arc holder (compute).
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Distinct terms interned so far — instrumentation for spotting hash-table doubling boundaries (a rehash shows up as a one-time materialization spike at a power of two). Never empty: the dict starts with 4 reserved terms.
Sourcepub fn reserve(&self, additional: usize)
pub fn reserve(&self, additional: usize)
Reserve capacity for additional more terms beyond the current
length, so a plan-estimated interning burst cannot trigger a
mid-execution hash-doubling rehash — a one-time full-table
relocation under the dict mutex (profiled as a 38–196ms stall when
a query crossed the 458,752-entry boundary mid-driver-page).
Sourcepub fn intern(&self, term: EncodedTerm) -> Result<TermId, ExecError>
pub fn intern(&self, term: EncodedTerm) -> Result<TermId, ExecError>
Intern term. Well-known DefaultGraph / rdf:type skip the map lock
after a cheap match. Other terms: existing index or sequential insert
from 4. Hitting the id ceiling ([has_room_for_one_more]) is
ExecError::TooManyTerms.
Sourcepub fn intern_ref(&self, term: &EncodedTerm) -> Result<TermId, ExecError>
pub fn intern_ref(&self, term: &EncodedTerm) -> Result<TermId, ExecError>
Intern a borrowed term (clones on insert).
Sourcepub fn peek(&self, term: &EncodedTerm) -> Option<TermId>
pub fn peek(&self, term: &EncodedTerm) -> Option<TermId>
Pure lookup: the id term already has, or None if it was never
interned. Never mutates the dict — the read-side counterpart of
Self::intern_ref. Use it when a pushed term list may name terms
that exist elsewhere in the query (an ancestor’s correlation
values, for one) and interning absent entries would grow the dict
without any column ever referencing them.
Unlike Self::intern_ref, a Placeholder maps to
Some(TermId::UNBOUND) instead of erroring — this is a lookup,
not an intern, and there is a well-defined id for “unbound”.
Callers that partition rows by id already guard unbound cells
(TermColumn::is_bound), so id 0 is never consulted downstream.
Sourcepub fn intern_column(
&self,
cells: impl ExactSizeIterator<Item = Option<EncodedTerm>>,
) -> Result<Vec<u32>, ExecError>
pub fn intern_column( &self, cells: impl ExactSizeIterator<Item = Option<EncodedTerm>>, ) -> Result<Vec<u32>, ExecError>
Intern a column under one mutex.
None cells become TermId::UNBOUND (0). Reserves cells.len()
extra catalog slots so inserts do not geometrically rehash, then lookup /
insert each cell. Drop the guard before I/O — this function is sync.
Bound columns should pass values.into_iter().map(Some) rather than
allocating a Vec<Option<EncodedTerm>>.
Sourcepub fn intern_columns<const N: usize>(
&self,
columns: [Vec<EncodedTerm>; N],
) -> Result<[Vec<u32>; N], ExecError>
pub fn intern_columns<const N: usize>( &self, columns: [Vec<EncodedTerm>; N], ) -> Result<[Vec<u32>; N], ExecError>
Intern N columns under ONE mutex acquisition.
Semantically identical to calling Self::intern_column on each
column in order — ids are assigned in exactly the same sequence
(column after column, first cell to last), so a term appearing in
several columns gets one id everywhere — but the dict lock is taken
once and the catalog reserved once for the whole batch. A
multi-column page absorb (the path walker’s S/O/G slots) then
serializes against concurrent interning on one acquisition instead
of N. Columns are moved in, never cloned; every cell is a bound
term (unbound cells do not exist at this boundary — callers omit
the row instead).
Sourcepub fn get(&self, id: TermId) -> Option<EncodedTerm>
pub fn get(&self, id: TermId) -> Option<EncodedTerm>
Reverse lookup. Id 0 is always None (unbound, not the Placeholder slot).
Sourcepub fn get_many(&self, ids: &[u32], out: &mut [Option<EncodedTerm>])
pub fn get_many(&self, ids: &[u32], out: &mut [Option<EncodedTerm>])
Reverse-lookup many TermIds under one mutex.
ids is the raw u32 buffer from crate::TermColumn::ids (0 =
unbound → None). ids.len() must equal out.len() (caller bug).
Whole-row / column / frame materialize must use this instead of looping
Self::get. Clone terms out and drop the guard — do not hold the
lock across decode_term, SPARQL eval, or I/O.