Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip verification on DAG::set_validate(false) #21

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions layout/src/adt/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ pub struct DAG {

/// Places nodes in levels.
ranks: RankType,

/// Perform validation checks.
validate: bool,
}

/// Used by users to keep track of nodes that are saved in the DAG.
Expand Down Expand Up @@ -78,9 +81,14 @@ impl DAG {
DAG {
nodes: Vec::new(),
ranks: Vec::new(),
validate: true,
}
}

pub fn set_validate(&mut self, validate: bool) {
self.validate = validate;
}

pub fn clear(&mut self) {
self.nodes.clear();
self.ranks.clear();
Expand Down Expand Up @@ -163,24 +171,26 @@ impl DAG {
}

pub fn verify(&self) {
// Check that the node indices are valid.
for node in &self.nodes {
for edge in &node.successors {
assert!(edge.idx < self.nodes.len());
if self.validate {
// Check that the node indices are valid.
for node in &self.nodes {
for edge in &node.successors {
assert!(edge.idx < self.nodes.len());
}
}
}

// Check that the graph is a DAG.
for (i, node) in self.nodes.iter().enumerate() {
let from = NodeHandle::from(i);
for dest in node.successors.iter() {
let reachable = self.is_reachable(*dest, from) && from != *dest;
assert!(!reachable, "We found a cycle!");
// Check that the graph is a DAG.
for (i, node) in self.nodes.iter().enumerate() {
let from = NodeHandle::from(i);
for dest in node.successors.iter() {
let reachable = self.is_reachable(*dest, from) && from != *dest;
assert!(!reachable, "We found a cycle!");
}
}
}

// Make sure that all of the nodes are in ranks.
assert_eq!(self.count_nodes_in_ranks(), self.len());
// Make sure that all of the nodes are in ranks.
assert_eq!(self.count_nodes_in_ranks(), self.len());
}
}

pub fn len(&self) -> usize {
Expand Down
Loading