xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
shamap
SHAMapNodeID.h
1
#pragma once
2
3
#include <xrpl/basics/CountedObject.h>
4
#include <xrpl/basics/base_uint.h>
5
6
#include <
compare
>
7
#include <
cstddef
>
8
#include <
optional
>
9
#include <
ostream
>
10
#include <
string
>
11
#include <
string_view
>
12
#include <
tuple
>
13
14
namespace
xrpl
{
15
19
class
SHAMapNodeID
:
public
CountedObject
<SHAMapNodeID>
20
{
21
private
:
22
UInt256
id_
;
23
unsigned
int
depth_
= 0;
24
25
public
:
26
SHAMapNodeID
() =
default
;
27
SHAMapNodeID
(
SHAMapNodeID
const
& other) =
default
;
28
SHAMapNodeID
(
unsigned
int
depth,
UInt256
const
& hash);
29
30
SHAMapNodeID
&
31
operator=
(
SHAMapNodeID
const
& other) =
default
;
32
33
[[nodiscard]]
bool
34
isRoot
()
const
35
{
36
return
depth_
== 0;
37
}
38
39
// Get the wire format (256-bit nodeID, 1-byte depth)
40
[[nodiscard]]
std::string
41
getRawString
()
const
;
42
43
[[nodiscard]]
unsigned
int
44
getDepth
()
const
45
{
46
return
depth_
;
47
}
48
49
[[nodiscard]]
UInt256
const
&
50
getNodeID
()
const
51
{
52
return
id_
;
53
}
54
55
[[nodiscard]]
SHAMapNodeID
56
getChildNodeID
(
unsigned
int
branch)
const
;
57
69
[[nodiscard]]
bool
70
isPrefixOf
(
UInt256
const
& key)
const
;
71
80
static
SHAMapNodeID
81
createID
(
unsigned
int
depth,
UInt256
const
& key);
82
90
std::strong_ordering
91
operator<=>
(
SHAMapNodeID
const
& n)
const
92
{
93
return
std::tie
(
depth_
,
id_
) <=>
std::tie
(n.
depth_
, n.
id_
);
94
}
95
104
bool
105
operator==
(
SHAMapNodeID
const
& n)
const
106
{
107
return
(
depth_
== n.
depth_
) && (
id_
== n.
id_
);
108
}
109
};
110
111
inline
std::string
112
to_string
(
SHAMapNodeID
const
& node)
113
{
114
if
(node.
isRoot
())
115
return
"NodeID(root)"
;
116
117
return
"NodeID("
+
std::to_string
(node.
getDepth
()) +
","
+
to_string
(node.
getNodeID
()) +
")"
;
118
}
119
120
inline
std::ostream
&
121
operator<<
(
std::ostream
& out,
SHAMapNodeID
const
& node)
122
{
123
return
out <<
to_string
(node);
124
}
125
136
[[nodiscard]]
std::optional<SHAMapNodeID>
137
deserializeSHAMapNodeID
(
void
const
* data,
std::size_t
size);
138
139
[[nodiscard]]
inline
std::optional<SHAMapNodeID>
140
deserializeSHAMapNodeID
(
std::string_view
s)
141
{
142
return
deserializeSHAMapNodeID
(s.
data
(), s.
size
());
143
}
144
145
149
[[nodiscard]]
unsigned
int
150
selectBranch
(SHAMapNodeID
const
&
id
,
UInt256
const
& hash);
151
152
}
// namespace xrpl
std::ostream
std::string
std::string_view
xrpl::CountedObject< SHAMapNodeID >::CountedObject
CountedObject() noexcept
Definition
CountedObject.h:119
xrpl::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition
SHAMapNodeID.h:20
xrpl::SHAMapNodeID::isPrefixOf
bool isPrefixOf(UInt256 const &key) const
Test whether this node ID lies on the path to the given leaf key.
Definition
libxrpl/shamap/SHAMapNodeID.cpp:122
xrpl::SHAMapNodeID::getChildNodeID
SHAMapNodeID getChildNodeID(unsigned int branch) const
Definition
libxrpl/shamap/SHAMapNodeID.cpp:94
xrpl::SHAMapNodeID::SHAMapNodeID
SHAMapNodeID()=default
xrpl::SHAMapNodeID::SHAMapNodeID
SHAMapNodeID(SHAMapNodeID const &other)=default
xrpl::SHAMapNodeID::depth_
unsigned int depth_
Definition
SHAMapNodeID.h:23
xrpl::SHAMapNodeID::operator=
SHAMapNodeID & operator=(SHAMapNodeID const &other)=default
xrpl::SHAMapNodeID::getNodeID
UInt256 const & getNodeID() const
Definition
SHAMapNodeID.h:50
xrpl::SHAMapNodeID::operator==
bool operator==(SHAMapNodeID const &n) const
Equality, which the spaceship above does not provide.
Definition
SHAMapNodeID.h:105
xrpl::SHAMapNodeID::createID
static SHAMapNodeID createID(unsigned int depth, UInt256 const &key)
Create a SHAMapNodeID of a node with the depth of the node and the key of a leaf.
Definition
libxrpl/shamap/SHAMapNodeID.cpp:171
xrpl::SHAMapNodeID::operator<=>
std::strong_ordering operator<=>(SHAMapNodeID const &n) const
Comparison operators.
Definition
SHAMapNodeID.h:91
xrpl::SHAMapNodeID::getDepth
unsigned int getDepth() const
Definition
SHAMapNodeID.h:44
xrpl::SHAMapNodeID::id_
UInt256 id_
Definition
SHAMapNodeID.h:22
xrpl::SHAMapNodeID::getRawString
std::string getRawString() const
Definition
libxrpl/shamap/SHAMapNodeID.cpp:85
xrpl::SHAMapNodeID::isRoot
bool isRoot() const
Definition
SHAMapNodeID.h:34
compare
cstddef
std::string_view::data
T data(T... args)
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::operator<<
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition
base_uint.h:672
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::deserializeSHAMapNodeID
std::optional< SHAMapNodeID > deserializeSHAMapNodeID(void const *data, std::size_t size)
Return an object representing a serialized SHAMap Node ID.
Definition
libxrpl/shamap/SHAMapNodeID.cpp:128
xrpl::selectBranch
unsigned int selectBranch(SHAMapNodeID const &id, UInt256 const &hash)
Returns the branch that would contain the given hash.
Definition
libxrpl/shamap/SHAMapNodeID.cpp:148
optional
ostream
std::string_view::size
T size(T... args)
std::size_t
string
string_view
std::strong_ordering
std::tie
T tie(T... args)
std::to_string
T to_string(T... args)
tuple
Generated by
1.17.0