Cleanups.

This commit is contained in:
JoelKatz
2012-05-17 23:54:09 -07:00
parent a2613dd785
commit 45b230c06b
3 changed files with 34 additions and 24 deletions

View File

@@ -12,7 +12,7 @@
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();
mTNByID[*root] = root;
}
@@ -88,6 +88,7 @@ SHAMapTreeNode::pointer SHAMap::checkCacheNode(const SHAMapNode& iNode)
SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
{ // walk down to the terminal node for this ID
SHAMapTreeNode::pointer inNode = root;
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
#ifdef ST_DEBUG
std::cerr << "aGI leaf " << node->getString() << std::endl;
std::cerr << "Existing: " << node->peekItem()->getTag().GetHex() << std::endl;
#endif
SHAMapItem::pointer otherItem = node->peekItem();
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())))
{ // we need a new inner node, since both go on same branch at this level
#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
SHAMapTreeNode::pointer newNode =
boost::make_shared<SHAMapTreeNode>(node->getChildNodeID(b1), mSeq);
boost::make_shared<SHAMapTreeNode>(mSeq, node->getChildNodeID(b1));
newNode->makeInner();
if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second)
assert(false);

View File

@@ -153,7 +153,7 @@ private:
SHAMapTreeNode& operator=(const SHAMapTreeNode&); // no implementation
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 SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);

View File

@@ -134,6 +134,7 @@ int SHAMapNode::selectBranch(const uint256& hash) const
assert(false);
return -1;
}
if ((hash & smMasks[mDepth]) != mNodeID)
{
std::cerr << "selectBranch(" << getString() << std::endl;
@@ -155,13 +156,13 @@ void SHAMapNode::dump() const
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)
{
}
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)
mItem = boost::make_shared<SHAMapItem>(*node.mItem);
@@ -342,13 +343,19 @@ std::string SHAMapTreeNode::getString() const
for(int i = 0; i < 16; ++i)
if (!isEmptyBranch(i))
{
ret += ",b";
ret += "\nb";
ret += boost::lexical_cast<std::string>(i);
ret += " = ";
ret += mHashes[i].GetHex();
}
}
if (isLeaf())
{
ret += ",leaf";
ret += ",leaf\n";
ret += " Tag=";
ret += getTag().GetHex();
ret += "\n Hash=";
ret += mHash.GetHex();
}
return ret;
}