data/RelationGraphBlocks.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "RelationGraphBlocks.h" | ||
| 2 | |||
| 3 | #include "RelationGraphRows.h" | ||
| 4 | |||
| 5 | #include <QHash> | ||
| 6 | #include <QMap> | ||
| 7 | #include <numeric> | ||
| 8 | |||
| 9 | namespace RelationGraphLayout { | ||
| 10 | |||
| 11 | 22 | QList<QList<int>> overviewBlocks(const RelationGraph::Graph &graph, QSet<int> *inArea) { | |
| 12 | 22 | const int n = int(graph.nodes.size()); | |
| 13 |
1/1✓ Branch 3 → 4 taken 22 times.
|
22 | QList<int> root(n); |
| 14 |
3/3✓ Branch 4 → 5 taken 22 times.
✓ Branch 5 → 6 taken 22 times.
✓ Branch 6 → 7 taken 22 times.
|
22 | std::iota(root.begin(), root.end(), 0); |
| 15 | 6962 | const auto find = [&root](int i) { | |
| 16 |
2/2✓ Branch 8 → 3 taken 3382 times.
✓ Branch 8 → 9 taken 6962 times.
|
10344 | while (root[i] != i) |
| 17 | 3382 | i = root[i] = root[root[i]]; | |
| 18 | 6962 | return i; | |
| 19 | 22 | }; | |
| 20 |
2/2✓ Branch 30 → 9 taken 2986 times.
✓ Branch 30 → 31 taken 22 times.
|
3008 | for (const RelationGraph::Edge &e : graph.edges) { |
| 21 | 2986 | int step = 0; | |
| 22 |
5/8✓ Branch 11 → 12 taken 2986 times.
✗ Branch 11 → 22 not taken.
✓ Branch 12 → 13 taken 2986 times.
✗ Branch 12 → 22 not taken.
✓ Branch 15 → 16 taken 2954 times.
✓ Branch 15 → 22 taken 32 times.
✓ Branch 18 → 19 taken 2954 times.
✗ Branch 18 → 22 not taken.
|
5940 | if (e.from >= 0 && e.to >= 0 && e.from != e.to && isShown(graph.nodes.at(e.from)) && |
| 23 |
6/7✓ Branch 10 → 11 taken 2986 times.
✗ Branch 10 → 22 not taken.
✓ Branch 19 → 20 taken 2954 times.
✓ Branch 20 → 21 taken 1342 times.
✓ Branch 20 → 22 taken 1612 times.
✓ Branch 23 → 24 taken 1342 times.
✓ Branch 23 → 28 taken 1644 times.
|
8926 | isShown(graph.nodes.at(e.to)) && kinStep(e, &step)) |
| 24 |
3/3✓ Branch 24 → 25 taken 1342 times.
✓ Branch 25 → 26 taken 1342 times.
✓ Branch 26 → 27 taken 1342 times.
|
1342 | root[find(e.from)] = find(e.to); |
| 25 | } | ||
| 26 | // The members of one family card form one block, too: its area is drawn | ||
| 27 | // around them and would otherwise stretch between blocks far apart. | ||
| 28 |
2/2✓ Branch 58 → 33 taken 12 times.
✓ Branch 58 → 59 taken 22 times.
|
34 | for (const RelationGraph::Area &area : graph.areas) { |
| 29 | 12 | int first = -1; | |
| 30 |
2/2✓ Branch 55 → 36 taken 32 times.
✓ Branch 55 → 56 taken 12 times.
|
44 | for (int member : area.members) { |
| 31 |
4/8✓ Branch 37 → 38 taken 32 times.
✗ Branch 37 → 42 not taken.
✓ Branch 38 → 39 taken 32 times.
✗ Branch 38 → 42 not taken.
✗ Branch 41 → 42 not taken.
✓ Branch 41 → 43 taken 32 times.
✗ Branch 44 → 45 not taken.
✓ Branch 44 → 46 taken 32 times.
|
32 | if (member < 0 || member >= n || !isShown(graph.nodes.at(member))) |
| 32 | ✗ | continue; | |
| 33 |
1/1✓ Branch 46 → 47 taken 32 times.
|
32 | inArea->insert(member); |
| 34 |
2/2✓ Branch 47 → 48 taken 12 times.
✓ Branch 47 → 49 taken 20 times.
|
32 | if (first < 0) |
| 35 | 12 | first = member; | |
| 36 | else | ||
| 37 |
3/3✓ Branch 49 → 50 taken 20 times.
✓ Branch 50 → 51 taken 20 times.
✓ Branch 51 → 52 taken 20 times.
|
20 | root[find(member)] = find(first); |
| 38 | } | ||
| 39 | } | ||
| 40 | 22 | QMap<QString, QList<int>> byFirstKey; // deterministic block order | |
| 41 | 22 | QHash<int, QString> firstKey; | |
| 42 |
2/2✓ Branch 80 → 60 taken 2131 times.
✓ Branch 80 → 81 taken 22 times.
|
2153 | for (int i = 0; i < n; ++i) |
| 43 |
2/2✓ Branch 62 → 63 taken 2119 times.
✓ Branch 62 → 79 taken 12 times.
|
2131 | if (isShown(graph.nodes.at(i))) { |
| 44 |
1/1✓ Branch 63 → 64 taken 2119 times.
|
2119 | const int r = find(i); |
| 45 |
8/8✓ Branch 65 → 66 taken 1159 times.
✓ Branch 65 → 71 taken 960 times.
✓ Branch 70 → 71 taken 152 times.
✓ Branch 70 → 72 taken 1007 times.
✓ Branch 73 → 74 taken 1159 times.
✓ Branch 73 → 75 taken 960 times.
✓ Branch 75 → 76 taken 1112 times.
✓ Branch 75 → 78 taken 1007 times.
|
2119 | if (!firstKey.contains(r) || graph.nodes.at(i).key < firstKey.value(r)) |
| 46 |
1/1✓ Branch 77 → 78 taken 1112 times.
|
1112 | firstKey.insert(r, graph.nodes.at(i).key); |
| 47 | } | ||
| 48 |
2/2✓ Branch 92 → 82 taken 2131 times.
✓ Branch 92 → 93 taken 22 times.
|
2153 | for (int i = 0; i < n; ++i) |
| 49 |
2/2✓ Branch 84 → 85 taken 2119 times.
✓ Branch 84 → 91 taken 12 times.
|
2131 | if (isShown(graph.nodes.at(i))) |
| 50 |
3/3✓ Branch 85 → 86 taken 2119 times.
✓ Branch 87 → 88 taken 2119 times.
✓ Branch 88 → 89 taken 2119 times.
|
2119 | byFirstKey[firstKey.value(find(i))].append(i); |
| 51 |
1/1✓ Branch 93 → 94 taken 22 times.
|
44 | return byFirstKey.values(); |
| 52 | 22 | } | |
| 53 | |||
| 54 | } // namespace RelationGraphLayout | ||
| 55 |