Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/xrpl/protocol/STPathSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ class STPathElement final : public CountedObject<STPathElement>
bool
operator!=(STPathElement const& t) const;

[[nodiscard]] std::size_t
hash() const noexcept
{
return hash_value_;
}
Comment on lines +114 to +118

private:
static std::size_t
getHash(STPathElement const& element);
Expand Down
22 changes: 9 additions & 13 deletions src/xrpld/rpc/detail/Pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <optional>
#include <ostream>
#include <string>
#include <unordered_set>
#include <vector>

namespace xrpl {
Expand Down Expand Up @@ -978,16 +979,10 @@ Pathfinder::isNoRippleOut(STPath const& currentPath)
}

void
addUniquePath(STPathSet& pathSet, STPath const& path)
addUniquePath(STPathSet& pathSet, std::unordered_set<STPath, STPathHash>& index, STPath const& path)
{
// TODO(tom): building an STPathSet this way is quadratic in the size
// of the STPathSet!
for (auto const& p : pathSet)
{
if (p == path)
return;
}
pathSet.pushBack(path);
if (index.insert(path).second)
pathSet.pushBack(path);
}
Comment on lines 981 to 986

void
Expand Down Expand Up @@ -1021,7 +1016,7 @@ Pathfinder::addLink(
{ // non-default path to XRP destination
JLOG(j_.trace()) << "complete path found ax: "
<< currentPath.getJson(JsonOptions::KNone);
addUniquePath(completePaths_, currentPath);
addUniquePath(completePaths_, completePathsIndex_, currentPath);
}
}
else
Expand Down Expand Up @@ -1124,7 +1119,8 @@ Pathfinder::addLink(
{
JLOG(j_.trace()) << "complete path found ae: "
<< currentPath.getJson(JsonOptions::KNone);
addUniquePath(completePaths_, currentPath);
addUniquePath(
completePaths_, completePathsIndex_, currentPath);
}
}
else if (!bDestOnly)
Expand Down Expand Up @@ -1255,7 +1251,7 @@ Pathfinder::addLink(
// complete
JLOG(j_.trace()) << "complete path found bx: "
<< currentPath.getJson(JsonOptions::KNone);
addUniquePath(completePaths_, newPath);
addUniquePath(completePaths_, completePathsIndex_, newPath);
}
else
{
Expand Down Expand Up @@ -1301,7 +1297,7 @@ Pathfinder::addLink(
// complete
JLOG(j_.trace()) << "complete path found ba: "
<< currentPath.getJson(JsonOptions::KNone);
addUniquePath(completePaths_, newPath);
addUniquePath(completePaths_, completePathsIndex_, newPath);
}
else
{
Expand Down
15 changes: 15 additions & 0 deletions src/xrpld/rpc/detail/Pathfinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,22 @@
#include <xrpl/protocol/STAmount.h>
#include <xrpl/protocol/STPathSet.h>

#include <unordered_set>

namespace xrpl {

struct STPathHash
{
std::size_t
operator()(STPath const& path) const noexcept
{
std::size_t h = path.size();
for (auto const& elem : path)
h ^= elem.hash() + 0x9e3779b9 + (h << 6) + (h >> 2);
return h;
}
};
Comment on lines +17 to +27

/** Calculates payment paths.

The @ref RippleCalc determines the quality of the found paths.
Expand Down Expand Up @@ -187,6 +201,7 @@ class Pathfinder : public CountedObject<Pathfinder>

STPathElement source_;
STPathSet completePaths_;
std::unordered_set<STPath, STPathHash> completePathsIndex_;
Comment on lines 202 to +204
std::vector<PathRank> pathRanks_;
std::map<PathType, STPathSet> paths_;

Expand Down
Loading