| 87 | } |
| 88 | |
| 89 | bool GraphCycles::CheckInvariants() const { |
| 90 | Rep* r = rep_; |
| 91 | NodeSet ranks; // Set of ranks seen so far. |
| 92 | for (Vec<Node*>::size_type x = 0; x < r->nodes_.size(); x++) { |
| 93 | Node* nx = r->nodes_[x]; |
| 94 | if (nx->visited) { |
| 95 | LOG(FATAL) << "Did not clear visited marker on node " << x; |
| 96 | } |
| 97 | if (!ranks.insert(nx->rank).second) { |
| 98 | LOG(FATAL) << "Duplicate occurrence of rank " << nx->rank; |
| 99 | } |
| 100 | for (int32 y : nx->out.GetSequence()) { |
| 101 | Node* ny = r->nodes_[y]; |
| 102 | if (nx->rank >= ny->rank) { |
| 103 | LOG(FATAL) << "Edge " << x << "->" << y << " has bad rank assignment " |
| 104 | << nx->rank << "->" << ny->rank; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | int32 GraphCycles::NewNode() { |
| 112 | if (rep_->free_nodes_.empty()) { |