Skip to content

Commit de7c501

Browse files
authored
Merge pull request #43 from timbeurskens/or-operator-optimization
Or operator optimization
2 parents 7da47f0 + 82d74eb commit de7c501

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsbdd"
3-
version = "0.9.2"
3+
version = "0.9.3"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/bdd.rs

+34-5
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,40 @@ impl<S: BDDSymbol> BDDEnv<S> {
260260
}
261261
}
262262

263+
// disjunction
264+
pub fn or(&self, a: Rc<BDD<S>>, b: Rc<BDD<S>>) -> Rc<BDD<S>> {
265+
// self.not(self.nor(a, b))
266+
267+
match (a.as_ref(), b.as_ref()) {
268+
(&BDD::True, _) | (_, &BDD::True) => self.mk_const(true),
269+
(&BDD::False, _) => Rc::clone(&b),
270+
(_, &BDD::False) => Rc::clone(&a),
271+
// todo:
272+
(&BDD::Choice(ref at, ref va, ref af), &BDD::Choice(_, ref vb, _)) if va < vb => self
273+
.mk_choice(
274+
self.or(Rc::clone(at), Rc::clone(&b)),
275+
va.clone(),
276+
self.or(Rc::clone(af), Rc::clone(&b)),
277+
),
278+
(&BDD::Choice(_, ref va, _), &BDD::Choice(ref bt, ref vb, ref bf)) if vb < va => self
279+
.mk_choice(
280+
self.or(Rc::clone(bt), Rc::clone(&a)),
281+
vb.clone(),
282+
self.or(Rc::clone(bf), Rc::clone(&a)),
283+
),
284+
(&BDD::Choice(ref at, ref va, ref af), &BDD::Choice(ref bt, ref vb, ref bf))
285+
if va == vb =>
286+
{
287+
self.mk_choice(
288+
self.or(Rc::clone(at), Rc::clone(bt)),
289+
va.clone(),
290+
self.or(Rc::clone(af), Rc::clone(bf)),
291+
)
292+
}
293+
_ => panic!("unsupported match: {:?} {:?}", a, b),
294+
}
295+
}
296+
263297
pub fn not(&self, a: Rc<BDD<S>>) -> Rc<BDD<S>> {
264298
match *a.as_ref() {
265299
BDD::False => self.mk_const(true),
@@ -290,11 +324,6 @@ impl<S: BDDSymbol> BDDEnv<S> {
290324
)
291325
}
292326

293-
// disjunction
294-
pub fn or(&self, a: Rc<BDD<S>>, b: Rc<BDD<S>>) -> Rc<BDD<S>> {
295-
self.not(self.nor(a, b))
296-
}
297-
298327
// exclusive disjunction
299328
pub fn xor(&self, a: Rc<BDD<S>>, b: Rc<BDD<S>>) -> Rc<BDD<S>> {
300329
self.or(

0 commit comments

Comments
 (0)