GCC Code Coverage Report


Directory: ./
File: Graphs/GraphRoutines.cpp
Date: 2022-10-15 05:10:18
Exec Total Coverage
Lines: 25 25 100.0%
Functions: 1 1 100.0%
Branches: 23 34 67.6%
Decisions: 12 12 100.0%

Line Branch Decision Exec Source
1 // Copyright 2019-2022 Cambridge Quantum Computing
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "GraphRoutines.hpp"
16
17 #include <stack>
18
19 #include "AdjacencyData.hpp"
20
21 using std::map;
22 using std::set;
23 using std::size_t;
24 using std::vector;
25
26 namespace tket {
27 namespace graphs {
28
29 17163 vector<set<size_t>> GraphRoutines::get_connected_components(
30 const AdjacencyData& adjacency_data) {
31 17163 set<size_t> vertices_seen;
32 17163 vector<set<size_t>> result;
33
1/2
✓ Branch 1 taken 17163 times.
✗ Branch 2 not taken.
17163 const size_t number_of_vertices = adjacency_data.get_number_of_vertices();
34
35
2/2
✓ Branch 0 taken 498031 times.
✓ Branch 1 taken 17163 times.
2/2
✓ Decision 'true' taken 498031 times.
✓ Decision 'false' taken 17163 times.
515194 for (size_t v = 0; v < number_of_vertices; ++v) {
36
3/4
✓ Branch 1 taken 498031 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 192604 times.
✓ Branch 4 taken 305427 times.
2/2
✓ Decision 'true' taken 192604 times.
✓ Decision 'false' taken 305427 times.
498031 if (vertices_seen.count(v) != 0) {
37 192604 continue;
38 }
39 305427 set<size_t> vertices_seen_in_this_component;
40
1/2
✓ Branch 1 taken 305427 times.
✗ Branch 2 not taken.
305427 vertices_seen_in_this_component.insert(v);
41
42
1/2
✓ Branch 1 taken 305427 times.
✗ Branch 2 not taken.
305427 std::stack<size_t> vertices_to_examine_next;
43
1/2
✓ Branch 1 taken 305427 times.
✗ Branch 2 not taken.
305427 vertices_to_examine_next.push(v);
44
45
2/2
✓ Branch 1 taken 498031 times.
✓ Branch 2 taken 305427 times.
2/2
✓ Decision 'true' taken 498031 times.
✓ Decision 'false' taken 305427 times.
803458 while (!vertices_to_examine_next.empty()) {
46 498031 const size_t this_vertex = vertices_to_examine_next.top();
47 498031 vertices_to_examine_next.pop();
48 const auto& neighbouring_vertices =
49
1/2
✓ Branch 1 taken 498031 times.
✗ Branch 2 not taken.
498031 adjacency_data.get_neighbours(this_vertex);
50
51
2/2
✓ Branch 5 taken 777594 times.
✓ Branch 6 taken 498031 times.
2/2
✓ Decision 'true' taken 777594 times.
✓ Decision 'false' taken 498031 times.
1275625 for (size_t j : neighbouring_vertices) {
52
3/4
✓ Branch 1 taken 777594 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 192604 times.
✓ Branch 4 taken 584990 times.
2/2
✓ Decision 'true' taken 192604 times.
✓ Decision 'false' taken 584990 times.
777594 if (vertices_seen_in_this_component.count(j) == 0) {
53
1/2
✓ Branch 1 taken 192604 times.
✗ Branch 2 not taken.
192604 vertices_to_examine_next.push(j);
54
1/2
✓ Branch 1 taken 192604 times.
✗ Branch 2 not taken.
192604 vertices_seen_in_this_component.insert(j);
55 }
56 }
57 }
58 // Now, push back the vertices seen.
59
1/2
✓ Branch 1 taken 305427 times.
✗ Branch 2 not taken.
305427 result.emplace_back(vertices_seen_in_this_component);
60
2/2
✓ Branch 5 taken 498031 times.
✓ Branch 6 taken 305427 times.
2/2
✓ Decision 'true' taken 498031 times.
✓ Decision 'false' taken 305427 times.
803458 for (size_t k : vertices_seen_in_this_component) {
61
1/2
✓ Branch 1 taken 498031 times.
✗ Branch 2 not taken.
498031 vertices_seen.insert(k);
62 }
63 305427 }
64 34326 return result;
65 17163 }
66
67 } // namespace graphs
68 } // namespace tket
69