mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Cleanup and simplifications to SHAMap:
SHAMapTreeNode * Remove SHAMapTreeNode::pointer and SHAMapTreeNode::ref. * Add std includes necessary to make the header standalone. * Remove implementation from the SHAMapTreeNode declaration. * Make clear what part of SHAMapTreeNode is: 1) Truly public. 2) Used only by SHAMap. 3) Truly private to SHAMapTreeNode. SHAMapItem * Remove SHAMapItem::pointer and SHAMapItem::ref. * Add std includes necessary to make the header standalone. * Remove implementation from the SHAMapItem declaration. * Make clear what part of SHAMapItem is: 1) Truly public. 2) Used only by SHAMapTreeNode. 3) Truly private to SHAMapItem. SHAMapSyncFilter * Add override for SHAMapSyncFilter-derived functions. * Add missing header. * Default the destructor and delete the SHAMapSyncFilter copy members. SHAMapNodeID * Remove unused mHash member. * Remove unused std::hash and boost::hash specializations. * Remove unused constructor. * Remove unused comparison with uint256. * Remove unused getNodeID (int depth, uint256 const& hash). * Remove virtual specifier from getString(). * Fix operator<= and operator>=. * Document what API is used outside of SHAMap. * Move inline definitions outside of the class declaration. SHAMapMissingNode * Make SHAMapType a enum class to prevent unwanted conversions. * Remove needless ~SHAMapMissingNode() declaration/definition. * Add referenced std includes. SHAMapAddNode * Make SHAMapAddNode (int good, int bad, int duplicate) ctor private. * Move all member function definitions out of the class declaration. * Remove dependence on beast::lexicalCastThrow. * Make getGood() const. * Make get() const. * Add #include <string>. SHAMap * Remove unused enum STATE_MAP_BUCKETS. * Remove unused getCountedObjectName(). * Remove SHAMap::pointer * Remove SHAMap::ref * Remove unused fetchPackEntry_t. * Remove inline member function definitions from class declaration. * Remove unused getTrustedPath. * Remove unused getPath. * Remove unused visitLeavesInternal. * Make SHAMapState an enum class. * Explicitly delete SHAMap copy members. * Reduce access to nested types as much as possible. * Normalize member data names to one style. * Change last of the typedefs to usings under shamap. * Reorder some includes ripple-first, beast-second. * Declare a few constructions from make_shared with auto. * Mark those SHAMap member functions which can be, with const. * Add missing includes
This commit is contained in:
committed by
Vinnie Falco
parent
315a8b6b60
commit
ec1e6b9385
@@ -57,43 +57,15 @@ SHAMapNodeID::Masks (int depth)
|
||||
return masks->entry[depth];
|
||||
}
|
||||
|
||||
std::size_t
|
||||
SHAMapNodeID::calculate_hash (uint256 const& node, int depth)
|
||||
{
|
||||
struct HashParams
|
||||
{
|
||||
HashParams ()
|
||||
: golden_ratio (0x9e3779b9)
|
||||
{
|
||||
random_fill (&cookie_value);
|
||||
}
|
||||
|
||||
// The cookie value protects us against algorithmic complexity attacks.
|
||||
std::size_t cookie_value;
|
||||
std::size_t golden_ratio;
|
||||
};
|
||||
|
||||
static beast::static_initializer <HashParams> params;
|
||||
|
||||
std::size_t h = params->cookie_value + (depth * params->golden_ratio);
|
||||
|
||||
auto ptr = reinterpret_cast <const unsigned int*> (node.cbegin ());
|
||||
|
||||
for (int i = (depth + 7) / 8; i != 0; --i)
|
||||
h = (h * params->golden_ratio) ^ *ptr++;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
// canonicalize the hash to a node ID for this depth
|
||||
SHAMapNodeID::SHAMapNodeID (int depth, uint256 const& hash)
|
||||
: mNodeID (hash), mDepth (depth), mHash (0)
|
||||
: mNodeID (hash), mDepth (depth)
|
||||
{
|
||||
assert ((depth >= 0) && (depth < 65));
|
||||
mNodeID &= Masks(depth);
|
||||
}
|
||||
|
||||
SHAMapNodeID::SHAMapNodeID (void const* ptr, int len) : mHash (0)
|
||||
SHAMapNodeID::SHAMapNodeID (void const* ptr, int len)
|
||||
{
|
||||
if (len < 33)
|
||||
mDepth = -1;
|
||||
@@ -113,12 +85,6 @@ std::string SHAMapNodeID::getString () const
|
||||
"," + to_string (mNodeID) + ")";
|
||||
}
|
||||
|
||||
uint256 SHAMapNodeID::getNodeID (int depth, uint256 const& hash)
|
||||
{
|
||||
assert ((depth >= 0) && (depth <= 64));
|
||||
return hash & Masks(depth);
|
||||
}
|
||||
|
||||
void SHAMapNodeID::addIDRaw (Serializer& s) const
|
||||
{
|
||||
s.add256 (mNodeID);
|
||||
@@ -141,7 +107,7 @@ SHAMapNodeID SHAMapNodeID::getChildNodeID (int m) const
|
||||
uint256 child (mNodeID);
|
||||
child.begin ()[mDepth / 2] |= (mDepth & 1) ? m : (m << 4);
|
||||
|
||||
return SHAMapNodeID (mDepth + 1, child, true);
|
||||
return SHAMapNodeID (mDepth + 1, child);
|
||||
}
|
||||
|
||||
// Which branch would contain the specified hash
|
||||
|
||||
Reference in New Issue
Block a user