From 1f5cff396a757206c4ea222f6ca01578e0d045c7 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 6 Mar 2013 14:54:05 -0800 Subject: [PATCH] Fix comparison logic. --- src/cpp/ripple/Pathfinder.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cpp/ripple/Pathfinder.cpp b/src/cpp/ripple/Pathfinder.cpp index 1426d5e3b..5406076c2 100644 --- a/src/cpp/ripple/Pathfinder.cpp +++ b/src/cpp/ripple/Pathfinder.cpp @@ -79,9 +79,17 @@ PathOption::PathOption(PathOption::pointer other) #endif // Lower numbers have better quality. Sort higher quality first. -static bool bQualityCmp(std::pair a, std::pair b) +static bool bQualityCmp( + std::pair< std::pair, unsigned int> a, + std::pair< std::pair, unsigned int> b) { - return a.first < b.first; + if (a.first.first != b.first.first) + return a.first.first < b.first.first; + + if (a.first.second != b.first.second) + return a.first.second < b.first.second; + + return a.second < b.second; // FIXME: this biases accounts } // Return true, if path is a default path with an element. @@ -509,7 +517,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax // Only filter, sort, and limit if have non-default paths. if (iLimit) { - std::vector< std::pair > vMap; + std::vector< std::pair< std::pair, unsigned int> > vMap; // Build map of quality to entry. for (int i = vspResults.size(); i--;) @@ -556,7 +564,7 @@ bool Pathfinder::findPaths(const unsigned int iMaxSteps, const unsigned int iMax % uQuality % spCurrent.getJson(0)); - vMap.push_back(std::make_pair(uQuality, i)); + vMap.push_back(std::make_pair(std::make_pair(uQuality, spCurrent.mPath.size()), i)); } else {