diff --git a/src/cpp/ripple/PathDB.cpp b/src/cpp/ripple/PathDB.cpp new file mode 100644 index 000000000..4c9f8a47d --- /dev/null +++ b/src/cpp/ripple/PathDB.cpp @@ -0,0 +1 @@ +#include "PathDB.h" diff --git a/src/cpp/ripple/PathDB.h b/src/cpp/ripple/PathDB.h new file mode 100644 index 000000000..138e78bf6 --- /dev/null +++ b/src/cpp/ripple/PathDB.h @@ -0,0 +1,78 @@ +#ifndef PATHDB__H +#define PATHBD__H + +#include "uint256.h" +#include "TaggedCache.h" + +typedef std::pair currencyIssuer_t; +typedef std::pair currencyIssuer_ct; + +class PathDBEntry +{ +public: + typedef boost::shared_ptr pointer; + typedef const pointer& ref; + + const unsigned int sIsExchange = 0x00001; + const unsigned int sIsOffer = 0x00002; + const unsigned int sIsDirty = 0x10000; + +protected: + currencyIssuer_t mIn; + currencyIssuer_t mOut; + uint32 mLastSeq; + int mUseCount; + unsigned mFlags; + std::size_t mHash; + +public: + + void updateSeq(uint32); + + const uint160& getCurrencyIn() const { return mIn.first; } + const uint160& getIssuerIn() const { return mIn.second; } + const uint160& getCurrencyOut() const { return mOut.first; } + const uint160& getIssuerOut() const { return mOut.second; } + + bool isExchange() const; + bool isOffer() const; + bool isDirty() const; +}; + +class PathDB +{ +protected: + boost::recursive_mutex mLock; + TaggedCache mFromCache; + TaggedCache mToCache; + std::set mDirtyPaths; + +public: + + PathDB(); + + std::vector getPathsFrom(const uint160& currency, const uint160& issuer, + int maxBestPaths = 10, int maxRandPaths = 10); + + std::vector getPathsTo(const uint160& currency, const uint160& issuer, + int maxBestPaths = 10, int maxRandPaths = 10); + + void usedLine(const uint160& currency, const uint160& accountIn, const uint160& accountOut); + void usedExchange(const uint160& currencyFrom, const uint160& issuerFrom, + const uint160& currencyTo, const uint160& issuerTo); +}; + +extern std::size_t hash_value(const currencyIssuer_ct& ci) +{ + std::size_t r = hash_value(ci.second); + return ci.first.hash_combine(r); +} + +static inline std::size_t hash_value(const currencyIssuer_t& ci) +{ + std::size_t r = hash_value(ci.second); + return ci.first.hash_combine(r); +} + + +#endif