F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
RedBlackTreeMap.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \file RedBlackTreeMap.hpp
3 // \author bocchino
4 // \brief An map based on a red-black tree with internal storage
5 // ======================================================================
6 
7 #ifndef Fw_RedBlackTreeMap_HPP
8 #define Fw_RedBlackTreeMap_HPP
9 
11 
12 namespace Fw {
13 
14 template <typename K, typename V, FwSizeType C>
15 class RedBlackTreeMap final : public MapBase<K, V> {
16  // ----------------------------------------------------------------------
17  // Static assertions
18  // ----------------------------------------------------------------------
19 
20  static_assert(C > 0, "capacity must be greater than zero");
21 
22  // ----------------------------------------------------------------------
23  // Friend class for testing
24  // ----------------------------------------------------------------------
25 
26  template <typename KK, typename VV, FwSizeType CC>
27  friend class RedBlackTreeMapTester;
28 
29  public:
30  // ----------------------------------------------------------------------
31  // Public types
32  // ----------------------------------------------------------------------
33 
36 
39 
41  using Nodes = Node[C];
42 
45 
47  using FreeNodes = Index[C];
48 
49  public:
50  // ----------------------------------------------------------------------
51  // Public constructors and destructors
52  // ----------------------------------------------------------------------
53 
55  RedBlackTreeMap() : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {}
56 
58  RedBlackTreeMap(const RedBlackTreeMap<K, V, C>& map) : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {
59  *this = map;
60  }
61 
63  ~RedBlackTreeMap() override = default;
64 
65  public:
66  // ----------------------------------------------------------------------
67  // Public member functions
68  // ----------------------------------------------------------------------
69 
72  this->m_extMap.copyDataFrom(map);
73  return *this;
74  }
75 
78  ConstIterator begin() const override { return this->m_extMap.begin(); }
79 
81  void clear() override { this->m_extMap.clear(); }
82 
85  ConstIterator end() const override { return this->m_extMap.end(); }
86 
89  Success find(const K& key,
90  V& value
91  ) const override {
92  return this->m_extMap.find(key, value);
93  }
94 
97  FwSizeType getCapacity() const override { return this->m_extMap.getCapacity(); }
98 
101  FwSizeType getSize() const override { return this->m_extMap.getSize(); }
102 
105  Success insert(const K& key,
106  const V& value
107  ) override {
108  return this->m_extMap.insert(key, value);
109  }
110 
113  Success remove(const K& key,
114  V& value
115  ) override {
116  return this->m_extMap.remove(key, value);
117  }
118 
119  private:
120  // ----------------------------------------------------------------------
121  // Private member variables
122  // ----------------------------------------------------------------------
123 
125  Nodes m_nodes = {};
126 
128  FreeNodes m_freeNodes = {};
129 
131  ExternalRedBlackTreeMap<K, V> m_extMap = {};
132 };
133 
134 } // namespace Fw
135 
136 #endif
~RedBlackTreeMap() override=default
Destructor.
ConstIterator end() const override
PlatformSizeType FwSizeType
RedBlackTreeMap< K, V, C > & operator=(const RedBlackTreeMap< K, V, C > &map)
operator=
typename RedBlackTreeSetOrMapImpl< K, V >::Index Index
The type of a tree node index.
FwSizeType getSize() const override
Success find(const K &key, V &value) const override
RedBlackTreeMap(const RedBlackTreeMap< K, V, C > &map)
Copy constructor.
Node[C] Nodes
The type of the tree node array.
FwSizeType getCapacity() const override
Index[C] FreeNodes
The type of the free node array.
RedBlackTreeMap()
Zero-argument constructor.
void clear() override
Clear the map.
ConstIterator begin() const override
friend class RedBlackTreeMapTester
Success insert(const K &key, const V &value) override
Success/Failure.
typename RedBlackTreeSetOrMapImpl< K, V >::Node Node
The type of a tree node.