From 9f8c1bdc7ab9062a58e525c1b55c2ff6581a30f1 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Mon, 3 Sep 2012 03:15:42 -0700 Subject: [PATCH] Cleanups. --- src/SHAMap.cpp | 22 +++++++++++----------- src/SHAMap.h | 2 ++ src/SHAMapSync.cpp | 8 ++++---- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 046abe75c7..8ae69c405e 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -187,7 +187,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has if (node->getNodeHash() != hash) { std::cerr << "Attempt to get node, hash not in tree" << std::endl; - std::cerr << "ID: " << id.getString() << std::endl; + std::cerr << "ID: " << id << std::endl; std::cerr << "TgtHash " << hash << std::endl; std::cerr << "NodHash " << node->getNodeHash() << std::endl; dump(); @@ -242,7 +242,7 @@ SHAMapItem::pointer SHAMap::firstBelow(SHAMapTreeNode* node) { // Return the first item below this node #ifdef ST_DEBUG - std::cerr << "firstBelow(" << node->getString() << ")" << std::endl; + std::cerr << "firstBelow(" << *node << ")" << std::endl; #endif do { // Walk down the tree @@ -253,9 +253,9 @@ SHAMapItem::pointer SHAMap::firstBelow(SHAMapTreeNode* node) if (!node->isEmptyBranch(i)) { #ifdef ST_DEBUG - std::cerr << " FB: node " << node->getString() << std::endl; + std::cerr << " FB: node " << *node << std::endl; std::cerr << " has non-empty branch " << i << " : " << - node->getChildNodeID(i).getString() << ", " << node->getChildHash(i) << std::endl; + node->getChildNodeID(i) << ", " << node->getChildHash(i) << std::endl; #endif node = getNodePointer(node->getChildNodeID(i), node->getChildHash(i)); foundNode = true; @@ -268,7 +268,7 @@ SHAMapItem::pointer SHAMap::firstBelow(SHAMapTreeNode* node) SHAMapItem::pointer SHAMap::lastBelow(SHAMapTreeNode* node) { #ifdef DEBUG - std::cerr << "lastBelow(" << node->getString() << ")" << std::endl; + std::cerr << "lastBelow(" << *node << ")" << std::endl; #endif do @@ -306,7 +306,7 @@ SHAMapItem::pointer SHAMap::onlyBelow(SHAMapTreeNode* node) if (!found) { - std::cerr << node->getString() << std::endl; + std::cerr << *node << std::endl; assert(false); return SHAMapItem::pointer(); } @@ -480,7 +480,7 @@ bool SHAMap::delItem(const uint256& id) { eraseChildren(node); #ifdef ST_DEBUG - std::cerr << "Making item node " << node->getString() << std::endl; + std::cerr << "Making item node " << *node << std::endl; #endif node->setItem(item, type); } @@ -527,7 +527,7 @@ bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bo if (node->isInner()) { // easy case, we end on an inner node #ifdef ST_DEBUG - std::cerr << "aGI inner " << node->getString() << std::endl; + std::cerr << "aGI inner " << *node << std::endl; #endif int branch = node->selectBranch(tag); assert(node->isEmptyBranch(branch)); @@ -535,8 +535,8 @@ bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bo boost::make_shared(node->getChildNodeID(branch), item, type, mSeq); if (!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) { - std::cerr << "Node: " << node->getString() << std::endl; - std::cerr << "NewNode: " << newNode->getString() << std::endl; + std::cerr << "Node: " << *node << std::endl; + std::cerr << "NewNode: " << *newNode << std::endl; dump(); assert(false); throw std::runtime_error("invalid inner node"); @@ -546,7 +546,7 @@ bool SHAMap::addGiveItem(const SHAMapItem::pointer& item, bool isTransaction, bo else { // this is a leaf node that has to be made an inner node holding two items #ifdef ST_DEBUG - std::cerr << "aGI leaf " << node->getString() << std::endl; + std::cerr << "aGI leaf " << *node << std::endl; std::cerr << "Existing: " << node->peekItem()->getTag() << std::endl; #endif SHAMapItem::pointer otherItem = node->peekItem(); diff --git a/src/SHAMap.h b/src/SHAMap.h index 2e5c0ccbc8..b84dcb7272 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -78,6 +78,8 @@ public: extern std::size_t hash_value(const SHAMapNode& mn); +inline std::ostream& operator<<(std::ostream& out, const SHAMapNode& node) { return out << node.getString(); } + class SHAMapItem { // an item stored in a SHAMap public: diff --git a/src/SHAMapSync.cpp b/src/SHAMapSync.cpp index ee3bb0e1d5..5ae0af44c5 100644 --- a/src/SHAMapSync.cpp +++ b/src/SHAMapSync.cpp @@ -66,7 +66,7 @@ void SHAMap::getMissingNodes(std::vector& nodeIDs, std::vectorgetString(); + Log(lsTRACE) << "Got sync node from cache: " << *d; mTNByID[*d] = d; } } @@ -222,8 +222,8 @@ bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vectorgetDepth() != (node.getDepth() - 1)) { // Either this node is broken or we didn't request it (yet) - Log(lsINFO) << "unable to hook node " << node.getString(); - Log(lsINFO) << " stuck at " << iNode->getString(); + Log(lsINFO) << "unable to hook node " << node; + Log(lsINFO) << " stuck at " << *iNode; Log(lsINFO) << "got depth=" << node.getDepth() << ", walked to= " << iNode->getDepth(); return false; } @@ -304,7 +304,7 @@ bool SHAMap::deepCompare(SHAMap& other) return false; } -// Log(lsTRACE) << "Comparing inner nodes " << node->getString(); +// Log(lsTRACE) << "Comparing inner nodes " << *node; if (node->getNodeHash() != otherNode->getNodeHash()) return false;