[−][src]Trait egg::Language
Trait that defines a Language whose terms will be in the EGraph
.
Check out the define_language!
macro for an easy way to create
a Language
.
Note that the default implementations of
from_op_str
and
display_op
panic. You
should override them if you want to parse or pretty-print expressions.
define_language!
implements these for you.
See SymbolLang
for quick-and-dirty use cases.
Required methods
fn matches(&self, other: &Self) -> bool
Returns true if this enode matches another enode.
This should only consider the operator, not the children Id
s.
fn children(&self) -> &[Id]
Return a slice of the children Id
s.
fn children_mut(&mut self) -> &mut [Id]
Return a mutable slice of the children Id
s.
Provided methods
fn for_each<F: FnMut(Id)>(&self, f: F)
Runs a given function on each child Id
.
fn for_each_mut<F: FnMut(&mut Id)>(&mut self, f: F)
Runs a given function on each child Id
, allowing mutation of that Id
.
fn display_op(&self) -> &dyn Display
Returns something that will print the operator.
Default implementation panics, so make sure to implement this if you
want to print Language
elements.
The define_language!
macro will
implement this for you.
fn from_op_str(op_str: &str, children: Vec<Id>) -> Result<Self, String>
Given a string for the operator and the children, tries to make an enode.
Default implementation panics, so make sure to implement this if you
want to parse Language
elements.
The define_language!
macro will
implement this for you.
fn len(&self) -> usize
Returns the number of the children this enode has.
The default implementation uses fold
to accumulate the number of
children.
fn is_leaf(&self) -> bool
Returns true if this enode has no children.
fn update_children<F: FnMut(Id) -> Id>(&mut self, f: F)
Runs a given function to replace the children.
fn map_children<F: FnMut(Id) -> Id>(self, f: F) -> Self
Creates a new enode with children determined by the given function.
fn fold<F, T>(&self, init: T, f: F) -> T where
F: FnMut(T, Id) -> T,
T: Clone,
F: FnMut(T, Id) -> T,
T: Clone,
Folds over the children, given an initial accumulator.