mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add SHAMap::iterator
This commit is contained in:
committed by
Nik Bougalis
parent
eb709f415b
commit
c53b9f3713
@@ -33,13 +33,11 @@ TaggedCache <uint256, AcceptedLedger> AcceptedLedger::s_cache (
|
|||||||
|
|
||||||
AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger)
|
AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger)
|
||||||
{
|
{
|
||||||
SHAMap& txSet = *ledger->peekTransactionMap ();
|
for (auto const& item : *ledger->peekTransactionMap())
|
||||||
|
|
||||||
for (std::shared_ptr<SHAMapItem> item = txSet.peekFirstItem (); item;
|
|
||||||
item = txSet.peekNextItem (item->getTag ()))
|
|
||||||
{
|
{
|
||||||
SerialIter sit (item->slice());
|
SerialIter sit (item->slice());
|
||||||
insert (std::make_shared<AcceptedLedgerTx> (ledger, std::ref (sit)));
|
insert (std::make_shared<AcceptedLedgerTx>(
|
||||||
|
ledger, std::ref (sit)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1857,8 +1857,7 @@ void applyTransactions (std::shared_ptr<SHAMap> const& set,
|
|||||||
|
|
||||||
if (set)
|
if (set)
|
||||||
{
|
{
|
||||||
for (std::shared_ptr<SHAMapItem> item = set->peekFirstItem (); !!item;
|
for (auto const item : *set)
|
||||||
item = set->peekNextItem (item->getTag ()))
|
|
||||||
{
|
{
|
||||||
// If the checkLedger doesn't have the transaction
|
// If the checkLedger doesn't have the transaction
|
||||||
if (!checkLedger->hasTransaction (item->getTag ()))
|
if (!checkLedger->hasTransaction (item->getTag ()))
|
||||||
|
|||||||
@@ -1317,16 +1317,18 @@ bool ApplicationImp::loadOldLedger (
|
|||||||
cur = std::make_shared <Ledger> (*cur, true);
|
cur = std::make_shared <Ledger> (*cur, true);
|
||||||
assert (!cur->isImmutable());
|
assert (!cur->isImmutable());
|
||||||
|
|
||||||
for (auto it = txns->peekFirstItem(); it != nullptr;
|
for (auto const& item : *txns)
|
||||||
it = txns->peekNextItem(it->getTag()))
|
|
||||||
{
|
{
|
||||||
Transaction::pointer txn = replayLedger->getTransaction(it->getTag());
|
auto const txn =
|
||||||
m_journal.info << txn->getJson(0);
|
replayLedger->getTransaction(item->getTag());
|
||||||
|
if (m_journal.info) m_journal.info <<
|
||||||
|
txn->getJson(0);
|
||||||
Serializer s;
|
Serializer s;
|
||||||
txn->getSTransaction()->add(s);
|
txn->getSTransaction()->add(s);
|
||||||
if (!cur->addTransaction(it->getTag(), s))
|
if (! cur->addTransaction(item->getTag(), s))
|
||||||
m_journal.warning << "Unable to add transaction " << it->getTag();
|
if (m_journal.warning) m_journal.warning <<
|
||||||
getApp().getHashRouter().setFlag (it->getTag(), SF_SIGGOOD);
|
"Unable to add transaction " << item->getTag();
|
||||||
|
getApp().getHashRouter().setFlag (item->getTag(), SF_SIGGOOD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch to the mutable snapshot
|
// Switch to the mutable snapshot
|
||||||
|
|||||||
@@ -33,9 +33,11 @@
|
|||||||
#include <ripple/nodestore/Database.h>
|
#include <ripple/nodestore/Database.h>
|
||||||
#include <ripple/nodestore/NodeObject.h>
|
#include <ripple/nodestore/NodeObject.h>
|
||||||
#include <beast/utility/Journal.h>
|
#include <beast/utility/Journal.h>
|
||||||
|
#include <boost/iterator/iterator_facade.hpp>
|
||||||
#include <boost/thread/mutex.hpp>
|
#include <boost/thread/mutex.hpp>
|
||||||
#include <boost/thread/shared_lock_guard.hpp>
|
#include <boost/thread/shared_lock_guard.hpp>
|
||||||
#include <boost/thread/shared_mutex.hpp>
|
#include <boost/thread/shared_mutex.hpp>
|
||||||
|
#include <cassert>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
|
|
||||||
namespace ripple {
|
namespace ripple {
|
||||||
@@ -111,6 +113,19 @@ public:
|
|||||||
Family& f,
|
Family& f,
|
||||||
beast::Journal journal);
|
beast::Journal journal);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Iterator to a SHAMap's leaves
|
||||||
|
This is always a const iterator.
|
||||||
|
Meets the requirements of ForwardRange.
|
||||||
|
*/
|
||||||
|
class iterator;
|
||||||
|
|
||||||
|
iterator begin() const;
|
||||||
|
iterator end() const;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------
|
||||||
|
|
||||||
// Returns a new map that's a snapshot of this one.
|
// Returns a new map that's a snapshot of this one.
|
||||||
// Handles copy on write for mutable snapshots.
|
// Handles copy on write for mutable snapshots.
|
||||||
std::shared_ptr<SHAMap> snapShot (bool isMutable) const;
|
std::shared_ptr<SHAMap> snapShot (bool isMutable) const;
|
||||||
@@ -335,6 +350,70 @@ SHAMap::setUnbacked ()
|
|||||||
backed_ = false;
|
backed_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class SHAMap::iterator
|
||||||
|
: public boost::iterator_facade<
|
||||||
|
SHAMap::iterator,
|
||||||
|
std::shared_ptr<SHAMapItem const> const,
|
||||||
|
std::forward_iterator_tag>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
friend class boost::iterator_core_access;
|
||||||
|
|
||||||
|
SHAMap const* map_ = nullptr;
|
||||||
|
std::shared_ptr<
|
||||||
|
SHAMapItem const> item_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
iterator() = default;
|
||||||
|
iterator (iterator const&) = default;
|
||||||
|
iterator& operator= (iterator const&) = default;
|
||||||
|
|
||||||
|
iterator (SHAMap const& map,
|
||||||
|
std::shared_ptr<SHAMapItem const> const& item)
|
||||||
|
: map_(&map)
|
||||||
|
, item_(item)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void
|
||||||
|
increment()
|
||||||
|
{
|
||||||
|
item_ = map_->peekNextItem(
|
||||||
|
item_->key());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
equal (iterator const& other) const
|
||||||
|
{
|
||||||
|
assert(map_ == other.map_);
|
||||||
|
return item_ == other.item_;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<
|
||||||
|
SHAMapItem const> const&
|
||||||
|
dereference() const
|
||||||
|
{
|
||||||
|
return item_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
inline
|
||||||
|
SHAMap::iterator
|
||||||
|
SHAMap::begin() const
|
||||||
|
{
|
||||||
|
return iterator(*this, peekFirstItem());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
SHAMap::iterator
|
||||||
|
SHAMap::end() const
|
||||||
|
{
|
||||||
|
return iterator(*this, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user