GCC Code Coverage Report


Directory: Fw/DataStructures/
File: RedBlackTreeSet.hpp
Date: 2026-09-03 21:14:50
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 17 20 85.0%
Branches: 10 19 52.6%

Line Branch Exec Source
1 // ======================================================================
2 // \file RedBlackTreeSet.hpp
3 // \author bocchino
4 // \brief An array-based set with internal storage
5 // ======================================================================
6
7 #ifndef Fw_RedBlackTreeSet_HPP
8 #define Fw_RedBlackTreeSet_HPP
9
10 #include "Fw/DataStructures/ExternalRedBlackTreeSet.hpp"
11
12 namespace Fw {
13
14 template <typename T, FwSizeType C>
15 class RedBlackTreeSet final : public SetBase<T> {
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 TT, FwSizeType CC>
27 friend class RedBlackTreeSetTester;
28
29 public:
30 // ----------------------------------------------------------------------
31 // Public types
32 // ----------------------------------------------------------------------
33
34 //! The type of a const iterator
35 using ConstIterator = SetConstIterator<T>;
36
37 //! The type of a tree node
38 using Node = typename RedBlackTreeSetOrMapImpl<T, Nil>::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<T, Nil>::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 16896 times.
✓ Branch 19 taken 17 times.
✓ Branch 33 taken 17 times.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
33826 RedBlackTreeSet() : SetBase<T>(), m_extSet(m_nodes, m_freeNodes, C) {}
56
57 //! Copy constructor
58
4/8
✓ Branch 18 taken 1024 times.
✓ Branch 19 taken 1 times.
✓ Branch 33 taken 1 times.
✓ Branch 39 taken 1 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 56 not taken.
✗ Branch 57 not taken.
1025 RedBlackTreeSet(const RedBlackTreeSet<T, C>& set) : SetBase<T>(), m_extSet(m_nodes, m_freeNodes, C) { *this = set; }
59
60 //! Destructor
61
3/4
✓ Branch 10 taken 18 times.
✗ Branch 11 not taken.
✓ Branch 17 taken 17920 times.
✓ Branch 18 taken 18 times.
35876 ~RedBlackTreeSet() override = default;
62
63 public:
64 // ----------------------------------------------------------------------
65 // Public member functions
66 // ----------------------------------------------------------------------
67
68 //! operator=
69 2 RedBlackTreeSet<T, C>& operator=(const RedBlackTreeSet<T, C>& set) {
70 2 this->m_extSet.copyDataFrom(set);
71 2 return *this;
72 }
73
74 //! Get the begin iterator
75 //! \return The iterator
76 520 ConstIterator begin() const override { return this->m_extSet.begin(); }
77
78 //! Clear the set
79 188 void clear() override { this->m_extSet.clear(); }
80
81 //! Get the end iterator
82 //! \return The iterator
83 136 ConstIterator end() const override { return this->m_extSet.end(); }
84
85 //! Find an element in the set
86 //! \return SUCCESS if the element was found
87 4788 Success find(const T& element //!< The element
88 ) const override {
89 4788 return this->m_extSet.find(element);
90 }
91
92 //! Get the capacity of the set (max number of entries)
93 //! \return The capacity
94 3356 FwSizeType getCapacity() const override { return this->m_extSet.getCapacity(); }
95
96 //! Get the size (number of entries)
97 //! \return The size
98 12792 FwSizeType getSize() const override { return this->m_extSet.getSize(); }
99
100 //! Insert an element in the set
101 //! \return SUCCESS if there is room in the set
102 11942 Success insert(const T& element //!< The element
103 ) override {
104 11942 return this->m_extSet.insert(element);
105 }
106
107 //! Remove an element from the set
108 //! \return SUCCESS if the key was there
109 286 Success remove(const T& element //!< The element
110 ) override {
111 286 return this->m_extSet.remove(element);
112 }
113
114 private:
115 // ----------------------------------------------------------------------
116 // Private member variables
117 // ----------------------------------------------------------------------
118
119 //! The array for storing the tree nodes
120 Nodes m_nodes = {};
121
122 //! The array for storing the free node indices
123 FreeNodes m_freeNodes = {};
124
125 //! The external set implementation
126 ExternalRedBlackTreeSet<T> m_extSet = {};
127 };
128
129 } // namespace Fw
130
131 #endif
132