20 #include <ripple/beast/core/LexicalCast.h>
21 #include <ripple/crypto/csprng.h>
22 #include <ripple/protocol/Serializer.h>
23 #include <ripple/shamap/SHAMap.h>
24 #include <ripple/shamap/SHAMapNodeID.h>
32 enum { mask_size = 65 };
41 for (
int i = 0; i < mask_size - 1; i += 2)
44 *(selector.
begin() + (i / 2)) = 0xF0;
45 entry[i + 1] = selector;
46 *(selector.
begin() + (i / 2)) = 0xFF;
48 entry[mask_size - 1] = selector;
52 static masks_t
const masks;
53 return masks.entry[depth];
58 : id_(hash), depth_(depth)
89 Throw<std::logic_error>(
90 "Request for child node ID of " +
to_string(*
this));
93 Throw<std::logic_error>(
"Incorrect mask for " +
to_string(*
this));
107 unsigned int depth = *(
static_cast<unsigned char const*
>(data) + 32);
120 [[nodiscard]]
unsigned int
123 auto const depth =
id.getDepth();
124 auto branch =
static_cast<unsigned int>(*(hash.
begin() + (depth / 2)));
138 assert((depth >= 0) && (depth < 65));
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
SHAMapNodeID getChildNodeID(unsigned int m) const
unsigned int selectBranch(SHAMapNodeID const &id, uint256 const &hash)
Returns the branch that would contain the given hash.
std::optional< SHAMapNodeID > deserializeSHAMapNodeID(void const *data, std::size_t size)
Return an object representing a serialized SHAMap Node ID.
std::string getString() const
int add8(unsigned char i)
Identifies a node inside a SHAMap.
static uint256 const & depthMask(unsigned int depth)
std::string getRawString() const
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
int addBitString(base_uint< Bits, Tag > const &v)
static base_uint fromVoid(void const *data)
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
static SHAMapNodeID createID(int depth, uint256 const &key)
Create a SHAMapNodeID of a node with the depth of the node and the key of a leaf.