Skip to content

Commit

Permalink
Add support_set to BooleanExpression.
Browse files Browse the repository at this point in the history
  • Loading branch information
daemontus committed Sep 18, 2024
1 parent 3708a12 commit 04dde91
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/boolean_expression/_impl_boolean_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::super::{Bdd, BddVariableSet};
use super::BooleanExpression;
use super::BooleanExpression::*;
use super::_impl_parser::parse_boolean_expression;
use std::collections::HashSet;
use std::convert::TryFrom;
use std::fmt::{Display, Error, Formatter};

Expand Down Expand Up @@ -31,6 +32,32 @@ impl Display for BooleanExpression {
}
}

impl BooleanExpression {
pub fn support_set(&self) -> HashSet<String> {
fn _rec(e: &BooleanExpression, set: &mut HashSet<String>) {
match e {
Const(_) => (),
Variable(x) => {
set.insert(x.clone());
}
Not(inner) => _rec(inner, set),
And(a, b) | Or(a, b) | Xor(a, b) | Imp(a, b) | Iff(a, b) => {
_rec(a, set);
_rec(b, set);
}
Cond(a, b, c) => {
_rec(a, set);
_rec(b, set);
_rec(c, set);
}
}
}
let mut result = HashSet::new();
_rec(self, &mut result);
result
}
}

/// Methods for evaluating boolean expressions.
impl BddVariableSet {
/// Evaluate the given `BooleanExpression` in the context of this `BddVariableSet`. Return `None` if some
Expand Down

0 comments on commit 04dde91

Please sign in to comment.