MCPcopy Create free account
hub / github.com/colmap/colmap / BuildParentsFromAdjacencyList

Function BuildParentsFromAdjacencyList

src/colmap/math/spanning_tree.cc:49–75  ·  view source on GitHub ↗

Build parent pointers from adjacency list using BFS from root.

Source from the content-addressed store, hash-verified

47
48// Build parent pointers from adjacency list using BFS from root.
49void BuildParentsFromAdjacencyList(
50 const std::vector<std::vector<int>>& adjacency_list,
51 int root,
52 std::vector<int>& parents) {
53 const int num_nodes = static_cast<int>(adjacency_list.size());
54 parents.assign(num_nodes, -1);
55 parents[root] = root;
56
57 std::vector<char> visited(num_nodes, false);
58 visited[root] = true;
59
60 std::queue<int> queue;
61 queue.push(root);
62
63 while (!queue.empty()) {
64 const int current = queue.front();
65 queue.pop();
66
67 for (const int neighbor : adjacency_list[current]) {
68 if (!visited[neighbor]) {
69 visited[neighbor] = true;
70 parents[neighbor] = current;
71 queue.push(neighbor);
72 }
73 }
74 }
75}
76
77SpanningTree ComputeSpanningTreeInternal(
78 int num_nodes,

Callers 1

Calls 2

sizeMethod · 0.80
emptyMethod · 0.80

Tested by

no test coverage detected