From bb5f70cd7391c562cfdc340b8201533a485b4dcb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 7 Feb 2012 19:48:10 -0800 Subject: [PATCH] Cleanups and optimizations. --- SHAMap.h | 4 ++-- SHAMapNodes.cpp | 7 +++---- uint256.h | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/SHAMap.h b/SHAMap.h index 37ae4ecd5f..38ba597b6e 100644 --- a/SHAMap.h +++ b/SHAMap.h @@ -72,9 +72,9 @@ class hash_SMN { // These must be randomized for release public: std::size_t operator() (const SHAMapNode& mn) const - { return mn.getDepth() ^ static_cast(mn.getNodeID().PeekAt(0)); } + { return mn.getDepth() ^ static_cast(mn.getNodeID().GetAt(0)); } std::size_t operator() (const uint256& u) const - { return static_cast(u.PeekAt(0)); } + { return static_cast(u.GetAt(0)); } }; class SHAMapItem diff --git a/SHAMapNodes.cpp b/SHAMapNodes.cpp index 184806e11c..c8a5005828 100644 --- a/SHAMapNodes.cpp +++ b/SHAMapNodes.cpp @@ -99,10 +99,9 @@ SHAMapNode SHAMapNode::getChildNodeID(int m) const { // This can be optimized to avoid the << if needed assert((m>=0) && (m<16)); - uint256 branch=m; - branch<<=mDepth*4; - - return SHAMapNode(mDepth+1, mNodeID | branch); + uint256 child(mNodeID); + child.PeekAt(mDepth/8) |= m << (4*(mDepth%8)); + return SHAMapNode(mDepth+1, child); } int SHAMapNode::selectBranch(const uint256& hash) const diff --git a/uint256.h b/uint256.h index 17de428736..4077c5e593 100644 --- a/uint256.h +++ b/uint256.h @@ -303,7 +303,12 @@ public: return (!(a == b)); } - unsigned int PeekAt(int j) const + unsigned int GetAt(int j) const + { + return pn[j]; + } + + unsigned int& PeekAt(int j) { return pn[j]; }