rippled
Loading...
Searching...
No Matches
SHAMapLeafNode.cpp
1#include <xrpl/shamap/SHAMapLeafNode.h>
2
3namespace xrpl {
4
5SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<SHAMapItem const> item, std::uint32_t cowid)
6 : SHAMapTreeNode(cowid), item_(std::move(item))
7{
8 XRPL_ASSERT(
9 item_->size() >= 12,
10 "xrpl::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
11 "SHAMapItem const>, std::uint32_t) : minimum input size");
12}
13
15 boost::intrusive_ptr<SHAMapItem const> item,
16 std::uint32_t cowid,
17 SHAMapHash const& hash)
18 : SHAMapTreeNode(cowid, hash), item_(std::move(item))
19{
20 XRPL_ASSERT(
21 item_->size() >= 12,
22 "xrpl::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
23 "SHAMapItem const>, std::uint32_t, SHAMapHash const&) : minimum input "
24 "size");
25}
26
27boost::intrusive_ptr<SHAMapItem const> const&
29{
30 return item_;
31}
32
33bool
34SHAMapLeafNode::setItem(boost::intrusive_ptr<SHAMapItem const> item)
35{
36 XRPL_ASSERT(cowid_, "xrpl::SHAMapLeafNode::setItem : nonzero cowid");
37 item_ = std::move(item);
38
39 auto const oldHash = hash_;
40
41 updateHash();
42
43 return (oldHash != hash_);
44}
45
48{
50
51 auto const type = getType();
52
54 ret += ",txn\n";
55 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
56 ret += ",txn+md\n";
57 else if (type == SHAMapNodeType::tnACCOUNT_STATE)
58 ret += ",as\n";
59 else
60 ret += ",leaf\n";
61
62 ret += " Tag=";
63 ret += to_string(item_->key());
64 ret += "\n Hash=";
65 ret += to_string(hash_);
66 ret += "/";
67 ret += std::to_string(item_->size());
68 return ret;
69}
70
71void
73{
74 XRPL_ASSERT(hash_.isNonZero(), "xrpl::SHAMapLeafNode::invariants : nonzero hash");
75 XRPL_ASSERT(item_, "xrpl::SHAMapLeafNode::invariants : non-null item");
76}
77
78} // namespace xrpl
bool isNonZero() const
Definition SHAMapHash.h:39
boost::intrusive_ptr< SHAMapItem const > item_
void invariants(bool is_root=false) const final override
SHAMapLeafNode(boost::intrusive_ptr< SHAMapItem const > item, std::uint32_t cowid)
bool setItem(boost::intrusive_ptr< SHAMapItem const > i)
Set the item that this node points to and update the node's hash.
boost::intrusive_ptr< SHAMapItem const > const & peekItem() const
std::string getString(SHAMapNodeID const &) const final override
Identifies a node inside a SHAMap.
std::uint32_t cowid_
Determines the owning SHAMap, if any.
virtual SHAMapNodeType getType() const =0
Determines the type of node.
virtual std::string getString(SHAMapNodeID const &) const
virtual void updateHash()=0
Recalculate the hash of this node.
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:600
T to_string(T... args)