mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanups.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying)
|
SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(Modifying)
|
||||||
{
|
{
|
||||||
root = boost::make_shared<SHAMapTreeNode>(SHAMapNode(0, uint256()), mSeq);
|
root = boost::make_shared<SHAMapTreeNode>(mSeq, SHAMapNode(0, uint256()));
|
||||||
root->makeInner();
|
root->makeInner();
|
||||||
mTNByID[*root] = root;
|
mTNByID[*root] = root;
|
||||||
}
|
}
|
||||||
@@ -88,6 +88,7 @@ SHAMapTreeNode::pointer SHAMap::checkCacheNode(const SHAMapNode& iNode)
|
|||||||
|
|
||||||
SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
|
SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
|
||||||
{ // walk down to the terminal node for this ID
|
{ // walk down to the terminal node for this ID
|
||||||
|
|
||||||
SHAMapTreeNode::pointer inNode = root;
|
SHAMapTreeNode::pointer inNode = root;
|
||||||
|
|
||||||
while (!inNode->isLeaf())
|
while (!inNode->isLeaf())
|
||||||
@@ -464,6 +465,7 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
|
|||||||
{ // this is a leaf node that has to be made an inner node holding two items
|
{ // this is a leaf node that has to be made an inner node holding two items
|
||||||
#ifdef ST_DEBUG
|
#ifdef ST_DEBUG
|
||||||
std::cerr << "aGI leaf " << node->getString() << std::endl;
|
std::cerr << "aGI leaf " << node->getString() << std::endl;
|
||||||
|
std::cerr << "Existing: " << node->peekItem()->getTag().GetHex() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
SHAMapItem::pointer otherItem = node->peekItem();
|
SHAMapItem::pointer otherItem = node->peekItem();
|
||||||
assert(otherItem && (tag != otherItem->getTag()));
|
assert(otherItem && (tag != otherItem->getTag()));
|
||||||
@@ -475,10 +477,11 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
|
|||||||
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
|
{ // we need a new inner node, since both go on same branch at this level
|
||||||
#ifdef ST_DEBUG
|
#ifdef ST_DEBUG
|
||||||
std::cerr << "need new inner node at " << node->getDepth() << std::endl;
|
std::cerr << "need new inner node at " << node->getDepth() << ", "
|
||||||
|
<< b1 << "==" << b2 << std::endl;
|
||||||
#endif
|
#endif
|
||||||
SHAMapTreeNode::pointer newNode =
|
SHAMapTreeNode::pointer newNode =
|
||||||
boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), mSeq);
|
boost::make_shared<SHAMapTreeNode>(mSeq, node->getChildNodeID(b1));
|
||||||
newNode->makeInner();
|
newNode->makeInner();
|
||||||
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
|
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ private:
|
|||||||
SHAMapTreeNode& operator=(const SHAMapTreeNode&); // no implementation
|
SHAMapTreeNode& operator=(const SHAMapTreeNode&); // no implementation
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHAMapTreeNode(const SHAMapNode& nodeID, uint32 seq); // empty node
|
SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID); // empty node
|
||||||
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
||||||
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);
|
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ int SHAMapNode::selectBranch(const uint256& hash) const
|
|||||||
assert(false);
|
assert(false);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((hash & smMasks[mDepth]) != mNodeID)
|
if ((hash & smMasks[mDepth]) != mNodeID)
|
||||||
{
|
{
|
||||||
std::cerr << "selectBranch(" << getString() << std::endl;
|
std::cerr << "selectBranch(" << getString() << std::endl;
|
||||||
@@ -155,13 +156,13 @@ void SHAMapNode::dump() const
|
|||||||
std::cerr << getString() << std::endl;
|
std::cerr << getString() << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& nodeID, uint32 seq) : SHAMapNode(nodeID), mHash(0), mSeq(seq),
|
SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0), mSeq(seq),
|
||||||
mType(tnERROR), mFullBelow(false)
|
mType(tnERROR), mFullBelow(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapNode(node),
|
SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapNode(node),
|
||||||
mHash(node.mHash), mItem(node.mItem), mSeq(seq), mType(node.mType), mFullBelow(false)
|
mHash(node.mHash), mSeq(seq), mType(node.mType), mFullBelow(false)
|
||||||
{
|
{
|
||||||
if (node.mItem)
|
if (node.mItem)
|
||||||
mItem = boost::make_shared<SHAMapItem>(*node.mItem);
|
mItem = boost::make_shared<SHAMapItem>(*node.mItem);
|
||||||
@@ -342,13 +343,19 @@ std::string SHAMapTreeNode::getString() const
|
|||||||
for(int i = 0; i < 16; ++i)
|
for(int i = 0; i < 16; ++i)
|
||||||
if (!isEmptyBranch(i))
|
if (!isEmptyBranch(i))
|
||||||
{
|
{
|
||||||
ret += ",b";
|
ret += "\nb";
|
||||||
ret += boost::lexical_cast<std::string>(i);
|
ret += boost::lexical_cast<std::string>(i);
|
||||||
|
ret += " = ";
|
||||||
|
ret += mHashes[i].GetHex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isLeaf())
|
if (isLeaf())
|
||||||
{
|
{
|
||||||
ret += ",leaf";
|
ret += ",leaf\n";
|
||||||
|
ret += " Tag=";
|
||||||
|
ret += getTag().GetHex();
|
||||||
|
ret += "\n Hash=";
|
||||||
|
ret += mHash.GetHex();
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user