From 01f5740add44d097242e2e5365274cf31d8de2ad Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 25 Nov 2011 13:52:04 -0800 Subject: [PATCH] Endian fix. SHAMap now passes its (admittedly anemic right now) unit test. --- SHAMapNodes.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/SHAMapNodes.cpp b/SHAMapNodes.cpp index 1b0130183..aff4759da 100644 --- a/SHAMapNodes.cpp +++ b/SHAMapNodes.cpp @@ -15,7 +15,7 @@ std::string SHAMapNode::getString() const return ret; } -uint256 SHAMapNode::smMasks[11]; +uint256 SHAMapNode::smMasks[21]; bool SHAMapNode::operator<(const SHAMapNode &s) const { @@ -57,16 +57,11 @@ bool SHAMapNode::operator!=(const SHAMapNode &s) const void SHAMapNode::ClassInit() { // set up the depth masks - int i; - char HexBuf[65]; - - for(i=0; i<64; i++) HexBuf[i]='0'; - HexBuf[64]=0; - for(i=0; i<=leafDepth; i++) + uint256 selector; + for(int i=0; i<=leafDepth; i++) { - smMasks[i].SetHex(HexBuf); - HexBuf[2*i]='1'; - HexBuf[2*i+1]='F'; + smMasks[i]=selector; + *(selector.begin()+i)=0x1f; } } @@ -88,7 +83,11 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) assert(!isLeaf()); uint256 branch=m; - branch>>=(mDepth*8); + branch<<=248-(mDepth*8); + +#ifdef DEBUG + std::cerr << "m=" << m << ", branch=" << branch.GetHex() << std::endl; +#endif return SHAMapNode(mDepth+1, mNodeID | branch); }