fprime/Fw/DataStructures/docs/RedBlackTreeSet.md
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

5.6 KiB

RedBlackTreeSet

RedBlackTreeSet is a final class template defined in Fw/DataStructures. It represents a set based on a red-black tree with internal storage.

1. Template Parameters

RedBlackTreeSet has the following template parameters.

Kind Name Purpose
typename T The type of an element in the set
FwSizeType C The capacity, i.e., the maximum number of elements that the set can store

RedBlackTreeSet statically asserts that C > 0.

2. Base Class

RedBlackTreeSet is publicly derived from SetBase<T>.

3. Public Types

RedBlackTreeSet defines the following public types:

Name Definition
ConstIterator Alias of SetConstIterator<T>
Entry Alias of SetOrMapImplEntry<T, Nil>

The type Nil is defined in this file.

4. Private Member Variables

RedBlackTreeSet has the following private member variables.

Name Type Purpose Default Value
m_extSet ExternalRedBlackTreeSet<T> The external set implementation C++ default initialization
m_entries Entry[C] The array providing the backing memory for m_extSet C++ default initialization

The type Entry is defined in this section.

classDiagram
    RedBlackTreeSet *-- ExternalRedBlackTreeSet

5. Public Constructors and Destructors

5.1. Zero-Argument Constructor

RedBlackTreeSet()

Initialize m_extSet with ExternalRedBlackTreeSet<T>(m_entries, C).

Example:

RedBlackTreeSet<U32, 10> set;

5.2. Copy Constructor

RedBlackTreeSet(const RedBlackTreeSet<T, C>& set)
  1. Initialize m_extSet with ExternalRedBlackTreeSet<T>(m_entries, C).

  2. Set *this = set.

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set s1;
// Insert an item
const U32 element = 42;
const auto status = s1.insert(element);
ASSERT_EQ(status, Success::SUCCESS);
// Call the copy constructor
Set s2;
ASSERT_EQ(s2.getSize(), 1);

5.3. Destructor

~RedBlackTreeSet() override

Defined as = default.

6. Public Member Functions

6.1. operator=

RedBlackTreeSet<T, C>& operator=(const RedBlackTreeSet<T, C>& set)

Return m_extSet.copyDataFrom(set).

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set s1;
// Insert an item
U32 element = 42;
const auto status = s1.insert(element);
ASSERT_EQ(status, Success::SUCCESS);
// Call the default constructor
Set s2;
ASSERT_EQ(s2.getSize(), 0);
// Call the copy assignment operator
s2 = s1;
ASSERT_EQ(s2.getSize(), 1);
status = s2.find(element);
ASSERT_EQ(status, Success::SUCCESS);

6.2. begin

ConstIterator begin() const

Return m_extSet.begin().

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
// Insert an element in the set
const auto status = map.insert(42);
ASSERT_EQ(status, Fw::Success::SUCCESS);
// Get a set const iterator object
auto it = set.begin();
// Use the iterator to access the underlying map const entry
ASSERT_EQ(*it, 42);

6.3. clear

void clear() override

Call m_extSet.clear().

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
const auto status = set.insert(42);
ASSERT_EQ(set.getSize(), 1);
set.clear();
ASSERT_EQ(set.getSize(), 0);

6.4. end

ConstIterator end() const

Return m_extSet.end().

Example:

using Set = RedBlackTreeSet<U32, 10>;
// Call the constructor providing backing storage
Set set;
// Insert an element in the set
auto status = set.insert(42);
ASSERT_EQ(status, Fw::Success::SUCCESS);
// Get a set const iterator object
auto iter = set.begin();
// Check that iter is not at the end
ASSERT_NE(iter, set.end());
// Increment iter
it++;
// Check that iter is at the end
ASSERT_EQ(iter, set.end());

6.5. find

Success find(const K& element, V& value) override

Return m_extSet.find(element).

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
auto status = set.find(42);
ASSERT_EQ(status, Success::FAILURE);
status = set.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
status = set.find(42);
ASSERT_EQ(status, Success::SUCCESS);

6.6. getCapacity

FwSizeType getCapacity() const override

Return m_extSet.getCapacity().

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
ASSERT_EQ(set.getCapacity(), 10);

6.7. getSize

FwSizeType getSize() const override

Return m_extSet.getSize().

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
auto size = set.getSize();
ASSERT_EQ(size, 0);
const auto status = set.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
size = set.getSize();
ASSERT_EQ(size, 1);

6.8. insert

Success insert(const T& element) override

Return m_extSet.insert(element).

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
auto size = set.getSize();
ASSERT_EQ(size, 0);
const auto status = set.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
size = set.getSize();
ASSERT_EQ(size, 1);

6.9. remove

Success remove(const T& element) override

Return m_extSet.remove(element).

Example:

using Set = RedBlackTreeSet<U32, 10>;
Set set;
auto size = set.getSize();
ASSERT_EQ(size, 0);
auto status = set.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
size = set.getSize();
ASSERT_EQ(size, 1);
// Element does not exist
status = set.remove(0);
ASSERT_EQ(status, Success::FAILURE);
ASSERT_EQ(size, 1);
// Element exists
status = set.remove(42);
ASSERT_EQ(status, Success::SUCCESS);
ASSERT_EQ(size, 0);