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