Skip to content

Commit

Permalink
use slice instead of get(): src/bdd.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
shnarazk committed Feb 3, 2024
1 parent 75e5cf5 commit 99ad1ee
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/bdd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl ReducedDecisionDiagram for BDD<Node> {
}
let mut next_id: usize = 2;
for vi in vlist.keys().sorted().rev() {
let lst = vlist.get(vi).unwrap();
let lst = &vlist[vi];
let mut q: Vec<((usize, usize), &Node)> = Vec::new();
let mut old_key: (usize, usize) = (0, 0);
for node in lst.iter().cloned() {
Expand All @@ -73,12 +73,9 @@ impl ReducedDecisionDiagram for BDD<Node> {
} => {
if to_index.get(low) == to_index.get(high) {
// redundant vertex
to_index.insert(node.clone(), *to_index.get(low).unwrap());
to_index.insert(node.clone(), to_index[low]);
} else {
q.push((
(*to_index.get(low).unwrap(), *to_index.get(high).unwrap()),
node,
));
q.push(((to_index[low], to_index[high]), node));
}
}
}
Expand All @@ -99,24 +96,20 @@ impl ReducedDecisionDiagram for BDD<Node> {
ref low,
ref high,
} => {
let l = from_index.get(to_index.get(low).unwrap()).unwrap();
let h = from_index.get(to_index.get(high).unwrap()).unwrap();
let l = &from_index[&to_index[low]];
let h = &from_index[&to_index[high]];
let n = Node::new_var(var_index, (*l).clone(), (*h).clone());
to_index.insert(node.clone(), next_id);
to_index.insert(n.clone(), next_id);
from_index.insert(next_id, n);
// Rc::get_mut(&mut **node);
}
}
old_key = key;
}
}
}
// pick up a tree from the hash-table
self.graph = from_index
.get(to_index.get(&root).unwrap())
.unwrap()
.clone();
self.graph = from_index[&to_index[&root]].clone();
}
fn apply(&self, op: Box<dyn Fn(bool, bool) -> bool>, unit: bool, other: &Self) -> BDD<Node> {
let mut from_index: HashMap<usize, Node> = HashMap::new();
Expand Down Expand Up @@ -181,7 +174,7 @@ impl ReducedDecisionDiagram for BDD<Node> {
evaluation: &mut HashMap<Node, bool>,
merged: &mut HashMap<(usize, usize), Node>,
) -> Node {
let hash_key = (*to_index.get(&v1).unwrap(), *to_index.get(&v2).unwrap());
let hash_key = (to_index[&v1], to_index[&v2]);
if let Some(n) = merged.get(&hash_key) {
return n.clone(); // have already evaluaten
}
Expand All @@ -194,7 +187,7 @@ impl ReducedDecisionDiagram for BDD<Node> {
(Some(a), Some(b)) => Some(op(*a, *b)),
};
if let Some(b) = value {
return from_index.get(&(b as usize)).unwrap().clone();
return from_index[&(b as usize)].clone();
}
let v1key = v1.unified_key();
let v2key = v2.unified_key();
Expand Down

0 comments on commit 99ad1ee

Please sign in to comment.