rippled
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
ripple::SHAMapInnerNode Class Referencefinal
Inheritance diagram for ripple::SHAMapInnerNode:
Inheritance graph
[legend]
Collaboration diagram for ripple::SHAMapInnerNode:
Collaboration graph
[legend]

Public Member Functions

 SHAMapInnerNode (std::uint32_t cowid, std::uint8_t numAllocatedChildren=2)
 
 SHAMapInnerNode (SHAMapInnerNode const &)=delete
 
SHAMapInnerNodeoperator= (SHAMapInnerNode const &)=delete
 
 ~SHAMapInnerNode ()
 
std::shared_ptr< SHAMapTreeNodeclone (std::uint32_t cowid) const override
 Make a copy of this node, setting the owner. More...
 
SHAMapNodeType getType () const override
 Determines the type of node. More...
 
bool isLeaf () const override
 Determines if this is a leaf node. More...
 
bool isInner () const override
 Determines if this is an inner node. More...
 
bool isEmpty () const
 
bool isEmptyBranch (int m) const
 
int getBranchCount () const
 
SHAMapHash const & getChildHash (int m) const
 
void setChild (int m, std::shared_ptr< SHAMapTreeNode > child)
 
void shareChild (int m, std::shared_ptr< SHAMapTreeNode > const &child)
 
SHAMapTreeNodegetChildPointer (int branch)
 
std::shared_ptr< SHAMapTreeNodegetChild (int branch)
 
std::shared_ptr< SHAMapTreeNodecanonicalizeChild (int branch, std::shared_ptr< SHAMapTreeNode > node)
 
bool isFullBelow (std::uint32_t generation) const
 
void setFullBelowGen (std::uint32_t gen)
 
void updateHash () override
 Recalculate the hash of this node. More...
 
void updateHashDeep ()
 Recalculate the hash of all children and this node. More...
 
void serializeForWire (Serializer &) const override
 Serialize the node in a format appropriate for sending over the wire. More...
 
void serializeWithPrefix (Serializer &) const override
 Serialize the node in a format appropriate for hashing. More...
 
std::string getString (SHAMapNodeID const &) const override
 
void invariants (bool is_root=false) const override
 
std::uint32_t cowid () const
 Returns the SHAMap that owns this node. More...
 
void unshare ()
 If this node is shared with another map, mark it as no longer shared. More...
 
SHAMapHash const & getHash () const
 Return the hash of this node. More...
 

Static Public Member Functions

static std::shared_ptr< SHAMapTreeNodemakeFullInner (Slice data, SHAMapHash const &hash, bool hashValid)
 
static std::shared_ptr< SHAMapTreeNodemakeCompressedInner (Slice data)
 
static std::shared_ptr< SHAMapTreeNodemakeFromPrefix (Slice rawNode, SHAMapHash const &hash)
 
static std::shared_ptr< SHAMapTreeNodemakeFromWire (Slice rawNode)
 

Static Public Attributes

static constexpr unsigned int branchFactor = 16
 Each inner node has 16 children (the 'radix tree' part of the map) More...
 

Protected Attributes

SHAMapHash hash_
 
std::uint32_t cowid_
 Determines the owning SHAMap, if any. More...
 

Private Member Functions

void resizeChildArrays (std::uint8_t toAllocate)
 Convert arrays stored in hashesAndChildren_ so they can store the requested number of children. More...
 
std::optional< int > getChildIndex (int i) const
 Get the child's index inside the hashes or children array (stored in hashesAndChildren_. More...
 
template<class F >
void iterChildren (F &&f) const
 Call the f callback for all 16 (branchFactor) branches - even if the branch is empty. More...
 
template<class F >
void iterNonEmptyChildIndexes (F &&f) const
 Call the f callback for all non-empty branches. More...
 

Static Private Member Functions

static std::shared_ptr< SHAMapTreeNodemakeTransaction (Slice data, SHAMapHash const &hash, bool hashValid)
 
static std::shared_ptr< SHAMapTreeNodemakeAccountState (Slice data, SHAMapHash const &hash, bool hashValid)
 
static std::shared_ptr< SHAMapTreeNodemakeTransactionWithMeta (Slice data, SHAMapHash const &hash, bool hashValid)
 
static auto & getCounter () noexcept
 

Private Attributes

TaggedPointer hashesAndChildren_
 Opaque type that contains the hashes array (array of type SHAMapHash) and the children array (array of type std::shared_ptr<SHAMapInnerNode>). More...
 
std::uint32_t fullBelowGen_ = 0
 
std::uint16_t isBranch_ = 0
 
std::atomic< std::uint16_tlock_ = 0
 A bitlock for the children of this node, with one bit per child. More...
 

Detailed Description

Definition at line 41 of file SHAMapInnerNode.h.

Constructor & Destructor Documentation

◆ SHAMapInnerNode() [1/2]

ripple::SHAMapInnerNode::SHAMapInnerNode ( std::uint32_t  cowid,
std::uint8_t  numAllocatedChildren = 2 
)
explicit

Definition at line 38 of file SHAMapInnerNode.cpp.

◆ SHAMapInnerNode() [2/2]

ripple::SHAMapInnerNode::SHAMapInnerNode ( SHAMapInnerNode const &  )
delete

◆ ~SHAMapInnerNode()

ripple::SHAMapInnerNode::~SHAMapInnerNode ( )
default

Member Function Documentation

◆ resizeChildArrays()

void ripple::SHAMapInnerNode::resizeChildArrays ( std::uint8_t  toAllocate)
private

Convert arrays stored in hashesAndChildren_ so they can store the requested number of children.

Parameters
toAllocateallocate space for at least this number of children (must be <= branchFactor)
Note
the arrays may allocate more than the requested value in toAllocate. This is due to the implementation of TagPointer, which only supports allocating arrays of 4 different sizes.

Definition at line 62 of file SHAMapInnerNode.cpp.

◆ getChildIndex()

std::optional< int > ripple::SHAMapInnerNode::getChildIndex ( int  i) const
private

Get the child's index inside the hashes or children array (stored in hashesAndChildren_.

These arrays may or may not be sparse). The optional will be empty is an empty branch is requested and the arrays are sparse.

Parameters
iindex of the requested child

Definition at line 69 of file SHAMapInnerNode.cpp.

◆ iterChildren()

template<class F >
void ripple::SHAMapInnerNode::iterChildren ( F &&  f) const
private

Call the f callback for all 16 (branchFactor) branches - even if the branch is empty.

Parameters
fa one parameter callback function. The parameter is the child's hash.

Definition at line 49 of file SHAMapInnerNode.cpp.

◆ iterNonEmptyChildIndexes()

template<class F >
void ripple::SHAMapInnerNode::iterNonEmptyChildIndexes ( F &&  f) const
private

Call the f callback for all non-empty branches.

Parameters
fa two parameter callback function. The first parameter is the branch number, the second parameter is the index into the array. For dense formats these are the same, for sparse they may be different.

Definition at line 56 of file SHAMapInnerNode.cpp.

◆ operator=()

SHAMapInnerNode& ripple::SHAMapInnerNode::operator= ( SHAMapInnerNode const &  )
delete

◆ clone()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapInnerNode::clone ( std::uint32_t  cowid) const
overridevirtual

Make a copy of this node, setting the owner.

Implements ripple::SHAMapTreeNode.

Definition at line 75 of file SHAMapInnerNode.cpp.

◆ getType()

SHAMapNodeType ripple::SHAMapInnerNode::getType ( ) const
overridevirtual

Determines the type of node.

Implements ripple::SHAMapTreeNode.

Definition at line 120 of file SHAMapInnerNode.h.

◆ isLeaf()

bool ripple::SHAMapInnerNode::isLeaf ( ) const
overridevirtual

Determines if this is a leaf node.

Implements ripple::SHAMapTreeNode.

Definition at line 126 of file SHAMapInnerNode.h.

◆ isInner()

bool ripple::SHAMapInnerNode::isInner ( ) const
overridevirtual

Determines if this is an inner node.

Implements ripple::SHAMapTreeNode.

Definition at line 132 of file SHAMapInnerNode.h.

◆ isEmpty()

bool ripple::SHAMapInnerNode::isEmpty ( ) const

Definition at line 260 of file SHAMapInnerNode.cpp.

◆ isEmptyBranch()

bool ripple::SHAMapInnerNode::isEmptyBranch ( int  m) const

Definition at line 198 of file SHAMapInnerNode.h.

◆ getBranchCount()

int ripple::SHAMapInnerNode::getBranchCount ( ) const

Definition at line 266 of file SHAMapInnerNode.cpp.

◆ getChildHash()

SHAMapHash const & ripple::SHAMapInnerNode::getChildHash ( int  m) const

Definition at line 361 of file SHAMapInnerNode.cpp.

◆ setChild()

void ripple::SHAMapInnerNode::setChild ( int  m,
std::shared_ptr< SHAMapTreeNode child 
)

Definition at line 287 of file SHAMapInnerNode.cpp.

◆ shareChild()

void ripple::SHAMapInnerNode::shareChild ( int  m,
std::shared_ptr< SHAMapTreeNode > const &  child 
)

Definition at line 323 of file SHAMapInnerNode.cpp.

◆ getChildPointer()

SHAMapTreeNode * ripple::SHAMapInnerNode::getChildPointer ( int  branch)

Definition at line 335 of file SHAMapInnerNode.cpp.

◆ getChild()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapInnerNode::getChild ( int  branch)

Definition at line 348 of file SHAMapInnerNode.cpp.

◆ canonicalizeChild()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapInnerNode::canonicalizeChild ( int  branch,
std::shared_ptr< SHAMapTreeNode node 
)

Definition at line 371 of file SHAMapInnerNode.cpp.

◆ isFullBelow()

bool ripple::SHAMapInnerNode::isFullBelow ( std::uint32_t  generation) const

Definition at line 204 of file SHAMapInnerNode.h.

◆ setFullBelowGen()

void ripple::SHAMapInnerNode::setFullBelowGen ( std::uint32_t  gen)

Definition at line 210 of file SHAMapInnerNode.h.

◆ updateHash()

void ripple::SHAMapInnerNode::updateHash ( )
overridevirtual

Recalculate the hash of this node.

Implements ripple::SHAMapTreeNode.

Definition at line 196 of file SHAMapInnerNode.cpp.

◆ updateHashDeep()

void ripple::SHAMapInnerNode::updateHashDeep ( )

Recalculate the hash of all children and this node.

Definition at line 211 of file SHAMapInnerNode.cpp.

◆ serializeForWire()

void ripple::SHAMapInnerNode::serializeForWire ( Serializer ) const
overridevirtual

Serialize the node in a format appropriate for sending over the wire.

Implements ripple::SHAMapTreeNode.

Definition at line 226 of file SHAMapInnerNode.cpp.

◆ serializeWithPrefix()

void ripple::SHAMapInnerNode::serializeWithPrefix ( Serializer ) const
overridevirtual

Serialize the node in a format appropriate for hashing.

Implements ripple::SHAMapTreeNode.

Definition at line 250 of file SHAMapInnerNode.cpp.

◆ getString()

std::string ripple::SHAMapInnerNode::getString ( SHAMapNodeID const &  id) const
overridevirtual

Reimplemented from ripple::SHAMapTreeNode.

Definition at line 272 of file SHAMapInnerNode.cpp.

◆ invariants()

void ripple::SHAMapInnerNode::invariants ( bool  is_root = false) const
overridevirtual

Implements ripple::SHAMapTreeNode.

Definition at line 399 of file SHAMapInnerNode.cpp.

◆ makeFullInner()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapInnerNode::makeFullInner ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
static

Definition at line 126 of file SHAMapInnerNode.cpp.

◆ makeCompressedInner()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapInnerNode::makeCompressedInner ( Slice  data)
static

Definition at line 160 of file SHAMapInnerNode.cpp.

◆ getHash()

SHAMapHash const& ripple::SHAMapTreeNode::getHash ( ) const
inherited

Return the hash of this node.

Definition at line 143 of file SHAMapTreeNode.h.

◆ makeFromPrefix()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapTreeNode::makeFromPrefix ( Slice  rawNode,
SHAMapHash const &  hash 
)
staticinherited

Definition at line 148 of file SHAMapTreeNode.cpp.

◆ makeFromWire()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapTreeNode::makeFromWire ( Slice  rawNode)
staticinherited

Definition at line 116 of file SHAMapTreeNode.cpp.

◆ makeTransaction()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapTreeNode::makeTransaction ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 40 of file SHAMapTreeNode.cpp.

◆ makeAccountState()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapTreeNode::makeAccountState ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 84 of file SHAMapTreeNode.cpp.

◆ makeTransactionWithMeta()

std::shared_ptr< SHAMapTreeNode > ripple::SHAMapTreeNode::makeTransactionWithMeta ( Slice  data,
SHAMapHash const &  hash,
bool  hashValid 
)
staticprivateinherited

Definition at line 55 of file SHAMapTreeNode.cpp.

◆ getCounter()

static auto& ripple::CountedObject< SHAMapInnerNode >::getCounter
staticprivatenoexceptinherited

Definition at line 128 of file CountedObject.h.

Member Data Documentation

◆ branchFactor

constexpr unsigned int ripple::SHAMapInnerNode::branchFactor = 16
staticconstexpr

Each inner node has 16 children (the 'radix tree' part of the map)

Definition at line 46 of file SHAMapInnerNode.h.

◆ hashesAndChildren_

TaggedPointer ripple::SHAMapInnerNode::hashesAndChildren_
private

Opaque type that contains the hashes array (array of type SHAMapHash) and the children array (array of type std::shared_ptr<SHAMapInnerNode>).

Definition at line 53 of file SHAMapInnerNode.h.

◆ fullBelowGen_

std::uint32_t ripple::SHAMapInnerNode::fullBelowGen_ = 0
private

Definition at line 55 of file SHAMapInnerNode.h.

◆ isBranch_

std::uint16_t ripple::SHAMapInnerNode::isBranch_ = 0
private

Definition at line 56 of file SHAMapInnerNode.h.

◆ lock_

std::atomic<std::uint16_t> ripple::SHAMapInnerNode::lock_ = 0
mutableprivate

A bitlock for the children of this node, with one bit per child.

Definition at line 59 of file SHAMapInnerNode.h.

◆ hash_

SHAMapHash ripple::SHAMapTreeNode::hash_
protectedinherited

Definition at line 56 of file SHAMapTreeNode.h.

◆ cowid_

std::uint32_t ripple::SHAMapTreeNode::cowid_
protectedinherited

Determines the owning SHAMap, if any.

Used for copy-on-write semantics.

If this value is 0, the node is not dirty and does not need to be flushed. It is eligible for sharing and may be included multiple SHAMap instances.

Definition at line 64 of file SHAMapTreeNode.h.