rippled
Loading...
Searching...
No Matches
SHAMapInnerNode.h
1#pragma once
2
3#include <xrpl/basics/IntrusivePointer.h>
4#include <xrpl/shamap/SHAMapNodeID.h>
5#include <xrpl/shamap/detail/TaggedPointer.h>
6
7#include <atomic>
8#include <cstdint>
9#include <optional>
10#include <string>
11
12namespace xrpl {
13
14class SHAMapInnerNode final : public SHAMapTreeNode, public CountedObject<SHAMapInnerNode>
15{
16public:
18 static inline constexpr unsigned int branchFactor = 16;
19
20private:
26
29
32
43 void
45
55 getChildIndex(int i) const;
56
63 template <class F>
64 void
65 iterChildren(F&& f) const;
66
74 template <class F>
75 void
76 iterNonEmptyChildIndexes(F&& f) const;
77
78public:
79 explicit SHAMapInnerNode(std::uint32_t cowid, std::uint8_t numAllocatedChildren = 2);
80
83 operator=(SHAMapInnerNode const&) = delete;
85
86 // Needed to support intrusive weak pointers
87 void
88 partialDestructor() override;
89
91 clone(std::uint32_t cowid) const override;
92
94 getType() const override
95 {
97 }
98
99 bool
100 isLeaf() const override
101 {
102 return false;
103 }
104
105 bool
106 isInner() const override
107 {
108 return true;
109 }
110
111 bool
112 isEmpty() const;
113
114 bool
115 isEmptyBranch(int m) const;
116
117 int
118 getBranchCount() const;
119
120 SHAMapHash const&
121 getChildHash(int m) const;
122
123 void
125
126 void
128
130 getChildPointer(int branch);
131
133 getChild(int branch);
134
137
138 // sync functions
139 bool
140 isFullBelow(std::uint32_t generation) const;
141
142 void
144
145 void
146 updateHash() override;
147
149 void
151
152 void
153 serializeForWire(Serializer&) const override;
154
155 void
156 serializeWithPrefix(Serializer&) const override;
157
159 getString(SHAMapNodeID const&) const override;
160
161 void
162 invariants(bool is_root = false) const override;
163
165 makeFullInner(Slice data, SHAMapHash const& hash, bool hashValid);
166
169};
170
171inline bool
173{
174 return isBranch_ == 0;
175}
176
177inline bool
179{
180 return (isBranch_ & (1 << m)) == 0;
181}
182
183inline int
188
189inline bool
191{
192 return fullBelowGen_ == generation;
193}
194
195inline void
200
201} // namespace xrpl
Tracks the number of instances of an object.
void serializeWithPrefix(Serializer &) const override
Serialize the node in a format appropriate for hashing.
void updateHash() override
Recalculate the hash of this node.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFullInner(Slice data, SHAMapHash const &hash, bool hashValid)
bool isFullBelow(std::uint32_t generation) const
TaggedPointer hashesAndChildren_
Opaque type that contains the hashes array (array of type SHAMapHash) and the children array (array o...
static intr_ptr::SharedPtr< SHAMapTreeNode > makeCompressedInner(Slice data)
SHAMapHash const & getChildHash(int m) const
void updateHashDeep()
Recalculate the hash of all children and this node.
void iterNonEmptyChildIndexes(F &&f) const
Call the f callback for all non-empty branches.
SHAMapNodeType getType() const override
Determines the type of node.
void setFullBelowGen(std::uint32_t gen)
SHAMapTreeNode * getChildPointer(int branch)
std::string getString(SHAMapNodeID const &) const override
void iterChildren(F &&f) const
Call the f callback for all 16 (branchFactor) branches - even if the branch is empty.
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
void resizeChildArrays(std::uint8_t toAllocate)
Convert arrays stored in hashesAndChildren_ so they can store the requested number of children.
bool isInner() const override
Determines if this is an inner node.
std::uint32_t fullBelowGen_
void partialDestructor() override
std::atomic< std::uint16_t > lock_
A bitlock for the children of this node, with one bit per child.
intr_ptr::SharedPtr< SHAMapTreeNode > canonicalizeChild(int branch, intr_ptr::SharedPtr< SHAMapTreeNode > node)
bool isLeaf() const override
Determines if this is a leaf node.
void shareChild(int m, intr_ptr::SharedPtr< SHAMapTreeNode > const &child)
intr_ptr::SharedPtr< SHAMapTreeNode > clone(std::uint32_t cowid) const override
Make a copy of this node, setting the owner.
intr_ptr::SharedPtr< SHAMapTreeNode > getChild(int branch)
void setChild(int m, intr_ptr::SharedPtr< SHAMapTreeNode > child)
void serializeForWire(Serializer &) const override
Serialize the node in a format appropriate for sending over the wire.
std::optional< int > getChildIndex(int i) const
Get the child's index inside the hashes or children array (stored in hashesAndChildren_.
SHAMapInnerNode & operator=(SHAMapInnerNode const &)=delete
SHAMapInnerNode(SHAMapInnerNode const &)=delete
void invariants(bool is_root=false) const override
bool isEmptyBranch(int m) const
Identifies a node inside a SHAMap.
A shared intrusive pointer class that supports weak pointers.
An immutable linear range of bytes.
Definition Slice.h:26
TaggedPointer is a combination of a pointer and a mask stored in the lowest two bits.
std::uint32_t cowid() const
Returns the SHAMap that owns this node.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
int popcnt16(std::uint16_t a)