MCPcopy Create free account
hub / github.com/LBANN/lbann / breadth_first_search

Function breadth_first_search

src/utils/graph.cpp:162–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160}
161
162std::vector<El::Int>
163breadth_first_search(El::Int root,
164 const std::map<El::Int, std::set<El::Int>>& edges)
165{
166
167 // Initialize data structures
168 std::unordered_map<El::Int, bool> is_visited;
169 std::vector<El::Int> sorted_nodes;
170 std::queue<El::Int> search_queue;
171 search_queue.push(root);
172
173 // Visit nodes until search queue is exhausted
174 while (!search_queue.empty()) {
175 const auto& node = search_queue.front();
176 search_queue.pop();
177 for (const auto& neighbor : get_neighbors(node, edges)) {
178 if (!is_visited[neighbor]) {
179 is_visited[neighbor] = true;
180 sorted_nodes.push_back(neighbor);
181 search_queue.push(neighbor);
182 }
183 }
184 }
185
186 // Return list of sorted nodes
187 return sorted_nodes;
188}
189
190std::vector<El::Int>
191depth_first_search(El::Int root,

Callers

nothing calls this directly

Calls 3

get_neighborsFunction · 0.85
pushMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected