{
auto &operations = graph.operations();
bool cyclic = false;
- std::vector<bool> visited(operations.size(), false);
- std::vector<bool> on_stack(operations.size(), false);
+
+ std::unordered_map<operation::Index, bool> visited;
+ operations.iterate([&](const graph::operation::Index &index, const operation::Node &) {
+ visited[index] = false;
+ });
+ std::unordered_map<operation::Index, bool> on_stack = visited; // Copy from visited
std::function<void(const operation::Index &index, const operation::Node &)> dfs_recursive =
[&](const operation::Index &index, const operation::Node &node) -> void {
- if (on_stack[index.value()])
+ if (on_stack[index])
cyclic = true;
- if (visited[index.value()])
+ if (visited[index])
return;
- visited[index.value()] = true;
- on_stack[index.value()] = true;
+ visited[index] = true;
+ on_stack[index] = true;
for (auto output : node.getOutputs())
{
}
}
- on_stack[index.value()] = false;
+ on_stack[index] = false;
};
operations.iterate(dfs_recursive);