Refactor RippleCalc.cpp:

* Add comments
* Restrict code to 80 colums
* Remove boost::format
* Remove BOOST_FOREACH
* Make members private
* Add ripple_unordered_set to UnorderedContainers.h
* Replace boost::unordered_set with ripple::unordered_set
This commit is contained in:
Tom Swirly
2014-05-08 13:53:13 -04:00
committed by Nik Bougalis
parent 6f2bcc6fb0
commit 390ea65e15
13 changed files with 1418 additions and 1264 deletions

View File

@@ -29,7 +29,7 @@
#include "../../beast/beast/chrono/chrono_io.h"
#include "../../beast/beast/Insight.h"
#include "../../beast/beast/container/hardened_hash.h"
#include "UnorderedMap.h"
#include "UnorderedContainers.h"
namespace ripple {

View File

@@ -17,12 +17,13 @@
*/
//==============================================================================
#ifndef RIPPLE_UNORDERED_MAP_H
#define RIPPLE_UNORDERED_MAP_H
#ifndef RIPPLE_UNORDERED_CONTAINERS_H
#define RIPPLE_UNORDERED_CONTAINERS_H
#include "../../beast/beast/container/hash_append.h"
#include <unordered_map>
#include <unordered_set>
namespace ripple
{
@@ -32,6 +33,11 @@ template <class Key, class Value, class Hash = beast::uhash<>,
class Allocator = std::allocator<std::pair<Key const, Value>>>
using unordered_map = std::unordered_map <Key, Value, Hash, Pred, Allocator>;
template <class Value, class Hash = beast::uhash<>,
class Pred = std::equal_to<Value>,
class Allocator = std::allocator<Value>>
using unordered_set = std::unordered_set <Value, Hash, Pred, Allocator>;
} // ripple
#endif

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_RESOURCE_LOGIC_H_INCLUDED
#define RIPPLE_RESOURCE_LOGIC_H_INCLUDED
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include "../../beast/beast/chrono/abstract_clock.h"
@@ -595,17 +595,17 @@ public:
beast::PropertyStream::Set s ("inbound", map);
writeList (now, s, state->inbound);
}
{
beast::PropertyStream::Set s ("outbound", map);
writeList (now, s, state->outbound);
}
{
beast::PropertyStream::Set s ("admin", map);
writeList (now, s, state->admin);
}
{
beast::PropertyStream::Set s ("inactive", map);
writeList (now, s, state->inactive);

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SITEFILES_SECTION_H_INCLUDED
#define RIPPLE_SITEFILES_SECTION_H_INCLUDED
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include <vector>
namespace ripple {

View File

@@ -21,7 +21,7 @@
#define RIPPLE_SITEFILES_SITEFILE_H_INCLUDED
#include "Section.h"
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include <string>
#include <unordered_map>

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SITEFILES_LOGIC_H_INCLUDED
#define RIPPLE_SITEFILES_LOGIC_H_INCLUDED
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include <memory>
@@ -32,7 +32,7 @@ Config file format:
Syntactically a series of lines, where line has this format:
[ <vertical whitespace> ] <anything> ( <vertical-whitespace> OR <end-of-file> )
Semantically a series of of zero or more sections, where each section
has a name and optional data. Specifically, the format:
( <start-of-file> OR <header> ) <data>
@@ -119,7 +119,7 @@ public:
void addURL (std::string const& urlstr)
{
beast::ParsedURL const p (urlstr);
if (p.error())
{
m_journal.error <<

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include "../../../beast/beast/unit_test/suite.h"

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include "../../../beast/beast/unit_test/suite.h"
@@ -193,7 +193,7 @@ public:
{
Map c;
c.insert (std::make_pair (a1, 1));
if (! expect (c.size () == 1)) return;
c.insert (std::make_pair (a2, 2));
@@ -250,7 +250,7 @@ public:
testcase ("ripple::unordered_map <RippleAssetRef, int>");
testAssetMap <ripple::unordered_map <RippleAssetRef, int>> ();
#endif
#endif
}
//--------------------------------------------------------------------------
@@ -281,19 +281,19 @@ public:
// log << std::hex << hash (Book (a1, a2));
// log << std::hex << hash (Book (a1, a2));
//
//
// log << std::hex << hash (Book (a1, a3));
// log << std::hex << hash (Book (a1, a3));
//
//
// log << std::hex << hash (Book (a1, a4));
// log << std::hex << hash (Book (a1, a4));
//
//
// log << std::hex << hash (Book (a2, a3));
// log << std::hex << hash (Book (a2, a3));
//
//
// log << std::hex << hash (Book (a2, a4));
// log << std::hex << hash (Book (a2, a4));
//
//
// log << std::hex << hash (Book (a3, a4));
// log << std::hex << hash (Book (a3, a4));

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_VALIDATORS_CHOSENLIST_H_INCLUDED
#define RIPPLE_VALIDATORS_CHOSENLIST_H_INCLUDED
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
namespace ripple {
namespace Validators {

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_VALIDATORS_TUNING_H_INCLUDED
#define RIPPLE_VALIDATORS_TUNING_H_INCLUDED
#include "../../common/UnorderedMap.h"
#include "../../common/UnorderedContainers.h"
#include <boost/version.hpp>

File diff suppressed because it is too large Load Diff

View File

@@ -27,27 +27,47 @@ namespace ripple {
The quality is a synonym for price. Specifically, the amount of
input required to produce a given output along a specified path.
*/
// VFALCO TODO What's the difference between a RippleState versus PathState?
// TODO(vfalco) What's the difference between a RippleState versus PathState?
//
class RippleCalc
{
public:
// First time working in reverse a funding source was mentioned. Source may only be used there.
curIssuerNode mumSource; // Map of currency, issuer to node index.
private:
// First time working in reverse a funding source was mentioned. Source may
// only be used there.
//
// Map of currency, issuer to node index.
curIssuerNode mumSource;
// If the transaction fails to meet some constraint, still need to delete unfunded offers.
boost::unordered_set<uint256> musUnfundedFound; // Offers that were found unfunded.
// If the transaction fails to meet some constraint, still need to delete
// unfunded offers.
//
// Offers that were found unfunded.
unordered_set<uint256> mUnfundedOffers;
void pathNext (PathState::ref psrCur, const bool bMultiQuality, const LedgerEntrySet& lesCheckpoint, LedgerEntrySet& lesCurrent);
TER calcNode (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeRev (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeFwd (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeOfferRev (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeOfferFwd (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAccountRev (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAccountFwd (const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAdvance (const unsigned int uNode, PathState& psCur, const bool bMultiQuality, const bool bReverse);
TER calcNodeDeliverRev (
void pathNext (
PathState::ref psrCur, const bool bMultiQuality,
const LedgerEntrySet& lesCheckpoint, LedgerEntrySet& lesCurrent);
TER calcNode (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeRev (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeFwd (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeOfferRev (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeOfferFwd (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAccountRev (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAccountFwd (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality);
TER calcNodeAdvance (
const unsigned int uNode, PathState& psCur, const bool bMultiQuality,
const bool bReverse);
TER calcNodeDeliverRev (
const unsigned int uNode,
PathState& psCur,
const bool bMultiQuality,
@@ -55,7 +75,7 @@ public:
const STAmount& saOutReq,
STAmount& saOutAct);
TER calcNodeDeliverFwd (
TER calcNodeDeliverFwd (
const unsigned int uNode,
PathState& psCur,
const bool bMultiQuality,
@@ -64,39 +84,43 @@ public:
STAmount& saInAct,
STAmount& saInFees);
void calcNodeRipple (const std::uint32_t uQualityIn, const std::uint32_t uQualityOut,
const STAmount& saPrvReq, const STAmount& saCurReq,
STAmount& saPrvAct, STAmount& saCurAct,
std::uint64_t& uRateMax);
void calcNodeRipple (
const std::uint32_t uQualityIn, const std::uint32_t uQualityOut,
const STAmount& saPrvReq, const STAmount& saCurReq,
STAmount& saPrvAct, STAmount& saCurAct, std::uint64_t& uRateMax);
RippleCalc (LedgerEntrySet& lesNodes, const bool bOpenLedger)
: lesActive (lesNodes), mOpenLedger (bOpenLedger)
RippleCalc (LedgerEntrySet& activeLedger, const bool bOpenLedger)
: mActiveLedger (activeLedger), mOpenLedger (bOpenLedger)
{
;
}
public:
static TER rippleCalc (
LedgerEntrySet& lesActive,
STAmount& saMaxAmountAct,
STAmount& saDstAmountAct,
LedgerEntrySet& lesActive,
STAmount& saMaxAmountAct,
STAmount& saDstAmountAct,
std::vector<PathState::pointer>& vpsExpanded,
const STAmount& saDstAmountReq,
const STAmount& saMaxAmountReq,
const uint160& uDstAccountID,
const uint160& uSrcAccountID,
const STPathSet& spsPaths,
const bool bPartialPayment,
const bool bLimitQuality,
const bool bNoRippleDirect,
const bool bStandAlone, // --> True, not to affect accounts.
const bool bOpenLedger = true // --> What kind of errors to return.
const STAmount& saDstAmountReq,
const STAmount& saMaxAmountReq,
const uint160& uDstAccountID,
const uint160& uSrcAccountID,
const STPathSet& spsPaths,
const bool bPartialPayment,
const bool bLimitQuality,
const bool bNoRippleDirect,
// --> True, not to affect accounts.
const bool bStandAlone,
// --> What kind of errors to return.
const bool bOpenLedger = true
);
static void setCanonical (STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded, bool bKeepDefault);
static void setCanonical (
STPathSet& spsDst, const std::vector<PathState::pointer>& vpsExpanded,
bool bKeepDefault);
protected:
LedgerEntrySet& lesActive;
bool mOpenLedger;
private:
LedgerEntrySet& mActiveLedger;
bool mOpenLedger;
};
} // ripple

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SYNC_UNORDERED_MAP_H
#define RIPPLE_SYNC_UNORDERED_MAP_H
#include "../../ripple/common/UnorderedMap.h"
#include "../../ripple/common/UnorderedContainers.h"
namespace ripple {