20#include <xrpld/shamap/SHAMap.h>
21#include <xrpld/shamap/SHAMapNodeID.h>
22#include <xrpl/beast/core/LexicalCast.h>
23#include <xrpl/beast/utility/instrumentation.h>
24#include <xrpl/crypto/csprng.h>
25#include <xrpl/protocol/Serializer.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)
62 "ripple::SHAMapNodeID::SHAMapNodeID : maximum depth input");
65 "ripple::SHAMapNodeID::SHAMapNodeID : hash and depth inputs do match");
82 "ripple::SHAMapNodeID::getChildNodeID : valid branch input");
94 "ripple::SHAMapNodeID::getChildNodeID : maximum leaf depth");
97 Throw<std::logic_error>(
98 "Request for child node ID of " +
to_string(*
this));
101 Throw<std::logic_error>(
"Incorrect mask for " +
to_string(*
this));
115 unsigned int depth = *(
static_cast<unsigned char const*
>(data) + 32);
128[[nodiscard]]
unsigned int
131 auto const depth =
id.getDepth();
132 auto branch =
static_cast<unsigned int>(*(hash.
begin() + (depth / 2)));
148 (depth >= 0) && (depth < 65),
149 "ripple::SHAMapNodeID::createID : valid branch input");
Identifies a node inside a SHAMap.
SHAMapNodeID getChildNodeID(unsigned int m) const
std::string getRawString() const
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.
static constexpr unsigned int leafDepth
The depth of the hash map: data is only present in the leaves.
static constexpr unsigned int branchFactor
Number of children each non-leaf node has (the 'radix tree' part of the map)
int addBitString(base_uint< Bits, Tag > const &v)
int add8(unsigned char i)
std::string getString() const
static base_uint fromVoid(void const *data)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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.
static uint256 const & depthMask(unsigned int depth)
std::string to_string(base_uint< Bits, Tag > const &a)