Skip to content

Commit

Permalink
Merge pull request #27 from timbeurskens/performance-improvements
Browse files Browse the repository at this point in the history
Optimized mk_choice function
  • Loading branch information
timbeurskens authored Mar 23, 2022
2 parents 6d0a1d4 + 2afb5ac commit df74f3d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Build
run: cargo build --verbose --release
run: cargo build --verbose --release --examples --bins --lib
- name: Run tests
run: cargo test --verbose --release
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rsbdd"
version = "0.6.4"
version = "0.6.5"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 7 additions & 5 deletions src/bdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,15 @@ impl<S: BDDSymbol> BDDEnv<S> {
// early simplification step
let ins = self.simplify(&Rc::new(BDD::Choice(true_subtree, symbol, false_subtree)));

if self.nodes.borrow().contains_key(&ins) {
self.find(&ins)
// pre-borrow the nodes as mutable
let mut nodes_borrow = self.nodes.borrow_mut();

// if the node already exists, return a reference to it
if let Some(subtree) = nodes_borrow.get(&ins) {
Rc::clone(subtree)
} else {
// only insert if it is not already in the lookup table
self.nodes
.borrow_mut()
.insert(ins.as_ref().clone(), Rc::clone(&ins));
nodes_borrow.insert(ins.as_ref().clone(), Rc::clone(&ins));
Rc::clone(&ins)
}
}
Expand Down

0 comments on commit df74f3d

Please sign in to comment.