pub fn search_with_accelerator<T, F, U, A>(
    start: &[T],
    pat: F,
    max_size: Option<usize>,
    filter: &[T],
    order_constraints: &[(T, T)],
    infer: fn(Solver<T, A>, story: &[T]) -> Option<T>,
    accelerator: &mut A,
) -> (Vec<U>, Result<(), Error>)
    where T: Clone + PartialEq + Eq + Hash,
          F: Fn(&T) -> Option<U>
{
    let mut cache = HashSet::new();
    for s in start {
        cache.insert(s.clone());
    }
    let mut filter_cache: HashSet<T> = HashSet::new();
    for f in filter {
        filter_cache.insert(f.clone());
    }
    let mut res: Vec<T> = start.into();
    let mut matches: Vec<U> = vec![];

    for expr in start {
        if let Some(val) = (pat)(expr) {
            matches.push(val);
        }
    }

    loop {
        if let Some(n) = max_size {
            if res.len() >= n {break};
        }

        // Modify filter to prevent violating of order-constraints.
        let mut added_to_filter = vec![];
        for (i, &(ref a, ref b)) in order_constraints.iter().enumerate() {
            if !cache.contains(a) && !filter_cache.contains(b) {
                added_to_filter.push(i);
            }
        }
        for &i in &added_to_filter {
            filter_cache.insert(order_constraints[i].1.clone());
        }

        let expr = if let Some(expr) = infer(Solver {
                cache: &cache,
                filter_cache: &filter_cache,
                accelerator,
            }, &res) {
            expr
        } else {
            return (matches, Ok(()));
        };
        res.push(expr.clone());

        if let Some(val) = (pat)(&expr) {
            matches.push(val);
        }

        cache.insert(expr);

        // Revert filter.
        for &i in &added_to_filter {
            filter_cache.remove(&order_constraints[i].1);
        }

    }
    (matches, Err(Error::MaxSize))
}
/// Searches for matches by a pattern.
///
/// - `pat` specifies the map and acceptance criteria
/// - `max_size` specifies the maximum size of proof
///
/// Returns `Ok` if all rules where exausted.
/// Returns `Err` if the maximum size of proof was exceeded.
Searches for matches by a pattern.
`pat` specifies the map and acceptance criteria
`max_size` specifies the maximum size of proof

Returns `Ok` if all rules where exausted.
Returns `Err` if the maximum size of proof was exceeded.
Searches for matches by a pattern . ` pat ` specifies the map and acceptance criteria ` max_size ` specifies the maximum size of proof Returns ` Ok ` if all rules where exausted . Returns ` Err ` if the maximum size of proof was exceeded .
pub fn search_with_accelerator<T, F, U, A>(
    start: &[T],
    pat: F,
    max_size: Option<usize>,
    filter: &[T],
    order_constraints: &[(T, T)],
    infer: fn(Solver<T, A>, story: &[T]) -> Option<T>,
    accelerator: &mut A,
) -> (Vec<U>, Result<(), Error>)
    where T: Clone + PartialEq + Eq + Hash,
          F: Fn(&T) -> Option<U>
{
    let mut cache = HashSet::new();
    for s in start {
        cache.insert(s.clone());
    }
    let mut filter_cache: HashSet<T> = HashSet::new();
    for f in filter {
        filter_cache.insert(f.clone());
    }
    let mut res: Vec<T> = start.into();
    let mut matches: Vec<U> = vec![];
    for expr in start {
        if let Some(val) = (pat)(expr) {
            matches.push(val);
        }
    }
    loop {
        if let Some(n) = max_size {
            if res.len() >= n {break};
        }
        // Modify filter to prevent violating of order-constraints.
        let mut added_to_filter = vec![];
        for (i, &(ref a, ref b)) in order_constraints.iter().enumerate() {
            if !cache.contains(a) && !filter_cache.contains(b) {
                added_to_filter.push(i);
            }
        }
        for &i in &added_to_filter {
            filter_cache.insert(order_constraints[i].1.clone());
        }
        let expr = if let Some(expr) = infer(Solver {
                cache: &cache,
                filter_cache: &filter_cache,
                accelerator,
            }, &res) {
            expr
        } else {
            return (matches, Ok(()));
        };
        res.push(expr.clone());
        if let Some(val) = (pat)(&expr) {
            matches.push(val);
        }
        cache.insert(expr);
        // Revert filter.
        for &i in &added_to_filter {
            filter_cache.remove(&order_constraints[i].1);
        }
    }
    (matches, Err(Error::MaxSize))
}
pub fn search_with_accelerator < T , F , U , A > ( start : & [ T ] , pat : F , max_size : Option < usize > , filter : & [ T ] , order_constraints : & [ ( T , T ) ] , infer : fn ( Solver < T , A > , story : & [ T ] ) -> Option < T > , accelerator : & mut A , ) -> ( Vec < U > , Result < ( ) , Error > ) where T : Clone + PartialEq + Eq + Hash , F : Fn ( & T ) -> Option < U > { let mut cache = HashSet :: new ( ) ; for s in start { cache . insert ( s . clone ( ) ) ; } let mut filter_cache : HashSet < T > = HashSet :: new ( ) ; for f in filter { filter_cache . insert ( f . clone ( ) ) ; } let mut res : Vec < T > = start . into ( ) ; let mut matches : Vec < U > = vec ! [ ] ; for expr in start { if let Some ( val ) = ( pat ) ( expr ) { matches . push ( val ) ; } } loop { if let Some ( n ) = max_size { if res . len ( ) >= n { break } ; } // Modify filter to prevent violating of order-constraints. let mut added_to_filter = vec ! [ ] ; for ( i , & ( ref a , ref b ) ) in order_constraints . iter ( ) . enumerate ( ) { if ! cache . contains ( a ) && ! filter_cache . contains ( b ) { added_to_filter . push ( i ) ; } } for & i in & added_to_filter { filter_cache . insert ( order_constraints [ i ] . 1 . clone ( ) ) ; } let expr = if let Some ( expr ) = infer ( Solver { cache : & cache , filter_cache : & filter_cache , accelerator , } , & res ) { expr } else { return ( matches , Ok ( ( ) ) ) ; } ; res . push ( expr . clone ( ) ) ; if let Some ( val ) = ( pat ) ( & expr ) { matches . push ( val ) ; } cache . insert ( expr ) ; // Revert filter. for & i in & added_to_filter { filter_cache . remove ( & order_constraints [ i ] . 1 ) ; } } ( matches , Err ( Error :: MaxSize ) ) }
Searches for matches by a pattern.
Searches for matches by a pattern .
start
&[T]
pat
F
max_size
Option<usize>
filter
&[T]
order_constraints
&[(T, T)]
infer
fn(Solver<T, A>, story: &[T]) -> Option<T>
story
&[T]
accelerator
&mut A
start
&[T]
pat
F
max_size
Option<usize>
filter
&[T]
order_constraints
&[(T, T)]
infer
fn(Solver<T, A>, story: &[T]) -> Option<T>
story
&[T]
accelerator
&mut A