1
use crate::utilities::create_var_map;
2
use crate::utilities::SemiCompressedTermTree;
3
use crate::Rule;
4

            
5
/// This is a [Rule] condition stored as semi compressed trees such that they can be
6
/// subsituted efficiently.
7
#[derive(Hash, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
8
pub struct EMACondition {
9
    /// Conditions lhs and rhs are stored in the term pool as much as possible with a SemiCompressedTermTree
10
    pub semi_compressed_lhs: SemiCompressedTermTree,
11
    pub semi_compressed_rhs: SemiCompressedTermTree,
12

            
13
    /// whether the lhs and rhs should be equal or different
14
    pub equality: bool,
15
}
16

            
17
/// Computes the extended condition from a given rewrite rule.
18
107500
pub fn extend_conditions(rule: &Rule) -> Vec<EMACondition> {
19
107500
    let var_map = create_var_map(&rule.lhs.clone().into());
20
107500
    let mut conditions = vec![];
21

            
22
136980
    for c in &rule.conditions {
23
29480
        let ema_condition = EMACondition {
24
29480
            semi_compressed_lhs: SemiCompressedTermTree::from_term(&c.lhs.copy().into(), &var_map),
25
29480
            semi_compressed_rhs: SemiCompressedTermTree::from_term(&c.rhs.copy().into(), &var_map),
26
29480
            equality: c.equality,
27
29480
        };
28
29480
        conditions.push(ema_condition);
29
29480
    }
30

            
31
107500
    conditions
32
107500
}