use std::collections::HashSet;
use crate::formulas::{EncodedFormula, FormulaFactory, FormulaType};
pub fn contains_pbc(formula: EncodedFormula, f: &FormulaFactory) -> bool {
let mut seen = HashSet::new();
let mut stack = Vec::new();
stack.push(formula);
seen.insert(formula);
while let Some(current) = stack.pop() {
let result = f.caches.contains_pbc.get(current).map_or_else(
|| {
use FormulaType::{And, Cc, Equiv, False, Impl, Lit, Not, Or, Pbc, True};
match current.formula_type() {
Pbc | Cc => true,
Lit(_) | True | False => false,
Equiv | Impl | Not | Or | And => {
for &op in &*current.operands(f) {
if seen.insert(op) {
stack.push(op);
}
}
false
}
}
},
|cached| cached,
);
if result && f.config.caches.contains_pbc {
f.caches.contains_pbc.insert(formula, true);
}
if result {
return true;
}
}
false
}