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.
| Kind | Name | Purpose |
|---|---|---|
typename |
KE |
The type of a key in a map or the element of a set |
typename |
VN |
The type of a value in a map or Nil for set |
2. Public Types
2.1. Type Aliases
ArraySetOrMapImpl defines the following type aliases:
| Name | Definition |
|---|---|
Entry |
Alias 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.
| Name | Type | Purpose | Default Value |
|---|---|---|---|
m_entries |
ExternalArray<Entry> |
The array for storing the set or map entries | C++ default initialization |
m_size |
FwSizeType |
The number of entries in the set or map | 0 |
classDiagram
ArraySetOrMapImpl *-- ExternalArray
ExternalArray *-- "1..*" Entry
4. Public Constructors and Destructors
4.1. Zero-Argument Constructor
Initialize each member variable with its default value.
4.2. Constructor Providing Typed Backing Storage
Call setStorage(entries, capacity).
4.3. Constructor Providing Untyped Backing Storage
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(size) bytes.
Call setStorage(data, capacity).
4.4. Copy Constructor
Set *this = map.
4.5. Destructor
Defined as = default.
5. Public Member Functions
5.1. operator=
-
If
&impl != this-
Set
m_entries = impl.m_entries. -
Set
m_size = impl.m_size.
-
-
Return
*this.
5.2. begin
Return ConstIterator(*this).
5.3. clear
Set m_size = 0.
5.4. end
-
Set
it = begin(). -
Call
it.setToEnd(). -
Return
it.
5.5. find
-
Set
status = Success::FAILURE. -
For
iin[0, m_size)-
Let
const auto& e = m_entries[i]. -
If
e.getKey() == keyOrElement-
Set
valueOrNil = e.getValue(). -
Set
status = Success::SUCCESS. -
Break out of the loop.
-
-
-
Return
status.
5.6. getCapacity
Return m_entries.getSize().
5.8. getSize
Return m_size.
5.9. insert
-
Set
status = Success::FAILURE. -
For
iin[0, m_size)-
Let
auto& e = m_entries[i]. -
If
e.getKey() == keyOrElement-
Call
e.setValue(valueOrNil). -
Set
status = Success::SUCCESS. -
Break out of the loop
-
-
-
If
(status == Success::FAILURE) && (m_size < getCapacity())-
Set
m_entries[m_size] = Entry(keyOrElement, valueOrNil). -
If
m_size > 0then callm_entries[m_size - 1].setNextEntry(&m_entries[m_size]). -
Increment
m_size. -
Set
status = Success::SUCCESS.
-
-
Return
status.
5.10. remove
-
Set
status = Success::FAILURE. -
For
iin[0, m_size)-
If
m_entries[i].getKey() == keyOrElement-
Set
valueOrNil = m_entries[i].getValue(). -
If
i < m_size - 1then-
m_entries[i] = m_entries[m_size - 1]. -
Call
m_entries[i].setNextEntry(&m_entries[i + 1]).
-
-
Otherwise call
m_entries[i].setNextEntry(nullptr). -
Decrement
size. -
Set
status = Success::SUCCESS. -
Break out of the loop.
-
-
-
Return
status.
5.11. setStorage (Typed Data)
-
Call
m_entries.setStorage(entries, capacity). -
Call
clear().
5.12. setStorage (Untyped Data)
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(size) bytes.
-
Call
m_entries.setStorage(data, capacity). -
Call
clear().
6. Public Static Functions
6.1. getByteArrayAlignment
Return ExternalArray<Entry>::getByteArrayAlignment().
6.2. getByteArraySize
Return ExternalArray<Entry>::getByteArraySize(capacity).