| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \file ArraySet.hpp | ||
| 3 | // \author bocchino | ||
| 4 | // \brief An array-based set with internal storage | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #ifndef Fw_ArraySet_HPP | ||
| 8 | #define Fw_ArraySet_HPP | ||
| 9 | |||
| 10 | #include "Fw/DataStructures/ExternalArraySet.hpp" | ||
| 11 | |||
| 12 | namespace Fw { | ||
| 13 | |||
| 14 | template <typename T, FwSizeType C> | ||
| 15 | class ArraySet 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 ArraySetTester; | ||
| 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 an implementation entry | ||
| 38 | using Entry = SetOrMapImplEntry<T, Nil>; | ||
| 39 | |||
| 40 | //! The type of the implementation entries | ||
| 41 | using Entries = Entry[C]; | ||
| 42 | |||
| 43 | public: | ||
| 44 | // ---------------------------------------------------------------------- | ||
| 45 | // Public constructors and destructors | ||
| 46 | // ---------------------------------------------------------------------- | ||
| 47 | |||
| 48 | //! Zero-argument constructor | ||
| 49 |
3/3✓ Branch 12 taken 24 times.
✓ Branch 18 taken 17071 times.
✓ Branch 19 taken 24 times.
|
34008 | ArraySet() : SetBase<T>(), m_extSet(m_entries, C) {} |
| 50 | |||
| 51 | //! Copy constructor | ||
| 52 |
4/8✓ Branch 12 taken 1 times.
✓ Branch 18 taken 1024 times.
✓ Branch 19 taken 1 times.
✓ Branch 25 taken 1 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
|
1025 | ArraySet(const ArraySet<T, C>& set) : SetBase<T>(), m_extSet(m_entries, C) { *this = set; } |
| 53 | |||
| 54 | //! Destructor | ||
| 55 |
3/4✓ Branch 4 taken 25 times.
✗ Branch 5 not taken.
✓ Branch 11 taken 18095 times.
✓ Branch 12 taken 25 times.
|
36240 | ~ArraySet() override = default; |
| 56 | |||
| 57 | public: | ||
| 58 | // ---------------------------------------------------------------------- | ||
| 59 | // Public member functions | ||
| 60 | // ---------------------------------------------------------------------- | ||
| 61 | |||
| 62 | //! operator= | ||
| 63 | 2 | ArraySet<T, C>& operator=(const ArraySet<T, C>& set) { | |
| 64 | 2 | this->m_extSet.copyDataFrom(set); | |
| 65 | 2 | return *this; | |
| 66 | } | ||
| 67 | |||
| 68 | //! Get the begin iterator | ||
| 69 | //! \return The iterator | ||
| 70 | 495 | ConstIterator begin() const override { return this->m_extSet.begin(); } | |
| 71 | |||
| 72 | //! Clear the set | ||
| 73 | 194 | void clear() override { this->m_extSet.clear(); } | |
| 74 | |||
| 75 | //! Get the end iterator | ||
| 76 | //! \return The iterator | ||
| 77 | 161 | ConstIterator end() const override { return this->m_extSet.end(); } | |
| 78 | |||
| 79 | //! Find an element in the set | ||
| 80 | //! \return SUCCESS if the element was found | ||
| 81 | 4880 | Success find(const T& element //!< The element | |
| 82 | ) const override { | ||
| 83 | 4880 | return this->m_extSet.find(element); | |
| 84 | } | ||
| 85 | |||
| 86 | //! Get the capacity of the set (max number of entries) | ||
| 87 | //! \return The capacity | ||
| 88 | 3346 | FwSizeType getCapacity() const override { return this->m_extSet.getCapacity(); } | |
| 89 | |||
| 90 | //! Get the size (number of entries) | ||
| 91 | //! \return The size | ||
| 92 | 12958 | FwSizeType getSize() const override { return this->m_extSet.getSize(); } | |
| 93 | |||
| 94 | //! Insert an element in the set | ||
| 95 | //! \return SUCCESS if there is room in the set | ||
| 96 | 11956 | Success insert(const T& element //!< The element | |
| 97 | ) override { | ||
| 98 | 11956 | return this->m_extSet.insert(element); | |
| 99 | } | ||
| 100 | |||
| 101 | //! Remove an element from the set | ||
| 102 | //! \return SUCCESS if the key was there | ||
| 103 | 337 | Success remove(const T& element //!< The element | |
| 104 | ) override { | ||
| 105 | 337 | return this->m_extSet.remove(element); | |
| 106 | } | ||
| 107 | |||
| 108 | private: | ||
| 109 | // ---------------------------------------------------------------------- | ||
| 110 | // Private member variables | ||
| 111 | // ---------------------------------------------------------------------- | ||
| 112 | |||
| 113 | //! The external set implementation | ||
| 114 | ExternalArraySet<T> m_extSet = {}; | ||
| 115 | |||
| 116 | //! The array providing the backing memory for m_extSet | ||
| 117 | Entries m_entries = {}; | ||
| 118 | }; | ||
| 119 | |||
| 120 | } // namespace Fw | ||
| 121 | |||
| 122 | #endif | ||
| 123 |