mirror of
https://github.com/XRPLF/rippled.git
synced 2026-08-21 22:30:57 +00:00
79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <xrpl/basics/SHAMapHash.h>
|
|
#include <xrpl/basics/base_uint.h>
|
|
#include <xrpl/basics/safe_cast.h>
|
|
#include <xrpl/beast/utility/instrumentation.h>
|
|
#include <xrpl/shamap/SHAMapItem.h>
|
|
#include <xrpl/shamap/SHAMapNodeID.h>
|
|
#include <xrpl/shamap/SHAMapTreeNode.h>
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
namespace xrpl {
|
|
|
|
class SHAMapLeafNode : public SHAMapTreeNode
|
|
{
|
|
protected:
|
|
boost::intrusive_ptr<SHAMapItem const> item_;
|
|
|
|
SHAMapLeafNode(boost::intrusive_ptr<SHAMapItem const> item, std::uint32_t cowid);
|
|
|
|
SHAMapLeafNode(
|
|
boost::intrusive_ptr<SHAMapItem const> item,
|
|
std::uint32_t cowid,
|
|
SHAMapHash const& hash);
|
|
|
|
public:
|
|
SHAMapLeafNode(SHAMapLeafNode const&) = delete;
|
|
SHAMapLeafNode&
|
|
operator=(SHAMapLeafNode const&) = delete;
|
|
|
|
bool
|
|
isLeaf() const final
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
isInner() const final
|
|
{
|
|
return false;
|
|
}
|
|
|
|
void
|
|
invariants(bool isRoot = false) const final;
|
|
|
|
public:
|
|
boost::intrusive_ptr<SHAMapItem const> const&
|
|
peekItem() const;
|
|
|
|
/**
|
|
* Set the item that this node points to and update the node's hash.
|
|
*
|
|
* @param i the new item
|
|
* @return false if the change was, effectively, a noop (that is, if the
|
|
* hash was unchanged); true otherwise.
|
|
*/
|
|
bool
|
|
setItem(boost::intrusive_ptr<SHAMapItem const> i);
|
|
|
|
std::string
|
|
getString(SHAMapNodeID const&) const final;
|
|
};
|
|
|
|
/**
|
|
* Return the key of the item held by a SHAMap leaf node.
|
|
*
|
|
* @param node a node known to be a leaf (see SHAMapTreeNode::isLeaf).
|
|
*/
|
|
inline uint256 const&
|
|
leafKey(SHAMapTreeNode const& node)
|
|
{
|
|
XRPL_ASSERT(node.isLeaf(), "xrpl::leafKey : node is a leaf");
|
|
return safeDowncast<SHAMapLeafNode const&>(node).peekItem()->key();
|
|
}
|
|
|
|
} // namespace xrpl
|