rippled
Loading...
Searching...
No Matches
SHAMapInnerNode.h
1#ifndef XRPL_SHAMAP_SHAMAPINNERNODE_H_INCLUDED
2#define XRPL_SHAMAP_SHAMAPINNERNODE_H_INCLUDED
3
4#include <xrpl/basics/IntrusivePointer.h>
5#include <xrpl/shamap/SHAMapNodeID.h>
6#include <xrpl/shamap/detail/TaggedPointer.h>
7
8#include <atomic>
9#include <cstdint>
10#include <optional>
11#include <string>
12
13namespace ripple {
14
15class SHAMapInnerNode final : public SHAMapTreeNode,
16 public CountedObject<SHAMapInnerNode>
17{
18public:
20 static inline constexpr unsigned int branchFactor = 16;
21
22private:
28
31
34
45 void
47
57 getChildIndex(int i) const;
58
65 template <class F>
66 void
67 iterChildren(F&& f) const;
68
76 template <class F>
77 void
78 iterNonEmptyChildIndexes(F&& f) const;
79
80public:
81 explicit SHAMapInnerNode(
83 std::uint8_t numAllocatedChildren = 2);
84
87 operator=(SHAMapInnerNode const&) = delete;
89
90 // Needed to support intrusive weak pointers
91 void
92 partialDestructor() override;
93
95 clone(std::uint32_t cowid) const override;
96
98 getType() const override
99 {
101 }
102
103 bool
104 isLeaf() const override
105 {
106 return false;
107 }
108
109 bool
110 isInner() const override
111 {
112 return true;
113 }
114
115 bool
116 isEmpty() const;
117
118 bool
119 isEmptyBranch(int m) const;
120
121 int
122 getBranchCount() const;
123
124 SHAMapHash const&
125 getChildHash(int m) const;
126
127 void
129
130 void
132
134 getChildPointer(int branch);
135
137 getChild(int branch);
138
141
142 // sync functions
143 bool
144 isFullBelow(std::uint32_t generation) const;
145
146 void
148
149 void
150 updateHash() override;
151
153 void
155
156 void
157 serializeForWire(Serializer&) const override;
158
159 void
160 serializeWithPrefix(Serializer&) const override;
161
163 getString(SHAMapNodeID const&) const override;
164
165 void
166 invariants(bool is_root = false) const override;
167
169 makeFullInner(Slice data, SHAMapHash const& hash, bool hashValid);
170
173};
174
175inline bool
177{
178 return isBranch_ == 0;
179}
180
181inline bool
183{
184 return (isBranch_ & (1 << m)) == 0;
185}
186
187inline int
192
193inline bool
195{
196 return fullBelowGen_ == generation;
197}
198
199inline void
204
205} // namespace ripple
206#endif
Tracks the number of instances of an object.
bool isInner() const override
Determines if this is an inner node.
std::optional< int > getChildIndex(int i) const
Get the child's index inside the hashes or children array (stored in hashesAndChildren_.
void setChild(int m, intr_ptr::SharedPtr< SHAMapTreeNode > child)
static intr_ptr::SharedPtr< SHAMapTreeNode > makeCompressedInner(Slice data)
intr_ptr::SharedPtr< SHAMapTreeNode > clone(std::uint32_t cowid) const override
Make a copy of this node, setting the owner.
static constexpr unsigned int branchFactor
Each inner node has 16 children (the 'radix tree' part of the map)
bool isFullBelow(std::uint32_t generation) const
bool isEmptyBranch(int m) const
void iterNonEmptyChildIndexes(F &&f) const
Call the f callback for all non-empty branches.
void serializeWithPrefix(Serializer &) const override
Serialize the node in a format appropriate for hashing.
void iterChildren(F &&f) const
Call the f callback for all 16 (branchFactor) branches - even if the branch is empty.
void resizeChildArrays(std::uint8_t toAllocate)
Convert arrays stored in hashesAndChildren_ so they can store the requested number of children.
bool isLeaf() const override
Determines if this is a leaf node.
void updateHash() override
Recalculate the hash of this node.
intr_ptr::SharedPtr< SHAMapTreeNode > getChild(int branch)
void partialDestructor() override
void shareChild(int m, intr_ptr::SharedPtr< SHAMapTreeNode > const &child)
SHAMapHash const & getChildHash(int m) const
void invariants(bool is_root=false) const override
std::string getString(SHAMapNodeID const &) const override
intr_ptr::SharedPtr< SHAMapTreeNode > canonicalizeChild(int branch, intr_ptr::SharedPtr< SHAMapTreeNode > node)
SHAMapInnerNode & operator=(SHAMapInnerNode const &)=delete
SHAMapInnerNode(SHAMapInnerNode const &)=delete
TaggedPointer hashesAndChildren_
Opaque type that contains the hashes array (array of type SHAMapHash) and the children array (array o...
void setFullBelowGen(std::uint32_t gen)
void serializeForWire(Serializer &) const override
Serialize the node in a format appropriate for sending over the wire.
SHAMapNodeType getType() const override
Determines the type of node.
void updateHashDeep()
Recalculate the hash of all children and this node.
SHAMapTreeNode * getChildPointer(int branch)
std::atomic< std::uint16_t > lock_
A bitlock for the children of this node, with one bit per child.
static intr_ptr::SharedPtr< SHAMapTreeNode > makeFullInner(Slice data, SHAMapHash const &hash, bool hashValid)
Identifies a node inside a SHAMap.
A shared intrusive pointer class that supports weak pointers.
An immutable linear range of bytes.
Definition Slice.h:27
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:6
int popcnt16(std::uint16_t a)