getNodePointer function for when you only know the node ID.

This commit is contained in:
JoelKatz
2013-08-14 02:30:46 -07:00
parent 5a81b0a4a8
commit 6d36aed7df
2 changed files with 29 additions and 0 deletions

View File

@@ -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<SHAMapNode, SHAMapTreeNode::pointer>::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

View File

@@ -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);