[][src]Struct egg::Extractor

pub struct Extractor<'a, CF: CostFunction<L>, L: Language, M> { /* fields omitted */ }

Extracting a single RecExpr from an EGraph.

use egg::*;

define_language! {
    enum SimpleLanguage {
        Num(i32),
        Add = "+",
        Mul = "*",
    }
}

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 (mut egraph, root) = EGraph::from_expr(&start);

SimpleRunner::default().run(&mut egraph, &rules);

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());

Methods

impl<'a, CF, L, M> Extractor<'a, CF, L, M> where
    CF: CostFunction<L>,
    L: Language
[src]

pub fn new(egraph: &'a EGraph<L, M>, 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, M> !RefUnwindSafe for Extractor<'a, CF, L, M>

impl<'a, CF, L, M> !Send for Extractor<'a, CF, L, M>

impl<'a, CF, L, M> !Sync for Extractor<'a, CF, L, M>

impl<'a, CF, L, M> Unpin for Extractor<'a, CF, L, M> where
    CF: Unpin,
    <CF as CostFunction<L>>::Cost: Unpin

impl<'a, CF, L, M> !UnwindSafe for Extractor<'a, CF, L, M>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.