GCC Code Coverage Report


Directory: ./
File: Fw/DataStructures/RedBlackTreeMap.hpp
Date: 2026-09-03 21:13:48
Exec Total Coverage
Lines: 19 19 100.0%
Functions: 33 50 66.0%
Branches: 10 17 58.8%

Line Branch Exec Source
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
10 #include "Fw/DataStructures/ExternalRedBlackTreeMap.hpp"
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
34 //! The type of a const iterator
35 using ConstIterator = MapConstIterator<K, V>;
36
37 //! The type of a tree node
38 using Node = typename RedBlackTreeSetOrMapImpl<K, V>::Node;
39
40 //! The type of the tree node array
41 using Nodes = Node[C];
42
43 //! The type of a tree node index
44 using Index = typename RedBlackTreeSetOrMapImpl<K, V>::Index;
45
46 //! The type of the free node array
47 using FreeNodes = Index[C];
48
49 public:
50 // ----------------------------------------------------------------------
51 // Public constructors and destructors
52 // ----------------------------------------------------------------------
53
54 //! Zero-argument constructor
55
3/7
✓ Branch 18 taken 21808 times.
✓ Branch 19 taken 47 times.
✓ Branch 33 taken 47 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
38768 RedBlackTreeMap() : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {}
56
57 //! Copy constructor
58
3/5
✓ Branch 18 taken 1024 times.
✓ Branch 19 taken 1 times.
✓ Branch 33 taken 1 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
1025 RedBlackTreeMap(const RedBlackTreeMap<K, V, C>& map) : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {
59
1/1
✓ Branch 4 taken 1 times.
1 *this = map;
60 1 }
61
62 //! Destructor
63
3/4
✓ Branch 10 taken 48 times.
✗ Branch 11 not taken.
✓ Branch 17 taken 22832 times.
✓ Branch 18 taken 48 times.
45760 ~RedBlackTreeMap() override = default;
64
65 public:
66 // ----------------------------------------------------------------------
67 // Public member functions
68 // ----------------------------------------------------------------------
69
70 //! operator=
71 2 RedBlackTreeMap<K, V, C>& operator=(const RedBlackTreeMap<K, V, C>& map) {
72 2 this->m_extMap.copyDataFrom(map);
73 2 return *this;
74 }
75
76 //! Get the begin iterator
77 //! \return The iterator
78 574 ConstIterator begin() const override { return this->m_extMap.begin(); }
79
80 //! Clear the map
81 207 void clear() override { this->m_extMap.clear(); }
82
83 //! Get the end iterator
84 //! \return The iterator
85 204 ConstIterator end() const override { return this->m_extMap.end(); }
86
87 //! Find a value associated with a key in the map
88 //! \return SUCCESS if the item was found
89 5161 Success find(const K& key, //!< The key
90 V& value //!< The value
91 ) const override {
92 5161 return this->m_extMap.find(key, value);
93 }
94
95 //! Get the capacity of the map (max number of entries)
96 //! \return The capacity
97 3396 FwSizeType getCapacity() const override { return this->m_extMap.getCapacity(); }
98
99 //! Get the size (number of entries)
100 //! \return The size
101 13035 FwSizeType getSize() const override { return this->m_extMap.getSize(); }
102
103 //! Insert a (key, value) pair in the map
104 //! \return SUCCESS if there is room in the map
105 12088 Success insert(const K& key, //!< The key
106 const V& value //!< The value
107 ) override {
108 12088 return this->m_extMap.insert(key, value);
109 }
110
111 //! Remove a (key, value) pair from the map
112 //! \return SUCCESS if the key was there
113 305 Success remove(const K& key, //!< The key
114 V& value //!< The value
115 ) override {
116 305 return this->m_extMap.remove(key, value);
117 }
118
119 private:
120 // ----------------------------------------------------------------------
121 // Private member variables
122 // ----------------------------------------------------------------------
123
124 //! The array for storing the tree nodes
125 Nodes m_nodes = {};
126
127 //! The array for storing the free node indices
128 FreeNodes m_freeNodes = {};
129
130 //! The external map implementation
131 ExternalRedBlackTreeMap<K, V> m_extMap = {};
132 };
133
134 } // namespace Fw
135
136 #endif
137