#include "BitcoinUtil.h" #include "SHAMap.h" #include bool SHAMapNode::operator<(const SHAMapNode &s) const { if(s.mDepthmDepth) return false; return mNodeID(const SHAMapNode &s) const { if(s.mDepthmDepth) return true; return mNodeID>s.mNodeID; } bool SHAMapNode::operator<=(const SHAMapNode &s) const { if(s.mDepthmDepth) return false; return mNodeID<=s.mNodeID; } bool SHAMapNode::operator>=(const SHAMapNode &s) const { if(s.mDepthmDepth) return true; return mNodeID>=s.mNodeID; } bool SHAMapNode::operator==(const SHAMapNode &s) const { return (s.mDepth==mDepth) && (s.mNodeID==mNodeID); } bool SHAMapNode::operator!=(const SHAMapNode &s) const { return (s.mDepth!=mDepth) || (s.mNodeID!=mNodeID); } void SHAMapNode::ClassInit() { int i; char HexBuf[65]; for(i=0; i<64; i++) HexBuf[i]='0'; HexBuf[64]=0; for(i=0; i=0 && depth>=(mDepth*8); return SHAMapNode(mDepth+1, mNodeID | branch); } int SHAMapNode::selectBranch(const uint256 &hash) { if(isLeaf()) // no nodes under this node return -1; if((hash&smMasks[mDepth])!=mNodeID) return -1; // does not go under this node uint256 selector=hash&smMasks[mDepth+1]; int branch=*(selector.begin()+mDepth); assert(branch>=0 && branch<32); return branch; } SHAMapLeafNode::SHAMapLeafNode(const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0) { ; } void SHAMapLeafNode::updateHash(void) { } bool SHAMapLeafNode::hasHash(const uint256& hash) const { BOOST_FOREACH(const uint256& entry, mHashes) if(entry==hash) return true; return false; } bool SHAMapLeafNode::addHash(const uint256& hash) { // The node will almost never have more than one hash in it std::list::iterator it; for(it=mHashes.begin(); it!=mHashes.end(); it++) { if(*it==hash) return false; if(*it>hash) break; } mHashes.insert(it, hash); updateHash(); return true; } bool SHAMapLeafNode::delHash(const uint256& hash) { std::list::iterator it; for(it=mHashes.begin(); it!=mHashes.end(); it++) { if(*it==hash) { mHashes.erase(it); updateHash(); return true; } } return false; }