MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / bfs

Function bfs

src/graph/algorithms/TopologicalSort.cpp:72–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70} // namespace detail
71
72std::vector<NodeID> bfs(Graph &g)
73{
74 std::vector<NodeID> bfs_order_vector;
75
76 // Created visited vector
77 std::vector<bool> visited(g.nodes().size(), false);
78
79 // Create BFS queue
80 std::list<NodeID> queue;
81
82 // Push inputs and mark as visited
83 for (auto &input : g.nodes(NodeType::Input))
84 {
85 if (input != EmptyNodeID)
86 {
87 visited[input] = true;
88 queue.push_back(input);
89 }
90 }
91
92 // Push const nodes and mark as visited
93 for (auto &const_node : g.nodes(NodeType::Const))
94 {
95 if (const_node != EmptyNodeID)
96 {
97 visited[const_node] = true;
98 queue.push_back(const_node);
99 }
100 }
101
102 // Iterate over vector and edges
103 while (!queue.empty())
104 {
105 // Dequeue a node from queue and process
106 NodeID n = queue.front();
107 bfs_order_vector.push_back(n);
108 queue.pop_front();
109
110 const INode *node = g.node(n);
111 ARM_COMPUTE_ERROR_ON(node == nullptr);
112 for (const auto &eid : node->output_edges())
113 {
114 const Edge *e = g.edge(eid);
115 ARM_COMPUTE_ERROR_ON(e == nullptr);
116 if (!visited[e->consumer_id()] && detail::all_inputs_are_visited(e->consumer(), visited))
117 {
118 visited[e->consumer_id()] = true;
119 queue.push_back(e->consumer_id());
120 }
121 }
122 }
123
124 return bfs_order_vector;
125}
126
127std::vector<NodeID> dfs(Graph &g)
128{

Callers

nothing calls this directly

Calls 8

all_inputs_are_visitedFunction · 0.85
push_backMethod · 0.80
nodeMethod · 0.80
edgeMethod · 0.80
consumer_idMethod · 0.80
consumerMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected