DRY up and document magic constant used for hash maps

This commit is contained in:
Vinnie Falco
2013-06-07 11:35:56 -07:00
parent 3cf2fb884d
commit db9f62646d
3 changed files with 25 additions and 19 deletions

View File

@@ -26,21 +26,13 @@ void SHAMapNode::setMHash() const
{
using namespace std;
// VFALCO: TODO, figure out what this is for and whether or
// not it affects the protocol specification.
//
// NOTE, this constant is used elsewhere as well.
// should it be DRY?
//
const std::size_t mysteriousConstant = 0x9e3779b9;
std::size_t h = HashMaps::getInstance ().getNonce <std::size_t> ()
+ (mDepth * mysteriousConstant);
+ (mDepth * HashMaps::goldenRatio);
const unsigned int *ptr = reinterpret_cast <const unsigned int *>(mNodeID.begin());
for (int i = (mDepth + 7) / 8; i != 0; --i)
h = (h * mysteriousConstant) ^ *ptr++;
h = (h * HashMaps::goldenRatio) ^ *ptr++;
mHash = h;
}