mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Need a 'walkTo' function. That walks as far as possible to tree
position.
This commit is contained in:
23
SHAMap.cpp
23
SHAMap.cpp
@@ -118,6 +118,29 @@ SHAMapLeafNode::pointer SHAMap::walkToLeaf(const uint256& id, bool create, bool
|
|||||||
return returnLeaf(ln, modify);
|
return returnLeaf(ln, modify);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SHAMapInnerNode::pointer SHAMap::walkTo(const SHAMapNode& id)
|
||||||
|
{ // walk down to this ID, as far as possible
|
||||||
|
SHAMapInnerNode::pointer inNode=root;
|
||||||
|
int i=0;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
int branch=inNode->selectBranch(id.getNodeID());
|
||||||
|
if(branch<0) // somehow we got on the wrong branch
|
||||||
|
throw SHAMapException(InvalidNode);
|
||||||
|
if (inNode->isEmptyBranch(branch)) // we know no branches below this one
|
||||||
|
return inNode;
|
||||||
|
if(!inNode->isChildLeaf()) // this is the last inner node
|
||||||
|
return inNode;
|
||||||
|
|
||||||
|
SHAMapInnerNode::pointer next=getInner(inNode->getChildNodeID(branch), inNode->getChildHash(branch), false);
|
||||||
|
if(!next) // we don't have the next node
|
||||||
|
return inNode;
|
||||||
|
assert(next->getDepth() == (inNode->getDepth()+1));
|
||||||
|
inNode=next;
|
||||||
|
assert(i++ < SHAMapNode::leafDepth);
|
||||||
|
} while(1);
|
||||||
|
}
|
||||||
|
|
||||||
SHAMapLeafNode::pointer SHAMap::getLeaf(const SHAMapNode& id, const uint256& hash, bool modify)
|
SHAMapLeafNode::pointer SHAMap::getLeaf(const SHAMapNode& id, const uint256& hash, bool modify)
|
||||||
{ // retrieve a leaf whose node hash is known
|
{ // retrieve a leaf whose node hash is known
|
||||||
assert(!!hash);
|
assert(!!hash);
|
||||||
|
|||||||
2
SHAMap.h
2
SHAMap.h
@@ -234,6 +234,7 @@ protected:
|
|||||||
SHAMapLeafNode::pointer returnLeaf(SHAMapLeafNode::pointer leaf, bool modify);
|
SHAMapLeafNode::pointer returnLeaf(SHAMapLeafNode::pointer leaf, bool modify);
|
||||||
SHAMapInnerNode::pointer getInner(const SHAMapNode& id, const uint256& hash, bool modify);
|
SHAMapInnerNode::pointer getInner(const SHAMapNode& id, const uint256& hash, bool modify);
|
||||||
SHAMapInnerNode::pointer returnNode(SHAMapInnerNode::pointer node, bool modify);
|
SHAMapInnerNode::pointer returnNode(SHAMapInnerNode::pointer node, bool modify);
|
||||||
|
SHAMapInnerNode::pointer walkTo(const SHAMapNode& id);
|
||||||
|
|
||||||
SHAMapItem::pointer firstBelow(SHAMapInnerNode::pointer);
|
SHAMapItem::pointer firstBelow(SHAMapInnerNode::pointer);
|
||||||
SHAMapItem::pointer lastBelow(SHAMapInnerNode::pointer);
|
SHAMapItem::pointer lastBelow(SHAMapInnerNode::pointer);
|
||||||
@@ -289,6 +290,7 @@ public:
|
|||||||
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max);
|
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max);
|
||||||
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
|
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
|
||||||
std::list<std::vector<unsigned char> >& rawNode);
|
std::list<std::vector<unsigned char> >& rawNode);
|
||||||
|
bool addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode);
|
||||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode);
|
||||||
|
|
||||||
// caution: otherMap must be accessed only by this function
|
// caution: otherMap must be accessed only by this function
|
||||||
|
|||||||
Reference in New Issue
Block a user