Skip to main content

IndexStore

Struct IndexStore 

Source
pub struct IndexStore<Cfg: EGraphConfig> {
    pub by_op: DenseSpanMap<Cfg::G>,
    pub by_repr: DenseSpanMap<Cfg::G>,
    pub by_child_pos: DenseSpanMap<Cfg::G>,
    pub by_contains: DenseSpanMap<Cfg::G>,
    pub child_pos_stride: usize,
    pub repr: Vec<Cfg::G>,
    pub op: Vec<Cfg::O>,
    pub fanouts: FanOuts<Cfg::O>,
}
Expand description

All indices for leapfrog join, bulk-rebuilt after each e-graph rebuild.

Each family is a DenseSpanMap: one flat pool of node ids per family, plus a span table saying where each key’s run starts and how long it is. Every key is a dense integer (an op id, a class id, or a (position, class) pair flattened into one), so a probe is an array index and a slice, not a hash and a pointer chase into a per-key Vec. The container’s refines() pins each key’s slice to the order-preserving filter of the build stream down to that key, which is what makes the two-pass counting build substitutable for the per-key push it replaces.

Fields§

§by_op: DenseSpanMap<Cfg::G>

by_op[op] -> node ids with that operator, keyed by the op’s dense id.

§by_repr: DenseSpanMap<Cfg::G>

by_repr[repr] -> node ids in that e-class, keyed by the class representative’s id (see repr for which canonicalization).

§by_child_pos: DenseSpanMap<Cfg::G>

by_child_pos[pos * stride + child_repr] -> parent node ids with child_repr at pos.

The two-dimensional key is flattened by DenseSpanMap::composite_key, whose injectivity for a second component below the stride is lemma_composite_key_injective. Position-major rather than class-major so that one pattern position’s keys are one contiguous run of the span table, and so that the key is computable during the build’s single walk: the stride is the node bound, known before the walk, whereas the number of distinct positions is only known after it.

The position is Cfg::Index-wide: it is an offset into one node’s children, and a variadic node’s children are a span in the child pool, which that word already sizes. See IndexLookup::ByChildPos.

§by_contains: DenseSpanMap<Cfg::G>

by_contains[child_repr] -> variadic parent node ids (A/AC/ACI/PlainN).

§child_pos_stride: usize

Stride of the by_child_pos composite key: the node bound this index was built at. A probe class at or above it belongs to no bucket of this build and resolves to the empty slice, which is what an absent key resolved to when the family was a hash map.

§repr: Vec<Cfg::G>

repr[id] — the class representative of every node id as of this build.

The three keyed families above are keyed by this canonicalization, and it stops being the e-graph’s the moment the round’s first rule merges a class. A matcher that canonicalizes a lookup key with the live union-find and then probes a bucket keyed at build time reads a bucket that belongs to some other class, so the answer depends on which access path the join order happened to use. Keeping the build’s mapping makes every access path agree; see round_repr and chapter 09’s snapshot contract.

Filled by build only. build_delta leaves it empty: a delta is built in the same instant as its full index and shares that index’s canonicalization, so the mapping is stored once.

§op: Vec<Cfg::O>

op[id] — the operator of every node id as of this build.

A join that demotes its ByOp lookup to a per-candidate operator test (ematch::run_join) reads this instead of EGraph::node_op, which resolves the routing table and then the arity-specific arena: two dependent random loads over 10 MB and 20 MB against one over 4 · node_count bytes. The build pays for it with a sequential pass, where the same two loads stream.

Filled by build only, like repr: the delta’s ids are a subset of the full index’s, so one table serves both.

§fanouts: FanOuts<Cfg::O>

Measured selectivity of each access path, read by the scheduler through IndexStats::from_index.

Filled by build only, for the same reason as repr: a variant prices its delta atom by the delta’s cardinality against the full index’s fan-outs, so measuring the delta’s own would buy nothing and cost a pass per round.

Implementations§

Source§

impl<Cfg: EGraphConfig> IndexStore<Cfg>
where MSetCanon: VarCanon<Cfg::G, Cfg::C>,

Source

pub fn build<L: LitVal, const TRACK: bool, const PROOFS: bool>( eg: &EGraph<Cfg, L, TRACK, PROOFS>, ) -> Self

Bulk-rebuild all indices from the current e-graph state. Call after eg.rebuild().

Allocates its own scratch; a caller that builds an index per round should use build_with and keep one.

Source

pub fn build_with<L: LitVal, const TRACK: bool, const PROOFS: bool>( eg: &EGraph<Cfg, L, TRACK, PROOFS>, scratch: &mut IndexScratch<Cfg>, ) -> Self

build, reusing scratch’s stream buffers.

Source

pub fn build_delta<L: LitVal, const TRACK: bool, const PROOFS: bool>( eg: &EGraph<Cfg, L, TRACK, PROOFS>, touched: &[Cfg::G], ) -> Self

Build the per-round delta index from the touched-node log: the same four crosscutting families as build, but restricted to the nodes that were created or recanonicalized this round.

touched may contain duplicates (a node added then recanonicalized); they are deduplicated here. Subsumed nodes are skipped, exactly as in build, so for every key k the delta is a subset of the full index’s k bucket — build_delta(eg, eg.touched()) ⊆ build(eg).

Source

pub fn build_delta_with<L: LitVal, const TRACK: bool, const PROOFS: bool>( eg: &EGraph<Cfg, L, TRACK, PROOFS>, touched: &[Cfg::G], scratch: &mut IndexScratch<Cfg>, ) -> Self

build_delta, reusing scratch’s stream buffers.

Source

pub fn recycle_into(self, scratch: &mut IndexScratch<Cfg>, full: bool)

Hand this store’s four span arenas back to scratch for the next round.

full says which set of slots they came from, which the caller knows because it chose which build produced this store. Consuming self is what makes the hand-back safe: the maps’ pools and the arenas’ span tables are separate allocations, and only the arenas survive.

Not calling this is a performance bug and not a correctness one — the next build allocates a fresh arena — so it is deliberately an ordinary method rather than a Drop impl, which could not name the scratch.

Source

pub fn round_repr(&self, id: Cfg::G) -> Option<Cfg::G>

This build’s class representative for id, or None for an id minted after the build (and so present in no bucket) or on a delta store, which defers the mapping to its full index.

Source

pub fn round_op(&self, id: Cfg::G) -> Option<Cfg::O>

The operator of id as of this build, or None when the table is not filled (a delta store) or id postdates the build. See op.

Source

pub fn nodes_by_op(&self, op: Cfg::O) -> &[Cfg::G]

Nodes with the given operator; empty when the operator files no node.

Source

pub fn nodes_by_repr(&self, repr: Cfg::G) -> &[Cfg::G]

Nodes in the given e-class, as this build canonicalized it.

Source

pub fn nodes_by_child_pos( &self, child_repr: Cfg::G, pos: Cfg::Index, ) -> &[Cfg::G]

Parent nodes that have child_repr at position pos.

A class at or above the stride, or a position past the deepest one this build saw, names no key of the span table and yields the empty slice: the same answer the hash-map family gave for a key it had never inserted.

Source

pub fn nodes_by_contains(&self, child_repr: Cfg::G) -> &[Cfg::G]

Variadic nodes containing child_repr.

Source

pub fn iter_by_op(&self, op: Cfg::O) -> SortedVecCursor<'_, Cfg::G>

Get an iterator over nodes with the given operator.

Source

pub fn iter_by_repr(&self, repr: Cfg::G) -> SortedVecCursor<'_, Cfg::G>

Get an iterator over nodes in the given e-class.

Source

pub fn iter_by_child_pos( &self, child_repr: Cfg::G, pos: Cfg::Index, ) -> SortedVecCursor<'_, Cfg::G>

Get an iterator over parent nodes that have child_repr at position pos.

Source

pub fn iter_by_contains( &self, child_repr: Cfg::G, ) -> SortedVecCursor<'_, Cfg::G>

Get an iterator over variadic nodes containing child_repr.

Source

pub fn op_cardinalities(&self) -> impl Iterator<Item = (Cfg::O, usize)> + '_

Per-operator driver-scan cardinalities, for IndexStats.

Only operators that file at least one node are listed, so an absent operator stays absent rather than arriving with a zero, which is the distinction the cost model’s or_else chain reads.

Auto Trait Implementations§

§

impl<Cfg> Freeze for IndexStore<Cfg>
where DenseSpanMap<<Cfg as EGraphConfig>::G>: Freeze, Vec<<Cfg as EGraphConfig>::G>: Freeze, Vec<<Cfg as EGraphConfig>::O>: Freeze, FanOuts<<Cfg as EGraphConfig>::O>: Freeze,

§

impl<Cfg> RefUnwindSafe for IndexStore<Cfg>

§

impl<Cfg> Send for IndexStore<Cfg>
where DenseSpanMap<<Cfg as EGraphConfig>::G>: Send, Vec<<Cfg as EGraphConfig>::G>: Send, Vec<<Cfg as EGraphConfig>::O>: Send, FanOuts<<Cfg as EGraphConfig>::O>: Send,

§

impl<Cfg> Sync for IndexStore<Cfg>
where DenseSpanMap<<Cfg as EGraphConfig>::G>: Sync, Vec<<Cfg as EGraphConfig>::G>: Sync, Vec<<Cfg as EGraphConfig>::O>: Sync, FanOuts<<Cfg as EGraphConfig>::O>: Sync,

§

impl<Cfg> Unpin for IndexStore<Cfg>
where DenseSpanMap<<Cfg as EGraphConfig>::G>: Unpin, Vec<<Cfg as EGraphConfig>::G>: Unpin, Vec<<Cfg as EGraphConfig>::O>: Unpin, FanOuts<<Cfg as EGraphConfig>::O>: Unpin,

§

impl<Cfg> UnsafeUnpin for IndexStore<Cfg>

§

impl<Cfg> UnwindSafe for IndexStore<Cfg>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.