topology: refactor upstreamPorts, downstreamPorts
go from
```
std::unordered_map<PortType, std::vector<Path>> upstreamPorts;
std::unordered_map<PortType, std::vector<Path>> downstreamPorts;
```
to
```
std::unordered_map<PortType, std::set<Path>> upstreamPorts;
std::unordered_map<PortType, std::set<Path>> downstreamPorts;
```
since a given inventory item can only be an upstream once for a given
association.
Also, associations do not have any 'order' in which they need to be
created so we do not need any specific ordering as with a vector.
Tested: Topology Unit Tests Pass
Change-Id: I47e49343992eaad7ea2587e71a5499bc3dccc064
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index 1828ed7..3b9521c 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -22,7 +22,7 @@
}
else if (exposesType.ends_with("Port"))
{
- upstreamPorts[exposesType].emplace_back(path);
+ upstreamPorts[exposesType].insert(path);
}
else
{
@@ -43,7 +43,7 @@
}
PortType connectsTo = findConnectsTo->get<std::string>();
- downstreamPorts[connectsTo].emplace_back(path);
+ downstreamPorts[connectsTo].insert(path);
auto findPoweredBy = exposesItem.find("PowerPort");
if (findPoweredBy != exposesItem.end())
{
@@ -110,11 +110,11 @@
for (auto& upstreamPort : upstreamPorts)
{
- std::erase(upstreamPort.second, boardPath);
+ upstreamPort.second.erase(boardPath);
}
for (auto& downstreamPort : downstreamPorts)
{
- std::erase(downstreamPort.second, boardPath);
+ downstreamPort.second.erase(boardPath);
}
}
diff --git a/src/entity_manager/topology.hpp b/src/entity_manager/topology.hpp
index 3ca214d..a1f00fe 100644
--- a/src/entity_manager/topology.hpp
+++ b/src/entity_manager/topology.hpp
@@ -27,8 +27,8 @@
void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem);
- std::unordered_map<PortType, std::vector<Path>> upstreamPorts;
- std::unordered_map<PortType, std::vector<Path>> downstreamPorts;
+ std::unordered_map<PortType, std::set<Path>> upstreamPorts;
+ std::unordered_map<PortType, std::set<Path>> downstreamPorts;
std::set<Path> powerPaths;
std::unordered_map<Path, BoardType> boardTypes;
std::unordered_map<BoardName, Path> boardNames;