SpiecsEngine
 
Loading...
Searching...
No Matches
DirectedAcyclicGraph.cpp
Go to the documentation of this file.
1/**
2* @file DirectedAcyclicGraph.cpp.
3* @brief The DirectedAcyclicGraph Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9
10namespace scl {
11
13 {
14 m_Nodes[node->m_Name] = node;
15 }
16
18 {
19 std::unordered_map<std::string, bool> visited;
20 for (auto& node : m_Nodes)
21 {
22 if (!visited[node.first])
23 {
24 execute_internal(node.second, visited);
25 }
26 }
27 }
28
29 void directed_acyclic_graph::execute_internal(directed_acyclic_node* node, std::unordered_map<std::string, bool>& visited)
30 {
31 visited[node->m_Name] = true;
32 for (auto& dep : node->m_Dependencies)
33 {
34 if (!visited[dep])
35 {
36 execute_internal(m_Nodes[dep], visited);
37 }
38 }
39 node->m_Func();
40 }
41}
void add_node(directed_acyclic_node *node)
Add a node to this graph.
void execute_internal(directed_acyclic_node *node, std::unordered_map< std::string, bool > &visited)
Execute a node's function.
void execute()
Execute all node function by order.