Skip to content

Commit

Permalink
[FOLD] Fixes:
Browse files Browse the repository at this point in the history
* Fix build error on clang
* Fix issue Nik caught
* Take suggestions from code review
  • Loading branch information
JoelKatz committed Sep 4, 2014
1 parent dfc0dea commit 0b7dc95
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
29 changes: 14 additions & 15 deletions src/ripple/module/app/shamap/SHAMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ SHAMap::pointer SHAMap::snapShot (bool isMutable)
return ret;
}

std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>>
SHAMap::SharedPtrNodeStack
SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf)
{
// Walk the tree as far as possible to the specified identifier
// produce a stack of nodes along the way, with the terminal node at the top
std::stack <std::pair <SHAMapTreeNode::pointer, SHAMapNodeID> > stack;
SharedPtrNodeStack stack;

SHAMapTreeNode::pointer node = root;
SHAMapNodeID nodeID;
Expand All @@ -147,7 +147,7 @@ SHAMap::getStack (uint256 const& id, bool include_nonmatching_leaf)
}

void
SHAMap::dirtyUp (std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>>& stack,
SHAMap::dirtyUp (SharedPtrNodeStack& stack,
uint256 const& target, SHAMapTreeNode::pointer child)
{
// walk the tree up from through the inner nodes to the root
Expand Down Expand Up @@ -522,7 +522,7 @@ SHAMap::onlyBelow (SHAMapTreeNode* node)
if (!node->isEmptyBranch (i))
{
if (nextNode)
return false;
return SHAMap::pointer ();

nextNode = descendThrow (node, i);
}
Expand Down Expand Up @@ -587,8 +587,8 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT
{
// Get a pointer to the next item in the tree after a given item - item need not be in tree

std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>> stack =
getStack (id, true);
auto stack = getStack (id, true);

while (!stack.empty ())
{
SHAMapTreeNode* node = stack.top().first.get();
Expand Down Expand Up @@ -628,8 +628,8 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT
// Get a pointer to the previous item in the tree after a given item - item need not be in tree
SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id)
{
std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>> stack =
getStack (id, true);
auto stack = getStack (id, true);

while (!stack.empty ())
{
SHAMapTreeNode* node = stack.top ().first.get();
Expand Down Expand Up @@ -704,8 +704,7 @@ bool SHAMap::delItem (uint256 const& id)
// delete the item with this ID
assert (mState != smsImmutable);

std::stack <std::pair <SHAMapTreeNode::pointer, SHAMapNodeID>> stack =
getStack (id, true);
auto stack = getStack (id, true);

if (stack.empty ())
throw (std::runtime_error ("missing node"));
Expand Down Expand Up @@ -758,7 +757,7 @@ bool SHAMap::delItem (uint256 const& id)

if (item)
{
for (int i = 0; i > 16; ++i)
for (int i = 0; i < 16; ++i)
{
if (!node->isEmptyBranch (i))
{
Expand Down Expand Up @@ -798,8 +797,8 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta

assert (mState != smsImmutable);

std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>> stack =
getStack (tag, true);
auto stack = getStack (tag, true);

if (stack.empty ())
throw (std::runtime_error ("missing node"));

Expand Down Expand Up @@ -879,8 +878,8 @@ bool SHAMap::updateGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasM

assert (mState != smsImmutable);

std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>> stack =
getStack (tag, true);
auto stack = getStack (tag, true);

if (stack.empty ())
throw (std::runtime_error ("missing node"));

Expand Down
7 changes: 5 additions & 2 deletions src/ripple/module/app/shamap/SHAMap.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Expand Down Expand Up @@ -115,6 +116,8 @@ class SHAMap
typedef std::map<uint256, DeltaItem> Delta;
typedef hash_map<SHAMapNodeID, SHAMapTreeNode::pointer, SHAMapNode_hash> NodeMap;

typedef std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>> SharedPtrNodeStack;

public:
// build new map
SHAMap (
Expand Down Expand Up @@ -254,11 +257,11 @@ class SHAMap
SHAMapTreeNode::pointer fetchNode (uint256 const& hash);

/** Update hashes up to the root */
void dirtyUp (std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>>& stack,
void dirtyUp (SharedPtrNodeStack& stack,
uint256 const& target, SHAMapTreeNode::pointer terminal);

/** Get the path from the root to the specified node */
std::stack<std::pair<SHAMapTreeNode::pointer, SHAMapNodeID>>
SharedPtrNodeStack
getStack (uint256 const& id, bool include_nonmatching_leaf);

/** Walk to the specified index, returning the node */
Expand Down
1 change: 0 additions & 1 deletion src/ripple/module/app/shamap/SHAMapTreeNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ std::mutex SHAMapTreeNode::childLock;

SHAMapTreeNode::SHAMapTreeNode (std::uint32_t seq)
: mSeq (seq)
, mAccessSeq (seq)
, mType (tnERROR)
, mIsBranch (0)
, mFullBelow (false)
Expand Down
9 changes: 2 additions & 7 deletions src/ripple/module/app/shamap/SHAMapTreeNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,7 @@ class SHAMapTreeNode
}
void setSeq (std::uint32_t s)
{
mAccessSeq = mSeq = s;
}
void touch (std::uint32_t s)
{
if (mSeq != 0)
mAccessSeq = s;
mSeq = s;
}
uint256 const& getNodeHash () const
{
Expand Down Expand Up @@ -196,7 +191,7 @@ class SHAMapTreeNode
uint256 mHashes[16];
SHAMapTreeNode::pointer mChildren[16];
SHAMapItem::pointer mItem;
std::uint32_t mSeq, mAccessSeq;
std::uint32_t mSeq;
TNType mType;
int mIsBranch;
bool mFullBelow;
Expand Down

0 comments on commit 0b7dc95

Please sign in to comment.