pub struct EGraph<L: Language, A: Analysis<L = L>> {
    pub nodes: Vec<L::Node>,
    pub classes: PrimaryMap<Id, EClass>,
    pub unionfind: UnionFind,
    pub analysis: Option<(A, SecondaryMap<Id, A::Value>)>,
    /* private fields */
}
Expand description

An egraph.

Fields§

§nodes: Vec<L::Node>

Node-allocation arena.

§classes: PrimaryMap<Id, EClass>

Eclass definitions. Each eclass consists of an enode, and child pointer to the rest of the eclass.

§unionfind: UnionFind

Union-find for canonical ID generation. This lets us name an eclass with a canonical ID that is the same for all generations of the class.

§analysis: Option<(A, SecondaryMap<Id, A::Value>)>

Analysis and per-node state.

Implementations§

source§

impl<L: Language, A: Analysis<L = L>> EGraph<L, A>where L::Node: 'static,

source

pub fn new(analysis: Option<A>) -> Self

Create a new aegraph.

source

pub fn with_capacity(nodes: usize, analysis: Option<A>) -> Self

Create a new aegraph with the given capacity.

source

pub fn add(&mut self, node: L::Node, node_ctx: &L) -> NewOrExisting<Id>

Add a new node.

source

pub fn union(&mut self, ctx: &L, a: Id, b: Id) -> Id

Merge one eclass into another, maintaining the acyclic property (args must have lower eclass Ids than the eclass containing the node with those args). Returns the Id of the merged eclass.

source

pub fn canonical_id_mut(&mut self, eclass: Id) -> Id

Get the canonical ID for an eclass. This may be an older generation, so will not be able to see all enodes in the eclass; but it will allow us to unambiguously refer to an eclass, even across merging.

source

pub fn canonical_id(&self, eclass: Id) -> Id

Get the canonical ID for an eclass. This may be an older generation, so will not be able to see all enodes in the eclass; but it will allow us to unambiguously refer to an eclass, even across merging.

source

pub fn enodes(&self, eclass: Id) -> NodeIter<L, A>

Get the enodes for a given eclass.

source

pub fn analysis_value(&self, eclass: Id) -> &A::Value

Get the analysis value for a given eclass. Panics if no analysis is present.

Auto Trait Implementations§

§

impl<L, A> RefUnwindSafe for EGraph<L, A>where A: RefUnwindSafe, <L as Language>::Node: RefUnwindSafe, <A as Analysis>::Value: RefUnwindSafe,

§

impl<L, A> Send for EGraph<L, A>where A: Send, <L as Language>::Node: Send, <A as Analysis>::Value: Send,

§

impl<L, A> Sync for EGraph<L, A>where A: Sync, <L as Language>::Node: Sync, <A as Analysis>::Value: Sync,

§

impl<L, A> Unpin for EGraph<L, A>where A: Unpin, <L as Language>::Node: Unpin, <A as Analysis>::Value: Unpin,

§

impl<L, A> UnwindSafe for EGraph<L, A>where A: UnwindSafe, <L as Language>::Node: UnwindSafe, <A as Analysis>::Value: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.