Back to Fprime

ArraySetOrMapImpl

Fw/DataStructures/docs/ArraySetOrMapImpl.md

4.2.25.5 KB
Original Source

ArraySetOrMapImpl

ArraySetOrMapImpl is a final class template defined in Fw/DataStructures. It represents an array-based implementation of a set or map. Internally it maintains an ExternalArray for storing the entries in the set or map.

1. Template Parameters

ArraySetOrMapImpl has the following template parameters.

KindNamePurpose
typenameKEThe type of a key in a map or the element of a set
typenameVNThe type of a value in a map or Nil for set

<a name="Public-Types"></a>

2. Public Types

<a name="Public-Type-Aliases"></a>

2.1. Type Aliases

ArraySetOrMapImpl defines the following type aliases:

NameDefinition
EntryAlias for SetOrMapImplEntry<KE, VN>

2.2. ConstIterator

ConstIterator is a public inner class of ArraySetOrMapImpl. It provides non-modifying iteration over the elements of an ArraySetOrMapImpl instance. It is a base class of SetOrMapImplConstIterator<KE, VN>.

3. Private Member Variables

ArraySetOrMapImpl has the following private member variables.

NameTypePurposeDefault Value
m_entriesExternalArray<Entry>The array for storing the set or map entriesC++ default initialization
m_sizeFwSizeTypeThe number of entries in the set or map0
mermaid
classDiagram
    ArraySetOrMapImpl *-- ExternalArray
    ExternalArray *-- "1..*" Entry

4. Public Constructors and Destructors

4.1. Zero-Argument Constructor

c++
ArraySetOrMapImpl()

Initialize each member variable with its default value.

4.2. Constructor Providing Typed Backing Storage

c++
ArraySetOrMapImpl(Entry* entries, FwSizeType capacity)

Call setStorage(entries, capacity).

4.3. Constructor Providing Untyped Backing Storage

c++
ArraySetOrMapImpl(ByteArray data, FwSizeType capacity)

data must be aligned according to getByteArrayAlignment() and must contain at least getByteArraySize(size) bytes.

Call setStorage(data, capacity).

4.4. Copy Constructor

c++
ArraySetOrMapImpl(const ArraySetOrMapImpl<KE, VN>& map)

Set *this = map.

4.5. Destructor

c++
~ArraySetOrMapImpl()

Defined as = default.

5. Public Member Functions

5.1. operator=

c++
ArraySetOrMapImpl<KE, VN>& operator=(const ArraySetOrMapImpl<KE, VN>& impl)
  1. If &impl != this

    1. Set m_entries = impl.m_entries.

    2. Set m_size = impl.m_size.

  2. Return *this.

5.2. begin

c++
ConstIterator begin() const

Return ConstIterator(*this).

5.3. clear

c++
void clear()

Set m_size = 0.

5.4. end

c++
ConstIterator end() const
  1. Set it = begin().

  2. Call it.setToEnd().

  3. Return it.

5.5. find

c++
Success find(const KE& keyOrElement, VN& valueOrNil) const
  1. Set status = Success::FAILURE.

  2. For i in [0, m_size)

    1. Let const auto& e = m_entries[i].

    2. If e.getKey() == keyOrElement

      1. Set valueOrNil = e.getValue().

      2. Set status = Success::SUCCESS.

      3. Break out of the loop.

  3. Return status.

5.6. getCapacity

c++
FwSizeType getCapacity() const

Return m_entries.getSize().

5.8. getSize

c++
FwSizeType getSize()

Return m_size.

5.9. insert

c++
Success insert(const KE& keyOrElement, const VN& valueOrNil)
  1. Set status = Success::FAILURE.

  2. For i in [0, m_size)

    1. Let auto& e = m_entries[i].

    2. If e.getKey() == keyOrElement

      1. Call e.setValue(valueOrNil).

      2. Set status = Success::SUCCESS.

      3. Break out of the loop

  3. If (status == Success::FAILURE) && (m_size < getCapacity())

    1. Set m_entries[m_size] = Entry(keyOrElement, valueOrNil).

    2. If m_size > 0 then call m_entries[m_size - 1].setNextEntry(&m_entries[m_size]).

    3. Increment m_size.

    4. Set status = Success::SUCCESS.

  4. Return status.

5.10. remove

c++
Success remove(const KE& keyOrElement, VN& valueOrNil)
  1. Set status = Success::FAILURE.

  2. For i in [0, m_size)

    1. If m_entries[i].getKey() == keyOrElement

      1. Set valueOrNil = m_entries[i].getValue().

      2. If i < m_size - 1 then

        1. m_entries[i] = m_entries[m_size - 1].

        2. Call m_entries[i].setNextEntry(&m_entries[i + 1]).

      3. Otherwise call m_entries[i].setNextEntry(nullptr).

      4. Decrement size.

      5. Set status = Success::SUCCESS.

      6. Break out of the loop.

  3. Return status.

5.11. setStorage (Typed Data)

c++
void setStorage(Entry* entries, FwSizeType capacity)
  1. Call m_entries.setStorage(entries, capacity).

  2. Call clear().

5.12. setStorage (Untyped Data)

c++
void setStorage(ByteArray data, FwSizeType capacity)

data must be aligned according to getByteArrayAlignment() and must contain at least getByteArraySize(size) bytes.

  1. Call m_entries.setStorage(data, capacity).

  2. Call clear().

6. Public Static Functions

<a name="getByteArrayAlignment"></a>

6.1. getByteArrayAlignment

c++
static constexpr U8 getByteArrayAlignment()

Return ExternalArray<Entry>::getByteArrayAlignment().

<a name="getByteArraySize"></a>

6.2. getByteArraySize

c++
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)

Return ExternalArray<Entry>::getByteArraySize(capacity).