-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathextract_conjuncts.rs
More file actions
30 lines (27 loc) · 1.05 KB
/
extract_conjuncts.rs
File metadata and controls
30 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use crate::expr::Expression;
use crate::expr::exprs::binary::Binary;
use crate::expr::exprs::operators::Operator;
/// Converting an expression to a conjunctive normal form can lead to a large number of expression
/// nodes.
/// For now, we will just extract the conjuncts from the expression, and return a vector of conjuncts.
/// We could look at try cnf with a size cap and otherwise return the original conjuncts.
pub fn conjuncts(expr: &Expression) -> Vec<Expression> {
let mut conjuncts = vec![];
conjuncts_impl(expr, &mut conjuncts);
if conjuncts.is_empty() {
conjuncts.push(expr.clone());
}
conjuncts
}
fn conjuncts_impl(expr: &Expression, conjuncts: &mut Vec<Expression>) {
if let Some(operator) = expr.as_opt::<Binary>()
&& *operator == Operator::KleeneAnd
{
conjuncts_impl(expr.child(0), conjuncts);
conjuncts_impl(expr.child(1), conjuncts);
} else {
conjuncts.push(expr.clone())
}
}