[−][src]Struct egg::Extractor
Extracting a single RecExpr
from an EGraph
.
use egg::*; define_language! { enum SimpleLanguage { Num(i32), "+" = Add([Id; 2]), "*" = Mul([Id; 2]), } } let rules: &[Rewrite<SimpleLanguage, ()>] = &[ rewrite!("commute-add"; "(+ ?a ?b)" => "(+ ?b ?a)"), rewrite!("commute-mul"; "(* ?a ?b)" => "(* ?b ?a)"), rewrite!("add-0"; "(+ ?a 0)" => "?a"), rewrite!("mul-0"; "(* ?a 0)" => "0"), rewrite!("mul-1"; "(* ?a 1)" => "?a"), ]; let start = "(+ 0 (* 1 10))".parse().unwrap(); let runner = Runner::default().with_expr(&start).run(&rules); let (egraph, root) = (runner.egraph, runner.roots[0]); let mut extractor = Extractor::new(&egraph, AstSize); let (best_cost, best) = extractor.find_best(root); assert_eq!(best_cost, 1); assert_eq!(best, "10".parse().unwrap());
Implementations
impl<'a, CF, L, N> Extractor<'a, CF, L, N> where
CF: CostFunction<L>,
L: Language,
N: Analysis<L>,
[src]
CF: CostFunction<L>,
L: Language,
N: Analysis<L>,
pub fn new(egraph: &'a EGraph<L, N>, cost_function: CF) -> Self
[src]
Create a new Extractor
given an EGraph
and a
CostFunction
.
The extraction does all the work on creation, so this function performs the greedy search for cheapest representative of each eclass.
pub fn find_best(&mut self, eclass: Id) -> (CF::Cost, RecExpr<L>)
[src]
Find the cheapest (lowest cost) represented RecExpr
in the
given eclass.
Auto Trait Implementations
impl<'a, CF, L, N> !RefUnwindSafe for Extractor<'a, CF, L, N>
impl<'a, CF, L, N> !Send for Extractor<'a, CF, L, N>
impl<'a, CF, L, N> !Sync for Extractor<'a, CF, L, N>
impl<'a, CF, L, N> Unpin for Extractor<'a, CF, L, N> where
CF: Unpin,
<CF as CostFunction<L>>::Cost: Unpin,
CF: Unpin,
<CF as CostFunction<L>>::Cost: Unpin,
impl<'a, CF, L, N> !UnwindSafe for Extractor<'a, CF, L, N>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,