Skip to content

Commit

Permalink
Different way of removing duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
ktf committed Aug 22, 2023
1 parent 6c5cd3c commit 6be9149
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Framework/Core/src/FairMQDeviceProxy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <fairmq/Message.h>
#include <fairmq/TransportFactory.h>

#include <unordered_set>

namespace o2::framework
{

Expand Down Expand Up @@ -142,9 +144,11 @@ void FairMQDeviceProxy::getMatchingForwardChannelIndexes(std::vector<ChannelInde
result.emplace_back(mForwardRoutes[ri].channel);
}
}
// Make it unique. A given set of payloads needs to be forwarded only once per channel.
std::sort(result.begin(), result.end(), [](ChannelIndex const& a, ChannelIndex const& b) { return a.value < b.value; });
result.erase(std::unique(result.begin(), result.end(), [](ChannelIndex const& a, ChannelIndex const& b) { return a.value == b.value; }), result.end());
// Remove duplicates, keeping the order of the channels.
std::unordered_set<int> numSet;
auto iter = std::stable_partition(result.begin(), result.end(),
[&](ChannelIndex n) { bool ret = !numSet.count(n.value); numSet.insert(n.value); return ret; }); // returns true if the item has not been "seen"
result.erase(iter, result.end());
}

ChannelIndex FairMQDeviceProxy::getOutputChannelIndexByName(std::string const& name) const
Expand Down

0 comments on commit 6be9149

Please sign in to comment.