1#include <xrpl/beast/core/LexicalCast.h>
2#include <xrpl/beast/utility/instrumentation.h>
3#include <xrpl/protocol/Serializer.h>
4#include <xrpl/shamap/SHAMap.h>
5#include <xrpl/shamap/SHAMapNodeID.h>
12 enum { mask_size = 65 };
21 for (
int i = 0; i < mask_size - 1; i += 2)
24 *(selector.
begin() + (i / 2)) = 0xF0;
25 entry[i + 1] = selector;
26 *(selector.
begin() + (i / 2)) = 0xFF;
28 entry[mask_size - 1] = selector;
32 static masks_t
const masks;
33 return masks.entry[depth];
38 : id_(hash), depth_(depth)
42 "ripple::SHAMapNodeID::SHAMapNodeID : maximum depth input");
45 "ripple::SHAMapNodeID::SHAMapNodeID : hash and depth inputs do match");
62 "ripple::SHAMapNodeID::getChildNodeID : valid branch input");
74 "ripple::SHAMapNodeID::getChildNodeID : maximum leaf depth");
77 Throw<std::logic_error>(
78 "Request for child node ID of " +
to_string(*
this));
81 Throw<std::logic_error>(
"Incorrect mask for " +
to_string(*
this));
95 unsigned int depth = *(
static_cast<unsigned char const*
>(data) + 32);
108[[nodiscard]]
unsigned int
111 auto const depth =
id.getDepth();
112 auto branch =
static_cast<unsigned int>(*(hash.
begin() + (depth / 2)));
128 (depth >= 0) && (depth < 65),
129 "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.
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)
unsigned int selectBranch(SHAMapNodeID const &id, uint256 const &hash)
Returns the branch that would contain the given hash.
std::string to_string(base_uint< Bits, Tag > const &a)