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
14SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<SHAMapItem const> item, std::uint32_t cowid, SHAMapHash const& hash)
15 : SHAMapTreeNode(cowid, hash), item_(std::move(item))
16{
17 XRPL_ASSERT(
18 item_->size() >= 12,
19 "xrpl::SHAMapLeafNode::SHAMapLeafNode(boost::intrusive_ptr<"
20 "SHAMapItem const>, std::uint32_t, SHAMapHash const&) : minimum input "
21 "size");
22}
23
24boost::intrusive_ptr<SHAMapItem const> const&
26{
27 return item_;
28}
29
30bool
31SHAMapLeafNode::setItem(boost::intrusive_ptr<SHAMapItem const> item)
32{
33 XRPL_ASSERT(cowid_, "xrpl::SHAMapLeafNode::setItem : nonzero cowid");
34 item_ = std::move(item);
35
36 auto const oldHash = hash_;
37
38 updateHash();
39
40 return (oldHash != hash_);
41}
42
45{
47
48 auto const type = getType();
49
51 ret += ",txn\n";
52 else if (type == SHAMapNodeType::tnTRANSACTION_MD)
53 ret += ",txn+md\n";
54 else if (type == SHAMapNodeType::tnACCOUNT_STATE)
55 ret += ",as\n";
56 else
57 ret += ",leaf\n";
58
59 ret += " Tag=";
60 ret += to_string(item_->key());
61 ret += "\n Hash=";
62 ret += to_string(hash_);
63 ret += "/";
64 ret += std::to_string(item_->size());
65 return ret;
66}
67
68void
70{
71 XRPL_ASSERT(hash_.isNonZero(), "xrpl::SHAMapLeafNode::invariants : nonzero hash");
72 XRPL_ASSERT(item_, "xrpl::SHAMapLeafNode::invariants : non-null item");
73}
74
75} // 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:597
T to_string(T... args)