Fw/DataStructures/docs/ArraySetOrMapImpl.md
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.
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 |
<a name="Public-Types"></a>
<a name="Public-Type-Aliases"></a>
ArraySetOrMapImpl defines the following type aliases:
| Name | Definition |
|---|---|
Entry | Alias for SetOrMapImplEntry<KE, VN> |
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>.
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
ArraySetOrMapImpl()
Initialize each member variable with its default value.
ArraySetOrMapImpl(Entry* entries, FwSizeType capacity)
Call setStorage(entries, capacity).
ArraySetOrMapImpl(ByteArray data, FwSizeType capacity)
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(size) bytes.
Call setStorage(data, capacity).
ArraySetOrMapImpl(const ArraySetOrMapImpl<KE, VN>& map)
Set *this = map.
~ArraySetOrMapImpl()
Defined as = default.
ArraySetOrMapImpl<KE, VN>& operator=(const ArraySetOrMapImpl<KE, VN>& impl)
If &impl != this
Set m_entries = impl.m_entries.
Set m_size = impl.m_size.
Return *this.
ConstIterator begin() const
Return ConstIterator(*this).
void clear()
Set m_size = 0.
ConstIterator end() const
Set it = begin().
Call it.setToEnd().
Return it.
Success find(const KE& keyOrElement, VN& valueOrNil) const
Set status = Success::FAILURE.
For i in [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.
FwSizeType getCapacity() const
Return m_entries.getSize().
FwSizeType getSize()
Return m_size.
Success insert(const KE& keyOrElement, const VN& valueOrNil)
Set status = Success::FAILURE.
For i in [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 > 0 then
call m_entries[m_size - 1].setNextEntry(&m_entries[m_size]).
Increment m_size.
Set status = Success::SUCCESS.
Return status.
Success remove(const KE& keyOrElement, VN& valueOrNil)
Set status = Success::FAILURE.
For i in [0, m_size)
If m_entries[i].getKey() == keyOrElement
Set valueOrNil = m_entries[i].getValue().
If i < m_size - 1 then
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.
void setStorage(Entry* entries, FwSizeType capacity)
Call m_entries.setStorage(entries, capacity).
Call clear().
void setStorage(ByteArray data, FwSizeType capacity)
data must be aligned according to
getByteArrayAlignment() and must
contain at least getByteArraySize(size) bytes.
Call m_entries.setStorage(data, capacity).
Call clear().
<a name="getByteArrayAlignment"></a>
static constexpr U8 getByteArrayAlignment()
Return ExternalArray<Entry>::getByteArrayAlignment().
<a name="getByteArraySize"></a>
static constexpr FwSizeType getByteArraySize(FwSizeType capacity)
Return ExternalArray<Entry>::getByteArraySize(capacity).