F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ExternalRedBlackTreeMap.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file ExternalRedBlackTreeMap.hpp
3 // \author bocchino
4 // \brief A map based on a red-black tree with external storage
5 // ======================================================================
6 
7 #ifndef Fw_ExternalRedBlackTreeMap_HPP
8 #define Fw_ExternalRedBlackTreeMap_HPP
9 
12 #include "Fw/Types/Assert.hpp"
13 
14 namespace Fw {
15 
16 template <typename K, typename V>
17 class ExternalRedBlackTreeMap final : public MapBase<K, V> {
18  // ----------------------------------------------------------------------
19  // Friend class for testing
20  // ----------------------------------------------------------------------
21 
22  template <typename KK, typename VV>
24 
25  public:
26  // ----------------------------------------------------------------------
27  // Public types
28  // ----------------------------------------------------------------------
29 
32 
35 
38 
39  public:
40  // ----------------------------------------------------------------------
41  // Public constructors and destructors
42  // ----------------------------------------------------------------------
43 
45  ExternalRedBlackTreeMap() = default;
46 
51  Index* freeNodes,
52  FwSizeType capacity
53  )
54  : MapBase<K, V>() {
55  this->setStorage(nodes, freeNodes, capacity);
56  }
57 
62  FwSizeType capacity
63  )
64  : MapBase<K, V>() {
65  this->setStorage(data, capacity);
66  }
67 
69  ExternalRedBlackTreeMap(const ExternalRedBlackTreeMap<K, V>& map) : MapBase<K, V>() { *this = map; }
70 
72  ~ExternalRedBlackTreeMap() override = default;
73 
74  public:
75  // ----------------------------------------------------------------------
76  // Public member functions
77  // ----------------------------------------------------------------------
78 
81  if (&map != this) {
82  this->m_impl = map.m_impl;
83  }
84  return *this;
85  }
86 
89  ConstIterator begin() const override { return ConstIterator(this->m_impl.begin()); }
90 
92  void clear() override { this->m_impl.clear(); }
93 
96  ConstIterator end() const override { return ConstIterator(this->m_impl.end()); }
97 
100  Success find(const K& key,
101  V& value
102  ) const override {
103  return this->m_impl.find(key, value);
104  }
105 
108  FwSizeType getCapacity() const override { return this->m_impl.getCapacity(); }
109 
112  FwSizeType getSize() const override { return this->m_impl.getSize(); }
113 
116  Success insert(const K& key,
117  const V& value
118  ) override {
119  return this->m_impl.insert(key, value);
120  }
121 
124  Success remove(const K& key,
125  V& value
126  ) override {
127  return this->m_impl.remove(key, value);
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 
172  RedBlackTreeSetOrMapImpl<K, V> m_impl = {};
173 };
174 
175 } // namespace Fw
176 
177 #endif
MapConstIterator< K, V > ConstIterator
The type of a const iterator.
ExternalRedBlackTreeMap< K, V > & operator=(const ExternalRedBlackTreeMap< K, V > &map)
operator=
FwSizeType getSize() const override
void setStorage(ByteArray data, FwSizeType capacity)
ConstIterator begin() const override
~ExternalRedBlackTreeMap() override=default
Destructor.
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
PlatformSizeType FwSizeType
Success insert(const KE &keyOrElement, const VN &valueOrNil)
Success remove(const KE &keyOrElement, VN &valueOrNil)
typename RedBlackTreeSetOrMapImpl< K, V >::Node Node
The type of a tree node.
ConstIterator end() const override
ExternalRedBlackTreeMap(const ExternalRedBlackTreeMap< K, V > &map)
Copy constructor.
ConstIterator begin() const
Get the begin iterator.
void setStorage(Node *nodes, Index *freeNodes, FwSizeType capacity)
typename RedBlackTreeSetOrMapImpl< K, V >::Index Index
The type of a tree node index.
ExternalRedBlackTreeMap(ByteArray data, FwSizeType capacity)
A variable-length byte array.
Definition: ByteArray.hpp:23
static constexpr U8 getByteArrayAlignment()
void clear()
Clear the set or map.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
FwSizeType getCapacity() const override
Success find(const K &key, V &value) const override
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
ConstIterator end() const
Get the end iterator.
ExternalRedBlackTreeMap()=default
Zero-argument constructor.
Success find(const KE &keyOrElement, VN &valueOrNil) const
ExternalRedBlackTreeMap(Node *nodes, Index *freeNodes, FwSizeType capacity)
Success/Failure.
Success insert(const K &key, const V &value) override
void clear() override
Clear the map.
void setStorage(Node *nodes, Index *freeNodes, FwSizeType capacity)