Skip to content

Commit

Permalink
test: assert uniqueness of nodes on fetch by id
Browse files Browse the repository at this point in the history
Co-authored-by: sword-smith <[email protected]>
  • Loading branch information
jan-ferdinand and Sword-Smith committed May 8, 2024
1 parent 8e38c8a commit 51eb30a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions triton-vm/src/table/constraint_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,14 @@ impl<II: InputIndicator> ConstraintCircuitBuilder<II> {
}

pub fn get_node_by_id(&self, id: usize) -> Option<ConstraintCircuitMonad<II>> {
self.all_nodes
.borrow()
let all_nodes = self.all_nodes.borrow();
let mut candidate_nodes = all_nodes
.iter()
.find(|node| node.circuit.borrow().id == id)
.cloned()
.filter(|node| node.circuit.borrow().id == id);
let num_candidates = candidate_nodes.clone().count();
assert!(num_candidates <= 1, "ID {id} not unique in builder");

candidate_nodes.next().cloned()
}

/// The unique monad representing the constant value 0.
Expand Down

0 comments on commit 51eb30a

Please sign in to comment.