Skip to content

Commit

Permalink
[projmgr] List layers: fix removal of subset configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
brondani committed Jul 11, 2024
1 parent b74676e commit 3546386
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 7 additions & 5 deletions tools/projmgr/src/ProjMgrWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4427,6 +4427,9 @@ bool ProjMgrWorker::IsConnectionSubset(const ConnectionsCollection& connectionSu
}

bool ProjMgrWorker::IsCollectionSubset(const ConnectionsCollectionVec& collectionSubset, const ConnectionsCollectionVec& collectionSuperset) {
if (collectionSubset.size() != collectionSuperset.size()) {
return false;
}
for (const auto& subset : collectionSubset) {
bool isSubset = false;
for (const auto& superset : collectionSuperset) {
Expand All @@ -4443,15 +4446,14 @@ bool ProjMgrWorker::IsCollectionSubset(const ConnectionsCollectionVec& collectio
}

void ProjMgrWorker::RemoveRedundantSubsets(std::vector<ConnectionsCollectionVec>& validConnections) {
const auto connections = validConnections;
auto it = validConnections.begin();
for (const auto& collection : connections) {
while (it < validConnections.end()) {
bool isSubset = false;
for (const auto& otherCollection : connections) {
if (&collection == &otherCollection) {
for (auto it2 = validConnections.begin(); it2 < validConnections.end(); it2++) {
if (it == it2) {
continue;
}
if (IsCollectionSubset(collection, otherCollection)) {
if (IsCollectionSubset(*it, *it2)) {
isSubset = true;
break;
}
Expand Down
19 changes: 15 additions & 4 deletions tools/projmgr/test/src/ProjMgrWorkerUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,15 +1259,26 @@ TEST_F(ProjMgrWorkerUnitTests, RemoveRedundantSubsets) {
const string strA = "A";
const string strB = "B";
const string strC = "C";
ConnectionsCollection A = { strA, RteUtils::EMPTY_STRING };
ConnectionsCollection B = { strB, RteUtils::EMPTY_STRING };
ConnectItem connect1 = { "1" };
ConnectItem connect2 = { "2" };
ConnectItem connect3 = { "3" };
const ConnectItem* c1 = { &connect1 };
const ConnectItem* c2 = { &connect2 };
const ConnectItem* c3 = { &connect3 };
ConnectionsCollection A = { strA, RteUtils::EMPTY_STRING, {c1, c2, c3} };
ConnectionsCollection As = { strA, RteUtils::EMPTY_STRING, {c3, c1} };
ConnectionsCollection B = { strB, RteUtils::EMPTY_STRING, {c1, c2, c3} };
ConnectionsCollection Bs = { strB, RteUtils::EMPTY_STRING, {c2} };
ConnectionsCollection C = { strC, RteUtils::EMPTY_STRING };
ConnectionsCollectionVec vecAB = { A, B };
ConnectionsCollectionVec vecA = { A };
ConnectionsCollectionVec vecAs = { As };
ConnectionsCollectionVec vecB = { B };
ConnectionsCollectionVec vecBs = { Bs };
ConnectionsCollectionVec vecC = { C };
vector<ConnectionsCollectionVec> validConnections = { vecAB, vecA, vecB, vecC };
vector<ConnectionsCollectionVec> expected = { vecAB, vecC };
ConnectionsCollectionVec vecBA = { B, A };
vector<ConnectionsCollectionVec> validConnections = { vecBs, vecAB, vecA, vecBA, vecB, vecAB, vecAs, vecC, vecBs };
vector<ConnectionsCollectionVec> expected = { vecA, vecB, vecAB, vecC };
RemoveRedundantSubsets(validConnections);
auto it = validConnections.begin();
for (const auto& expectedItem : expected) {
Expand Down

0 comments on commit 3546386

Please sign in to comment.