xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
shamap
SHAMapLeafNode.cpp
1
#include <xrpl/shamap/SHAMapLeafNode.h>
2
3
#include <xrpl/basics/SHAMapHash.h>
4
#include <xrpl/basics/base_uint.h>
5
#include <xrpl/beast/utility/instrumentation.h>
6
#include <xrpl/shamap/SHAMapItem.h>
7
#include <xrpl/shamap/SHAMapNodeID.h>
8
#include <xrpl/shamap/SHAMapTreeNode.h>
9
10
#include <boost/smart_ptr/intrusive_ptr.hpp>
11
12
#include <
cstdint
>
13
#include <
string
>
14
#include <
utility
>
15
16
namespace
xrpl
{
17
18
SHAMapLeafNode::SHAMapLeafNode
(boost::intrusive_ptr<SHAMapItem const> item,
std::uint32_t
cowid
)
19
:
SHAMapTreeNode
(
cowid
),
item_
(
std
::move(item))
20
{
21
XRPL_ASSERT(
22
item_
->size() >=
kMinShaMapItemBytes
,
23
"xrpl::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
24
"SHAMapItem const>, std::uint32_t) : minimum input size"
);
25
}
26
27
SHAMapLeafNode::SHAMapLeafNode
(
28
boost::intrusive_ptr<SHAMapItem const> item,
29
std::uint32_t
cowid
,
30
SHAMapHash
const
& hash)
31
:
SHAMapTreeNode
(
cowid
, hash),
item_
(
std
::move(item))
32
{
33
XRPL_ASSERT(
34
item_
->size() >=
kMinShaMapItemBytes
,
35
"xrpl::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
36
"SHAMapItem const>, std::uint32_t, SHAMapHash const&) : minimum input "
37
"size"
);
38
}
39
40
boost::intrusive_ptr<SHAMapItem const>
const
&
41
SHAMapLeafNode::peekItem
()
const
42
{
43
return
item_
;
44
}
45
46
bool
47
SHAMapLeafNode::setItem
(boost::intrusive_ptr<SHAMapItem const> item)
48
{
49
XRPL_ASSERT(
cowid_
,
"xrpl::SHAMapLeafNode::setItem : nonzero cowid"
);
50
item_
= std::move(item);
51
52
auto
const
oldHash =
hash_
;
53
54
updateHash
();
55
56
return
(oldHash !=
hash_
);
57
}
58
59
std::string
60
SHAMapLeafNode::getString
(
SHAMapNodeID
const
&
id
)
const
61
{
62
std::string
ret =
SHAMapTreeNode::getString
(
id
);
63
64
auto
const
type =
getType
();
65
66
if
(type ==
SHAMapNodeType::TnTransactionNm
)
67
{
68
ret +=
",txn\n"
;
69
}
70
else
if
(type ==
SHAMapNodeType::TnTransactionMd
)
71
{
72
ret +=
",txn+md\n"
;
73
}
74
else
if
(type ==
SHAMapNodeType::TnAccountState
)
75
{
76
ret +=
",as\n"
;
77
}
78
else
79
{
80
ret +=
",leaf\n"
;
81
}
82
83
ret +=
" Tag="
;
84
ret +=
to_string
(
item_
->key());
85
ret +=
"\n Hash="
;
86
ret +=
to_string
(
hash_
);
87
ret +=
"/"
;
88
ret +=
std::to_string
(
item_
->size());
89
return
ret;
90
}
91
92
void
93
SHAMapLeafNode::invariants
(
bool
)
const
94
{
95
XRPL_ASSERT(
hash_
.isNonZero(),
"xrpl::SHAMapLeafNode::invariants : nonzero hash"
);
96
XRPL_ASSERT(
item_
,
"xrpl::SHAMapLeafNode::invariants : non-null item"
);
97
}
98
99
}
// namespace xrpl
std::string
xrpl::SHAMapHash
Definition
SHAMapHash.h:16
xrpl::SHAMapLeafNode::item_
boost::intrusive_ptr< SHAMapItem const > item_
Definition
SHAMapLeafNode.h:19
xrpl::SHAMapLeafNode::SHAMapLeafNode
SHAMapLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
Definition
SHAMapLeafNode.cpp:18
xrpl::SHAMapLeafNode::invariants
void invariants(bool isRoot=false) const final
Definition
SHAMapLeafNode.cpp:93
xrpl::SHAMapLeafNode::setItem
bool setItem(boost::intrusive_ptr< SHAMapItem const > i)
Set the item that this node points to and update the node's hash.
Definition
SHAMapLeafNode.cpp:47
xrpl::SHAMapLeafNode::getString
std::string getString(SHAMapNodeID const &) const final
Definition
SHAMapLeafNode.cpp:60
xrpl::SHAMapLeafNode::peekItem
boost::intrusive_ptr< SHAMapItem const > const & peekItem() const
Definition
SHAMapLeafNode.cpp:41
xrpl::SHAMapNodeID
Identifies a node inside a SHAMap.
Definition
SHAMapNodeID.h:20
xrpl::SHAMapTreeNode::cowid_
std::uint32_t cowid_
Determines the owning SHAMap, if any.
Definition
SHAMapTreeNode.h:49
xrpl::SHAMapTreeNode::getType
virtual SHAMapNodeType getType() const =0
Determines the type of node.
xrpl::SHAMapTreeNode::hash_
SHAMapHash hash_
Definition
SHAMapTreeNode.h:40
xrpl::SHAMapTreeNode::SHAMapTreeNode
SHAMapTreeNode(std::uint32_t cowid) noexcept
Construct a node.
Definition
SHAMapTreeNode.h:58
xrpl::SHAMapTreeNode::getString
virtual std::string getString(SHAMapNodeID const &) const
Definition
SHAMapTreeNode.cpp:189
xrpl::SHAMapTreeNode::updateHash
virtual void updateHash()=0
Recalculate the hash of this node.
cstdint
xrpl::SHAMapTreeNode::cowid
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
Definition
SHAMapTreeNode.h:105
std::uint32_t
std
STL namespace.
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::SHAMapNodeType::TnTransactionMd
@ TnTransactionMd
Definition
SHAMapTreeNode.h:33
xrpl::SHAMapNodeType::TnTransactionNm
@ TnTransactionNm
Definition
SHAMapTreeNode.h:32
xrpl::SHAMapNodeType::TnAccountState
@ TnAccountState
Definition
SHAMapTreeNode.h:34
xrpl::to_string
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition
base_uint.h:657
xrpl::kMinShaMapItemBytes
constexpr std::size_t kMinShaMapItemBytes
Definition
SHAMapTreeNode.h:28
string
std::to_string
T to_string(T... args)
utility
Generated by
1.17.0