nlsr: refactor equality operator
Change-Id: Iaaef9511e6569d597afcc5fa083b98ce86d8f78d refs: #4127
This commit is contained in:
1 parent
4964870e9d
commit
af87575012
1 file changed
+4
-22
+4
-22
@@ -87,32 +87,14 @@ AdjacencyList::getAdjacent(const ndn::Name& adjName)
|
||||
bool
|
||||
AdjacencyList::operator==(const AdjacencyList& adl) const
|
||||
{
|
||||
if (size() != adl.size()) {
|
||||
if (m_adjList.size() != adl.getAdjList().size()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto comparator =
|
||||
[] (const Adjacent* lhs, const Adjacent* rhs) {
|
||||
return *lhs < *rhs;
|
||||
};
|
||||
std::set<Adjacent> ourList(m_adjList.cbegin(), m_adjList.cend());
|
||||
std::set<Adjacent> theirList(adl.getAdjList().cbegin(), adl.getAdjList().cend());
|
||||
|
||||
std::vector<const Adjacent*> ourList;
|
||||
std::transform(m_adjList.begin(), m_adjList.end(),
|
||||
std::back_inserter(ourList), std::pointer_traits<const Adjacent*>::pointer_to);
|
||||
|
||||
std::vector<const Adjacent*> theirList;
|
||||
std::transform(adl.getAdjList().begin(), adl.getAdjList().end(),
|
||||
std::back_inserter(theirList), std::pointer_traits<const Adjacent*>::pointer_to);
|
||||
|
||||
std::sort(ourList.begin(), ourList.end(), std::bind(comparator, _1, _2));
|
||||
std::sort(theirList.begin(), theirList.end(), std::bind(comparator, _1, _2));
|
||||
|
||||
for (size_t i = 0; i < ourList.size(); i++) {
|
||||
if (*(ourList[i]) != *(theirList[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return ourList == theirList;
|
||||
}
|
||||
|
||||
int32_t
|
||||
|
||||
Reference in new issue
Block a user