mirror of
https://github.com/nasa/fprime.git
synced 2025-12-10 00:44:37 -06:00
* Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTree impl * Fix typo * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl docs * Revise RedBlackTree impl docs * Revise RedBlackTree impl * Revise RedBlackTreeImpl docs * Revise Fw/DataStructures Reformat code * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Revise Fw/DataStructures Fix compile errors on Linux * Fix comments * Revise Fw/DataStructures Fix compile errors on Linux * Revise ArrayMap docs * Remove helper scripts * Revise tests for Fw/DataStructures * Fix spelling * Fix Markdown link * Fix uninitialized variable in test * Fix uninitialized variable in test * Fix "spelling" Why is the spelling check enforcing arbitrary rules of style? * Fix comments * Revise RedBlackTree impl docs * Start adding RedBlackTree impl * Revise tests for ArraySetOrMapImpl * Revise RedBlackTree impl * Revise comment * Revise comment * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise ArraySetOrMap impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Add RedBlackTree impl tester * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Fix comments * Revise RedBlackTree impl * Fix comments * Revise comments * Revise comments * Revise comments * Revise statement order for clarity * Revise unit tests for RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Add build and clean scripts Working around regressions in the F Prime build system * Revise build Fix warnings * Revise RedBlackTree impl and tests * Revise tests for RedBlackTree impl * Revise RedBlackTree impl and tests * Revise RedBlackTree tests Remove debug print statements * Revise RedBlackTree impl tester * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise build script * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl test * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise comment * Revise RedBlackTree impl and tests * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise RedBlackTree impl tests * Revise RedBlackTree impl * Revise RedBlackTree impl tests * Revise formatting * Format code * Revise docs * Revise docs for Fw/DataStructures * Revise Array and ExternalArray Add static assertions * Revise FifoQueue and Stack Add static assertions * Revise ArraySet and ArrayMap Add static assertions * Revise docs for ExternalRedBlackTreeMap * Revise docs for ExternalRedBlackTreeSet * Revise docs for RedBlackTreeMap * Revise docs for RedBlackTreeSet * Revise ExternalRedBlackTreeMap tests * Refactor ExternalStackTester * Revise ArrayMap tests * Add RedBlackTreeMap * Revise RedBlackTreeMap tests * Revise RedBlackTreeMap * Add ExternalRedBlackTreeSet * Add missing file * Revise SetConstIterator * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTreeSet tests * Revise ExternalRedBlackTree tests * Revise ExternalArraySet tests * Revise ExternalArraySet tests * Add RedBlackTreeSet * Revise RedBlackTreeSet tests * Refactor ArraySetTest * Revise RedBlackTreeSetOrMapImpl docs * Revise array initialization * Revise comments * Revise Array initialization * Revise Array design and implementation * Revert changes to Fw/DataStructures * Revise Array * Revise Array * Revise Array * Fix formatting * Add SizedContainer base class * Revise StackBase Make it inherit from SizedContainer Revise stack tests * Revise MapBase Make it inherit from SizedContainer Revise tests * Revise SetBase Make it inherit from SizedContainer Revise tests * Revise DataStructures design Add SizedContainer * Revise SDD for DataStructures * Revise DataStructures design * Revise DataStructures design * Revise DataStructures design * Revise DataStructures design * Fix spelling * Revise zero-arg constructor for Array * Revise Array interface Make it consistent with the arrays generated by FPP * Fix to assertion * Format code * Fix spelling * Fix spelling * Add -Wno-comment to suppress warnings for now * Revise comments * Revise diagrams * Fix comment warnings on gcc * Eliminate tabs * Remove utility scripts * Revise placement of break statements * Rename function getParentDirection --> getDirectionFromParent * Add comment * Add svg diagram * Add svg diagram * Add svg files * Revise diagram * Replace png with svg * Replace png with svg * Replace png with svg * Revise comment * Revise SDD for red-black tree * Revise SDD for red-black tree
132 lines
4.2 KiB
C++
132 lines
4.2 KiB
C++
// ======================================================================
|
|
// \file RedBlackTreeSet.hpp
|
|
// \author bocchino
|
|
// \brief An array-based set with internal storage
|
|
// ======================================================================
|
|
|
|
#ifndef Fw_RedBlackTreeSet_HPP
|
|
#define Fw_RedBlackTreeSet_HPP
|
|
|
|
#include "Fw/DataStructures/ExternalRedBlackTreeSet.hpp"
|
|
|
|
namespace Fw {
|
|
|
|
template <typename T, FwSizeType C>
|
|
class RedBlackTreeSet final : public SetBase<T> {
|
|
// ----------------------------------------------------------------------
|
|
// Static assertions
|
|
// ----------------------------------------------------------------------
|
|
|
|
static_assert(C > 0, "capacity must be greater than zero");
|
|
|
|
// ----------------------------------------------------------------------
|
|
// Friend class for testing
|
|
// ----------------------------------------------------------------------
|
|
|
|
template <typename TT, FwSizeType CC>
|
|
friend class RedBlackTreeSetTester;
|
|
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Public types
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! The type of a const iterator
|
|
using ConstIterator = SetConstIterator<T>;
|
|
|
|
//! The type of a tree node
|
|
using Node = typename RedBlackTreeSetOrMapImpl<T, Nil>::Node;
|
|
|
|
//! The type of the tree node array
|
|
using Nodes = Node[C];
|
|
|
|
//! The type of a tree node index
|
|
using Index = typename RedBlackTreeSetOrMapImpl<T, Nil>::Index;
|
|
|
|
//! The type of the free node array
|
|
using FreeNodes = Index[C];
|
|
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Public constructors and destructors
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! Zero-argument constructor
|
|
RedBlackTreeSet() : SetBase<T>(), m_extSet(m_nodes, m_freeNodes, C) {}
|
|
|
|
//! Copy constructor
|
|
RedBlackTreeSet(const RedBlackTreeSet<T, C>& set) : SetBase<T>(), m_extSet(m_nodes, m_freeNodes, C) { *this = set; }
|
|
|
|
//! Destructor
|
|
~RedBlackTreeSet() override = default;
|
|
|
|
public:
|
|
// ----------------------------------------------------------------------
|
|
// Public member functions
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! operator=
|
|
RedBlackTreeSet<T, C>& operator=(const RedBlackTreeSet<T, C>& set) {
|
|
this->m_extSet.copyDataFrom(set);
|
|
return *this;
|
|
}
|
|
|
|
//! Get the begin iterator
|
|
//! \return The iterator
|
|
ConstIterator begin() const override { return this->m_extSet.begin(); }
|
|
|
|
//! Clear the set
|
|
void clear() override { this->m_extSet.clear(); }
|
|
|
|
//! Get the end iterator
|
|
//! \return The iterator
|
|
ConstIterator end() const override { return this->m_extSet.end(); }
|
|
|
|
//! Find an element in the set
|
|
//! \return SUCCESS if the element was found
|
|
Success find(const T& element //!< The element
|
|
) const override {
|
|
return this->m_extSet.find(element);
|
|
}
|
|
|
|
//! Get the capacity of the set (max number of entries)
|
|
//! \return The capacity
|
|
FwSizeType getCapacity() const override { return this->m_extSet.getCapacity(); }
|
|
|
|
//! Get the size (number of entries)
|
|
//! \return The size
|
|
FwSizeType getSize() const override { return this->m_extSet.getSize(); }
|
|
|
|
//! Insert an element in the set
|
|
//! \return SUCCESS if there is room in the set
|
|
Success insert(const T& element //!< The element
|
|
) override {
|
|
return this->m_extSet.insert(element);
|
|
}
|
|
|
|
//! Remove an element from the set
|
|
//! \return SUCCESS if the key was there
|
|
Success remove(const T& element //!< The element
|
|
) override {
|
|
return this->m_extSet.remove(element);
|
|
}
|
|
|
|
private:
|
|
// ----------------------------------------------------------------------
|
|
// Private member variables
|
|
// ----------------------------------------------------------------------
|
|
|
|
//! The array for storing the tree nodes
|
|
Nodes m_nodes = {};
|
|
|
|
//! The array for storing the free node indices
|
|
FreeNodes m_freeNodes = {};
|
|
|
|
//! The external set implementation
|
|
ExternalRedBlackTreeSet<T> m_extSet = {};
|
|
};
|
|
|
|
} // namespace Fw
|
|
|
|
#endif
|