Skip to main content

EGraph

Struct EGraph 

Source
pub struct EGraph { /* private fields */ }
Expand description

An equivalence graph for layout expressions.

Stores expressions and their equivalence classes. Supports adding expressions, merging equivalence classes, and applying rewrite rules to discover equivalent layouts.

Implementations§

Source§

impl EGraph

Source

pub fn new() -> Self

Create a new empty e-graph.

Source

pub fn add(&mut self, expr: Expr) -> Id

Add an expression to the e-graph, returning its equivalence class id.

If the expression already exists (structurally identical after canonicalization), returns the existing id.

Source

pub fn equiv(&self, a: Id, b: Id) -> bool

Check if two ids are in the same equivalence class.

Source

pub fn merge(&mut self, a: Id, b: Id) -> Id

Merge two equivalence classes, returning the new canonical id.

Source

pub fn find(&self, id: Id) -> Id

Find the canonical representative of an equivalence class.

Source

pub fn class_count(&self) -> usize

Number of equivalence classes.

Source

pub fn node_count(&self) -> usize

Total number of expression nodes.

Source

pub fn last_apply_count(&self) -> usize

Number of rule applications in the last apply_rules call.

Source

pub fn apply_rules(&mut self) -> usize

Apply rewrite rules until saturation (no new equalities discovered) or the iteration budget is exhausted.

Returns the total number of rule applications.

Source

pub fn apply_rules_with_budget(&mut self, max_iterations: usize) -> usize

Apply rewrite rules with an explicit iteration budget.

Source

pub fn extract(&self, id: Id) -> Expr

Extract the best expression from an equivalence class.

Uses a simple cost model: prefer fewer nodes and simpler operations.

Source§

impl EGraph

Source

pub fn saturate(&mut self, config: &SaturationConfig) -> SaturationResult

Run equality saturation with explicit resource bounds.

Returns a SaturationResult indicating completion status. If the node budget, time limit, or memory limit is hit, the current state is preserved and the caller can still extract results.

Source

pub fn memory_usage(&self) -> usize

Estimated memory usage in bytes.

Trait Implementations§

Source§

impl Debug for EGraph

Source§

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

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

impl Default for EGraph

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