From 4ad353203789c1d057fa0f62e4c02a5821fbe64f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 18:13:59 -0700 Subject: [PATCH] Cosmetic changes. --- src/SHAMap.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index a307d2943..9c2eea361 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -430,16 +430,13 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) boost::recursive_mutex::scoped_lock sl(mLock); std::stack stack=getStack(tag, true); - if(stack.empty()) throw SHAMapException(MissingNode); + if (stack.empty()) throw SHAMapException(MissingNode); SHAMapTreeNode::pointer node=stack.top(); stack.pop(); - if( node->isLeaf() && (node->peekItem()->getTag()==tag) ) - { - std::cerr << "addGiveItem ends on leaf with same tag" << std::endl; - return false; - } + if (node->isLeaf() && (node->peekItem()->getTag() == tag)) + throw std::runtime_error("addGiveItem ends on leaf with same tag"); uint256 prevHash; returnNode(node, true); @@ -449,9 +446,9 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) #ifdef ST_DEBUG std::cerr << "aGI inner " << node->getString() << std::endl; #endif - int branch=node->selectBranch(tag); + int branch = node->selectBranch(tag); assert(node->isEmptyBranch(branch)); - SHAMapTreeNode::pointer newNode= + SHAMapTreeNode::pointer newNode = boost::make_shared(node->getChildNodeID(branch), item, type, mSeq); if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) { @@ -467,14 +464,14 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) #ifdef ST_DEBUG std::cerr << "aGI leaf " << node->getString() << std::endl; #endif - SHAMapItem::pointer otherItem=node->peekItem(); - assert(otherItem && (tag!=otherItem->getTag()) ); + SHAMapItem::pointer otherItem = node->peekItem(); + assert(otherItem && (tag != otherItem->getTag()) ); node->makeInner(); int b1, b2; - while( (b1=node->selectBranch(tag)) == (b2=node->selectBranch(otherItem->getTag())) ) + while ((b1 = node->selectBranch(tag)) == (b2 = node->selectBranch(otherItem->getTag()))) { // we need a new inner node, since both go on same branch at this level #ifdef ST_DEBUG std::cerr << "need new inner node at " << node->getDepth() << std::endl; @@ -484,26 +481,26 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); stack.push(node); - node=newNode; + node = newNode; } // we can add the two leaf nodes here assert(node->isInner()); - SHAMapTreeNode::pointer newNode= + SHAMapTreeNode::pointer newNode = boost::make_shared(node->getChildNodeID(b1), item, type, mSeq); assert(newNode->isValid() && newNode->isLeaf()); - if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) + if (!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); node->setChildHash(b1, newNode->getNodeHash()); // OPTIMIZEME hash op not needed - newNode=boost::make_shared(node->getChildNodeID(b2), otherItem, type, mSeq); + newNode = boost::make_shared(node->getChildNodeID(b2), otherItem, type, mSeq); assert(newNode->isValid() && newNode->isLeaf()); if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); node->setChildHash(b2, newNode->getNodeHash()); } - prevHash=node->getNodeHash(); + prevHash = node->getNodeHash(); assert(prevHash.isNonZero()); dirtyUp(stack, tag, prevHash); return true; @@ -534,7 +531,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction) returnNode(node, true); if (!node->setItem(item, isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE)) - return true; + return false; dirtyUp(stack, tag, node->getNodeHash()); return true;