From 6d36aed7df3f0fe5eb98dececcf9990a67a9a949 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 14 Aug 2013 02:30:46 -0700 Subject: [PATCH] getNodePointer function for when you only know the node ID. --- modules/ripple_app/shamap/ripple_SHAMap.cpp | 28 +++++++++++++++++++++ modules/ripple_app/shamap/ripple_SHAMap.h | 1 + 2 files changed, 29 insertions(+) diff --git a/modules/ripple_app/shamap/ripple_SHAMap.cpp b/modules/ripple_app/shamap/ripple_SHAMap.cpp index 69023b627..62dd15ea7 100644 --- a/modules/ripple_app/shamap/ripple_SHAMap.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMap.cpp @@ -985,6 +985,34 @@ SHAMapTreeNode::pointer SHAMap::getNode (const SHAMapNode& nodeID) return node; } +// This function returns NULL if no node with that ID exists in the map +// It throws if the map is incomplete +SHAMapTreeNode* SHAMap::getNodePointer (const SHAMapNode& nodeID) +{ + boost::unordered_map::iterator it = mTNByID.find (nodeID); + if (it != mTNByID.end()) + { + it->second->touch(mSeq); + return it->second.get(); + } + + SHAMapTreeNode* node = root.get(); + + while (nodeID != *node) + { + int branch = node->selectBranch (nodeID.getNodeID ()); + assert (branch >= 0); + + if ((branch < 0) || node->isEmptyBranch (branch)) + return NULL; + + node = getNodePointer (node->getChildNodeID (branch), node->getChildHash (branch)); + assert (node); + } + + return node; +} + bool SHAMap::getPath (uint256 const& index, std::vector< Blob >& nodes, SHANodeFormat format) { // Return the path of nodes to the specified index in the specified format diff --git a/modules/ripple_app/shamap/ripple_SHAMap.h b/modules/ripple_app/shamap/ripple_SHAMap.h index b195dd4f2..8a417b2b4 100644 --- a/modules/ripple_app/shamap/ripple_SHAMap.h +++ b/modules/ripple_app/shamap/ripple_SHAMap.h @@ -202,6 +202,7 @@ private: SHAMapTreeNode::pointer getNode (const SHAMapNode & id); SHAMapTreeNode::pointer getNode (const SHAMapNode & id, uint256 const & hash, bool modify); + SHAMapTreeNode* getNodePointer (const SHAMapNode & id); SHAMapTreeNode* getNodePointer (const SHAMapNode & id, uint256 const & hash); SHAMapTreeNode* getNodePointerNT (const SHAMapNode & id, uint256 const & hash); SHAMapTreeNode* getNodePointer (const SHAMapNode & id, uint256 const & hash, SHAMapSyncFilter * filter);