Skip to main content

TermDict

Struct TermDict 

Source
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

Source

pub fn new() -> Self

Empty dict with Placeholder @0 and reserved ids 1–3.

Source

pub fn new_shared() -> Arc<Self>

Shared dict for a crate-external std::sync::Arc holder (compute).

Source

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.

Source

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).

Source

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.

Source

pub fn intern_ref(&self, term: &EncodedTerm) -> Result<TermId, ExecError>

Intern a borrowed term (clones on insert).

Source

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.

Source

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>>.

Source

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).

Source

pub fn get(&self, id: TermId) -> Option<EncodedTerm>

Reverse lookup. Id 0 is always None (unbound, not the Placeholder slot).

Source

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.

Trait Implementations§

Source§

impl Debug for TermDict

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TermDict

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,