| 1077 | } |
| 1078 | |
| 1079 | void GraphConstructor::PrintCycles() { |
| 1080 | int num_nodes = outputs_.size(); |
| 1081 | absl::flat_hash_set<int> unvisited; |
| 1082 | for (int i = 0; i < num_nodes; i++) { |
| 1083 | unvisited.insert(i); |
| 1084 | } |
| 1085 | while (!unvisited.empty()) { |
| 1086 | int cur_node = *unvisited.begin(); |
| 1087 | // Nodes on the current branch of DFS in traversal order. This is used for |
| 1088 | // printing the nodes in the cycle. |
| 1089 | std::vector<int> cur_branch; |
| 1090 | // This is just to make lookups O(1). |
| 1091 | // is_on_cur_branch[i] == |
| 1092 | // (std::find(cur_branch.start(), |
| 1093 | // cur_branch.end(), i) != cur_branch.end()) |
| 1094 | std::vector<bool> is_on_cur_branch(num_nodes, false); |
| 1095 | DFS(cur_node, &cur_branch, &is_on_cur_branch, &unvisited); |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | Status GraphConstructor::Convert() { |
| 1100 | // Import functions before adding nodes, since imported nodes may refer to |