fprime/Fw/DataStructures/RedBlackTreeMap.hpp
Rob Bocchino e9d7f3ab66
Data structure library, phase 2 (#4062)
* 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
2025-10-06 13:26:23 -07:00

137 lines
4.4 KiB
C++

// ======================================================================
// \file RedBlackTreeMap.hpp
// \author bocchino
// \brief An map based on a red-black tree with internal storage
// ======================================================================
#ifndef Fw_RedBlackTreeMap_HPP
#define Fw_RedBlackTreeMap_HPP
#include "Fw/DataStructures/ExternalRedBlackTreeMap.hpp"
namespace Fw {
template <typename K, typename V, FwSizeType C>
class RedBlackTreeMap final : public MapBase<K, V> {
// ----------------------------------------------------------------------
// Static assertions
// ----------------------------------------------------------------------
static_assert(C > 0, "capacity must be greater than zero");
// ----------------------------------------------------------------------
// Friend class for testing
// ----------------------------------------------------------------------
template <typename KK, typename VV, FwSizeType CC>
friend class RedBlackTreeMapTester;
public:
// ----------------------------------------------------------------------
// Public types
// ----------------------------------------------------------------------
//! The type of a const iterator
using ConstIterator = MapConstIterator<K, V>;
//! The type of a tree node
using Node = typename RedBlackTreeSetOrMapImpl<K, V>::Node;
//! The type of the tree node array
using Nodes = Node[C];
//! The type of a tree node index
using Index = typename RedBlackTreeSetOrMapImpl<K, V>::Index;
//! The type of the free node array
using FreeNodes = Index[C];
public:
// ----------------------------------------------------------------------
// Public constructors and destructors
// ----------------------------------------------------------------------
//! Zero-argument constructor
RedBlackTreeMap() : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {}
//! Copy constructor
RedBlackTreeMap(const RedBlackTreeMap<K, V, C>& map) : MapBase<K, V>(), m_extMap(m_nodes, m_freeNodes, C) {
*this = map;
}
//! Destructor
~RedBlackTreeMap() override = default;
public:
// ----------------------------------------------------------------------
// Public member functions
// ----------------------------------------------------------------------
//! operator=
RedBlackTreeMap<K, V, C>& operator=(const RedBlackTreeMap<K, V, C>& map) {
this->m_extMap.copyDataFrom(map);
return *this;
}
//! Get the begin iterator
//! \return The iterator
ConstIterator begin() const override { return this->m_extMap.begin(); }
//! Clear the map
void clear() override { this->m_extMap.clear(); }
//! Get the end iterator
//! \return The iterator
ConstIterator end() const override { return this->m_extMap.end(); }
//! Find a value associated with a key in the map
//! \return SUCCESS if the item was found
Success find(const K& key, //!< The key
V& value //!< The value
) const override {
return this->m_extMap.find(key, value);
}
//! Get the capacity of the map (max number of entries)
//! \return The capacity
FwSizeType getCapacity() const override { return this->m_extMap.getCapacity(); }
//! Get the size (number of entries)
//! \return The size
FwSizeType getSize() const override { return this->m_extMap.getSize(); }
//! Insert a (key, value) pair in the map
//! \return SUCCESS if there is room in the map
Success insert(const K& key, //!< The key
const V& value //!< The value
) override {
return this->m_extMap.insert(key, value);
}
//! Remove a (key, value) pair from the map
//! \return SUCCESS if the key was there
Success remove(const K& key, //!< The key
V& value //!< The value
) override {
return this->m_extMap.remove(key, value);
}
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 map implementation
ExternalRedBlackTreeMap<K, V> m_extMap = {};
};
} // namespace Fw
#endif