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)
|
||||
{
|
||||
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())
|
||||
@@ -323,10 +324,10 @@ SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
else for(int i=node->selectBranch(id)-1; i>=0; i--)
|
||||
if(!node->isEmptyBranch(i))
|
||||
{
|
||||
node=getNode(node->getChildNodeID(i), node->getChildHash(i), false);
|
||||
node = getNode(node->getChildNodeID(i), node->getChildHash(i), false);
|
||||
if(!node) throw SHAMapException(MissingNode);
|
||||
SHAMapItem::pointer item=firstBelow(node);
|
||||
if(!item) throw SHAMapException(MissingNode);
|
||||
SHAMapItem::pointer item = firstBelow(node);
|
||||
if (!item) throw SHAMapException(MissingNode);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -337,8 +338,8 @@ SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
SHAMapItem::pointer SHAMap::peekItem(const uint256& id)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode::pointer leaf=walkTo(id, false);
|
||||
if(!leaf) return SHAMapItem::pointer();
|
||||
SHAMapTreeNode::pointer leaf = walkTo(id, false);
|
||||
if (!leaf) return SHAMapItem::pointer();
|
||||
return leaf->peekItem();
|
||||
}
|
||||
|
||||
@@ -433,7 +434,7 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
|
||||
std::stack<SHAMapTreeNode::pointer> stack = getStack(tag, true);
|
||||
if (stack.empty()) throw SHAMapException(MissingNode);
|
||||
|
||||
SHAMapTreeNode::pointer node=stack.top();
|
||||
SHAMapTreeNode::pointer node = stack.top();
|
||||
stack.pop();
|
||||
|
||||
if (node->isLeaf() && (node->peekItem()->getTag() == tag))
|
||||
@@ -464,9 +465,10 @@ 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()) );
|
||||
assert(otherItem && (tag != otherItem->getTag()));
|
||||
|
||||
node->makeInner();
|
||||
|
||||
@@ -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);
|
||||
@@ -607,8 +610,8 @@ void SHAMap::dump(bool hash)
|
||||
|
||||
std::cerr << " MAP Contains" << std::endl;
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
for(boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer, hash_SMN>::iterator it=mTNByID.begin();
|
||||
it!=mTNByID.end(); ++it)
|
||||
for(boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer, hash_SMN>::iterator it = mTNByID.begin();
|
||||
it != mTNByID.end(); ++it)
|
||||
{
|
||||
std::cerr << it->second->getString() << std::endl;
|
||||
if(hash) std::cerr << " " << it->second->getNodeHash().GetHex() << std::endl;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -74,18 +74,18 @@ bool SHAMapNode::operator!=(const uint256 &s) const
|
||||
void SHAMapNode::ClassInit()
|
||||
{ // set up the depth masks
|
||||
uint256 selector;
|
||||
for(int i=0; i<64; i+=2)
|
||||
for(int i = 0; i < 64; i += 2)
|
||||
{
|
||||
smMasks[i]=selector;
|
||||
*(selector.begin()+(i/2))=0x0F;
|
||||
smMasks[i+1]=selector;
|
||||
*(selector.begin()+(i/2))=0xFF;
|
||||
smMasks[i] = selector;
|
||||
*(selector.begin() + (i / 2)) = 0x0F;
|
||||
smMasks[i + 1]=selector;
|
||||
*(selector.begin() + (i / 2)) = 0xFF;
|
||||
}
|
||||
}
|
||||
|
||||
uint256 SHAMapNode::getNodeID(int depth, const uint256& hash)
|
||||
{
|
||||
assert(depth>=0 && depth<64);
|
||||
assert(depth >= 0 && depth < 64);
|
||||
return hash & smMasks[depth];
|
||||
}
|
||||
|
||||
@@ -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,15 +156,15 @@ 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)
|
||||
if (node.mItem)
|
||||
mItem = boost::make_shared<SHAMapItem>(*node.mItem);
|
||||
else
|
||||
memcpy(mHashes, node.mHashes, sizeof(mHashes));
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user