1#include <xrpl/shamap/SHAMapNodeID.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/basics/contract.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/protocol/Serializer.h>
7#include <xrpl/shamap/SHAMap.h>
19 static constexpr auto kMaskSize = 65;
28 for (
int i = 0; i < kMaskSize - 1; i += 2)
31 *(selector.
begin() + (i / 2)) = 0xF0;
32 entry[i + 1] = selector;
33 *(selector.
begin() + (i / 2)) = 0xFF;
35 entry[kMaskSize - 1] = selector;
39 static MasksT
const kMasks;
40 return kMasks.entry[depth];
47 depth <=
SHAMap::kLeafDepth,
"xrpl::SHAMapNodeID::SHAMapNodeID : maximum depth input");
50 "xrpl::SHAMapNodeID::SHAMapNodeID : hash and depth inputs do match");
97 unsigned int const depth = *(
static_cast<unsigned char const*
>(data) + 32);
110[[nodiscard]]
unsigned int
113 auto const depth =
id.getDepth();
114 auto branch =
static_cast<unsigned int>(*(hash.
begin() + (depth / 2)));
116 if ((depth & 1) != 0u)
132 XRPL_ASSERT((depth >= 0) && (depth < 65),
"xrpl::SHAMapNodeID::createID : valid branch input");
static BaseUInt fromVoid(void const *data)
Identifies a node inside a SHAMap.
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.
SHAMapNodeID getChildNodeID(unsigned int m) const
std::string getRawString() const
static constexpr unsigned int kLeafDepth
The depth of the hash map: data is only present in the leaves.
static constexpr unsigned int kBranchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map).
int addBitString(BaseUInt< Bits, Tag > const &v)
std::string getString() const
int add8(unsigned char i)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(BaseUInt< Bits, Tag > const &a)
static uint256 const & depthMask(unsigned int depth)
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.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)