F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ExternalRedBlackTreeSet.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file ExternalRedBlackTreeSet.hpp
3 // \author bocchino
4 // \brief An set based on a red-black tree with external storage
5 // ======================================================================
6 
7 #ifndef Fw_ExternalRedBlackTreeSet_HPP
8 #define Fw_ExternalRedBlackTreeSet_HPP
9 
13 #include "Fw/Types/Assert.hpp"
14 
15 namespace Fw {
16 
17 template <typename T>
18 class ExternalRedBlackTreeSet final : public SetBase<T> {
19  // ----------------------------------------------------------------------
20  // Friend class for testing
21  // ----------------------------------------------------------------------
22 
23  template <typename TT>
25 
26  public:
27  // ----------------------------------------------------------------------
28  // Public types
29  // ----------------------------------------------------------------------
30 
33 
36 
39 
40  public:
41  // ----------------------------------------------------------------------
42  // Public constructors and destructors
43  // ----------------------------------------------------------------------
44 
46  ExternalRedBlackTreeSet() = default;
47 
52  Index* freeNodes,
53  FwSizeType capacity
54  )
55  : SetBase<T>() {
56  this->setStorage(nodes, freeNodes, capacity);
57  }
58 
63  FwSizeType capacity
64  )
65  : SetBase<T>() {
66  this->setStorage(data, capacity);
67  }
68 
70  ExternalRedBlackTreeSet(const ExternalRedBlackTreeSet<T>& set) : SetBase<T>() { *this = set; }
71 
73  ~ExternalRedBlackTreeSet() override = default;
74 
75  public:
76  // ----------------------------------------------------------------------
77  // Public member functions
78  // ----------------------------------------------------------------------
79 
82  if (&set != this) {
83  this->m_impl = set.m_impl;
84  }
85  return *this;
86  }
87 
90  ConstIterator begin() const override { return ConstIterator(this->m_impl.begin()); }
91 
93  void clear() override { this->m_impl.clear(); }
94 
97  ConstIterator end() const override { return ConstIterator(this->m_impl.end()); }
98 
101  Success find(const T& element
102  ) const override {
103  Nil nil = {};
104  return this->m_impl.find(element, nil);
105  }
106 
109  FwSizeType getCapacity() const override { return this->m_impl.getCapacity(); }
110 
113  FwSizeType getSize() const override { return this->m_impl.getSize(); }
114 
117  Success insert(const T& element
118  ) override {
119  return this->m_impl.insert(element, Nil());
120  }
121 
124  Success remove(const T& element
125  ) override {
126  Nil nil = {};
127  return this->m_impl.remove(element, nil);
128  }
129 
133  void setStorage(Node* nodes,
134  Index* freeNodes,
135  FwSizeType capacity
136  ) {
137  this->m_impl.setStorage(nodes, freeNodes, capacity);
138  }
139 
143  void setStorage(ByteArray data,
144  FwSizeType capacity
145  ) {
146  this->m_impl.setStorage(data, capacity);
147  }
148 
149  public:
150  // ----------------------------------------------------------------------
151  // Public static functions
152  // ----------------------------------------------------------------------
153 
157 
161  static constexpr FwSizeType getByteArraySize(FwSizeType capacity
162  ) {
164  }
165 
166  private:
167  // ----------------------------------------------------------------------
168  // Private member variables
169  // ----------------------------------------------------------------------
170 
173 };
174 
175 } // namespace Fw
176 
177 #endif
FwSizeType getSize() const override
void setStorage(Node *nodes, Index *freeNodes, FwSizeType capacity)
PlatformSizeType FwSizeType
Success insert(const KE &keyOrElement, const VN &valueOrNil)
Success remove(const KE &keyOrElement, VN &valueOrNil)
ExternalRedBlackTreeSet(ByteArray data, FwSizeType capacity)
Success find(const T &element) const override
FwSizeType getCapacity() const override
ConstIterator begin() const
Get the begin iterator.
SetConstIterator< T > ConstIterator
The type of a const iterator.
ConstIterator end() const override
ExternalRedBlackTreeSet< T > & operator=(const ExternalRedBlackTreeSet< T > &set)
operator=
ExternalRedBlackTreeSet(Node *nodes, Index *freeNodes, FwSizeType capacity)
ExternalRedBlackTreeSet()=default
Zero-argument constructor.
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
ConstIterator begin() const override
A variable-length byte array.
Definition: ByteArray.hpp:23
void clear()
Clear the set or map.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
ExternalRedBlackTreeSet(const ExternalRedBlackTreeSet< T > &set)
Copy constructor.
void clear() override
Clear the set.
typename RedBlackTreeSetOrMapImpl< T, Nil >::Node Node
The type of a tree node.
static constexpr U8 getByteArrayAlignment()
typename RedBlackTreeSetOrMapImpl< T, Nil >::Index Index
The type of a tree node index.
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
ConstIterator end() const
Get the end iterator.
Definition: Nil.hpp:12
void setStorage(ByteArray data, FwSizeType capacity)
Success insert(const T &element) override
Success find(const KE &keyOrElement, VN &valueOrNil) const
~ExternalRedBlackTreeSet() override=default
Destructor.
Success/Failure.
void setStorage(Node *nodes, Index *freeNodes, FwSizeType capacity)