* 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
9.1 KiB
ExternalRedBlackTreeSet
ExternalRedBlackTreeSet is a final class template
defined in Fw/DataStructures.
It represents a set based on a red-black tree with external storage.
Internally it maintains an RedBlackTreeSetOrMapImpl
as the set implementation.
1. Template Parameters
ExternalRedBlackTreeSet has the following template parameters.
| Kind | Name | Purpose |
|---|---|---|
typename |
T |
The type of an element in the set |
2. Base Class
ExternalRedBlackTreeSet is publicly derived from
SetBase<T>.
3. Public Types
ExternalRedBlackTreeSet defines the following public types:
| Name | Definition |
|---|---|
ConstIterator |
Alias of MapConstIterator<T> |
Entry |
Alias of SetOrMapImplEntry<T, Nil> |
The type Nil is defined in this file.
4. Private Member Variables
ExternalRedBlackTreeSet has the following private member variables.
| Name | Type | Purpose | Default Value |
|---|---|---|---|
m_impl |
RedBlackTreeSetOrMapImpl<T, Nil> |
The set implementation | C++ default initialization |
The type Nil is defined in this file.
classDiagram
ExternalRedBlackTreeSet *-- RedBlackTreeSetOrMapImpl
5. Public Constructors and Destructors
5.1. Zero-Argument Constructor
ExternalRedBlackTreeSet()
Initialize each member variable with its default value.
Example:
ExternalRedBlackTreeSet<U32> set;
5.2. Constructor Providing Typed Backing Storage
ExternalRedBlackTreeSet(Entry* entries, FwSizeType capacity)
entries must point to a primitive array of at least capacity
elements of type Entry.
The type Entry is defined in this section.
Call setStorage(entries, capacity).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
5.3. Constructor Providing Untyped Backing Storage
ExternalRedBlackTreeSet(ByteArray data, FwSizeType capacity)
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(capacity) bytes.
Call setStorage(data, capacity).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
constexpr U8 alignment = Set::getByteArrayAlignment();
constexpr FwSizeType byteArraySize = Set::getByteArraySize(capacity);
alignas(alignment) U8 bytes[byteArraySize];
ExternalRedBlackTreeSet<U32> set(ByteArray(&bytes[0], sizeof bytes), capacity);
5.4. Copy Constructor
ExternalRedBlackTreeSet(const ExternalRedBlackTreeSet<T>& set)
Set *this = set.
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 3;
Set::Entry entries[capacity];
// Call the constructor providing backing storage
Set m1(entries, capacity);
// Insert an item
const auto status = m1.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
// Call the copy constructor
Set m2(m1);
ASSERT_EQ(m2.getSize(), 1);
5.5. Destructor
~ExternalRedBlackTreeSet() override
Defined as = default.
6. Public Member Functions
6.1. operator=
ExternalRedBlackTreeSet<T>& operator=(const ExternalRedBlackTreeSet<T>& set)
-
If
&set != this- Set
m_impl = set.m_impl.
- Set
-
Return
*this.
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 3;
Set::Entry entries[capacity];
// Call the constructor providing backing storage
Set m1(entries, capacity);
// Insert an item
const auto status = m1.insert(42);
ASSERT_EQ(status, Success::SUCCESS);
// Call the default constructor
Set m2;
ASSERT_EQ(m2.getSize(), 0);
// Call the copy assignment operator
m2 = m1;
ASSERT_EQ(m2.getSize(), 1);
6.2. begin
ConstIterator begin() const
Return m_impl.begin().
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
// Call the constructor providing backing storage
Set set(entries, capacity);
// Insert an entry in the set
const auto status = set.insert(42);
ASSERT_EQ(status, Fw::Success::SUCCESS);
// Get a set const iterator object
auto it = set.begin();
// Use the iterator to access the element
ASSERT_EQ(*it, 42);
6.3. clear
void clear() override
Call m_impl.clear().
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
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_impl.end().
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
// Call the constructor providing backing storage
Set set(entries, capacity);
// Insert an entry 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 T& element) override
-
Set
Nil nil = {}. -
Return
m_impl.find(key, nil).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
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_impl.getCapacity().
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
ASSERT_EQ(set.getCapacity(), capacity);
6.8. getSize
FwSizeType getSize() const override
Return m_impl.getSize().
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
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. insert
Success insert(const T& element) override
Return m_impl.insert(key, Nil()).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
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.10. remove
Success remove(const T& element) override
-
Set
Nil nil = {}. -
Return
m_impl.remove(key, nil).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set::Entry entries[capacity];
Set set(entries, capacity);
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);
6.11. setStorage (Typed Data)
void setStorage(Entry* entries, FwSizeType capacity)
entries must point to a primitive array of at least capacity
elements of type Entry.
The type Entry is defined in this section.
Call m_impl.setStorage(entries, capacity).
Example:
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
Set set;
Set::Entry entries[capacity];
set.setStorage(entries, capacity);
6.12. setStorage (Untyped Data)
void setStorage(ByteArray data, FwSizeType capacity)
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(capacity) bytes.
-
Call
m_entries.setStorage(data, capacity). -
Call
clear().
using Set = ExternalRedBlackTreeSet<U32>;
constexpr FwSizeType capacity = 10;
constexpr U8 alignment = Set::getByteArrayAlignment();
constexpr FwSizeType byteArraySize = Set::getByteArraySize(capacity);
alignas(alignment) U8 bytes[byteArraySize];
Set set;
set.setStorage(ByteArray(&bytes[0], sizeof bytes), capacity);
7. Public Static Functions
7.1. getByteArrayAlignment
static constexpr U8 getByteArrayAlignment()
Return RedBlackTreeSetOrMapImpl<Entry>::getByteArrayAlignment().
7.2. getByteArraySize
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
Return RedBlackTreeSetOrMapImpl<Entry>::getByteArraySize(capacity).