3#include <Foundation/Containers/DynamicArray.h>
12template <
typename KEY,
typename VALUE>
23 PL_DETECT_TYPE_CLASS(KEY, VALUE);
25 PL_ALWAYS_INLINE
bool operator<(
const Pair& rhs)
const {
return key < rhs.key; }
27 PL_ALWAYS_INLINE
bool operator==(
const Pair& rhs)
const {
return key == rhs.key; }
50 template <
typename CompatibleKeyType,
typename CompatibleValueType>
51 plUInt32
Insert(CompatibleKeyType&& key, CompatibleValueType&& value);
58 template <
typename CompatibleKeyType>
59 plUInt32
Find(
const CompatibleKeyType& key)
const;
64 template <
typename CompatibleKeyType>
65 plUInt32
LowerBound(
const CompatibleKeyType& key)
const;
70 template <
typename CompatibleKeyType>
71 plUInt32
UpperBound(
const CompatibleKeyType& key)
const;
74 const KEY&
GetKey(plUInt32 uiIndex)
const;
77 const VALUE&
GetValue(plUInt32 uiIndex)
const;
89 template <
typename CompatibleKeyType>
90 VALUE&
FindOrAdd(
const CompatibleKeyType& key,
bool* out_pExisted =
nullptr);
93 template <
typename CompatibleKeyType>
112 template <
typename CompatibleKeyType>
113 bool RemoveAndCopy(
const CompatibleKeyType& key,
bool bKeepSorted =
false);
116 template <
typename CompatibleKeyType>
120 template <
typename CompatibleKeyType>
121 bool Contains(
const CompatibleKeyType& key,
const VALUE& value)
const;
136 using const_iterator =
typename plDynamicArray<Pair>::const_iterator;
138 using iterator =
typename plDynamicArray<Pair>::iterator;
142 mutable bool m_bSorted;
147template <
typename KEY,
typename VALUE,
typename AllocatorWrapper = plDefaultAllocatorWrapper>
150 PL_DECLARE_MEM_RELOCATABLE_TYPE();
164template <
typename KEY,
typename VALUE>
167 return begin(ref_container.
GetData());
170template <
typename KEY,
typename VALUE>
173 return begin(container.
GetData());
175template <
typename KEY,
typename VALUE>
178 return cbegin(container.
GetData());
181template <
typename KEY,
typename VALUE>
184 return rbegin(ref_container.
GetData());
187template <
typename KEY,
typename VALUE>
190 return rbegin(container.
GetData());
193template <
typename KEY,
typename VALUE>
196 return crbegin(container.
GetData());
199template <
typename KEY,
typename VALUE>
202 return end(ref_container.
GetData());
205template <
typename KEY,
typename VALUE>
208 return end(container.
GetData());
211template <
typename KEY,
typename VALUE>
214 return cend(container.
GetData());
217template <
typename KEY,
typename VALUE>
220 return rend(ref_container.
GetData());
223template <
typename KEY,
typename VALUE>
226 return rend(container.
GetData());
229template <
typename KEY,
typename VALUE>
232 return crend(container.
GetData());
236#include <Foundation/Containers/Implementation/ArrayMap_inl.h>
Base class for all memory allocators.
Definition Allocator.h:23
An associative container, similar to plMap, but all data is stored in a sorted contiguous array,...
Definition ArrayMap.h:14
bool operator==(const plArrayMapBase< KEY, VALUE > &rhs) const
Compares the two containers for equality.
Definition ArrayMap_inl.h:294
plArrayMapBase(plAllocator *pAllocator)
Constructor.
Definition ArrayMap_inl.h:4
VALUE & FindOrAdd(const CompatibleKeyType &key, bool *out_pExisted=nullptr)
Returns the value stored at the given key. If none exists, one is created. bExisted indicates whether...
Definition ArrayMap_inl.h:195
plUInt64 GetHeapMemoryUsage() const
Returns the amount of bytes that are currently allocated on the heap.
Definition ArrayMap.h:134
plDynamicArray< Pair > & GetData()
Returns a reference to the map data array.
Definition ArrayMap_inl.h:181
VALUE & operator[](const CompatibleKeyType &key)
Same as FindOrAdd.
void Sort() const
Ensures the internal data structure is sorted. This is done automatically every time a lookup needs t...
Definition ArrayMap_inl.h:56
bool RemoveAndCopy(const CompatibleKeyType &key, bool bKeepSorted=false)
Removes one element with the given key. Returns true, if one was found and removed....
Definition ArrayMap_inl.h:239
const Pair & GetPair(plUInt32 uiIndex) const
Returns the key/value pair at the given index.
Definition ArrayMap_inl.h:218
const VALUE & GetValue(plUInt32 uiIndex) const
Returns the value that is stored at the given index.
Definition ArrayMap_inl.h:169
void Clear()
Purges all elements from the map.
Definition ArrayMap_inl.h:38
bool IsEmpty() const
True if the map contains no elements.
Definition ArrayMap_inl.h:32
bool Contains(const CompatibleKeyType &key) const
Returns whether an element with the given key exists.
const KEY & GetKey(plUInt32 uiIndex) const
Returns the key that is stored at the given index.
Definition ArrayMap_inl.h:163
void RemoveAtAndCopy(plUInt32 uiIndex, bool bKeepSorted=false)
Removes the element at the given index.
Definition ArrayMap_inl.h:224
plUInt32 Insert(CompatibleKeyType &&key, CompatibleValueType &&value)
Always inserts a new value under the given key. Duplicates are allowed. Returns the index of the newl...
Definition ArrayMap_inl.h:46
plUInt32 GetCount() const
Returns the number of elements stored in the map.
Definition ArrayMap_inl.h:26
plUInt32 Find(const CompatibleKeyType &key) const
Returns an index to one element with the given key. If the key is inserted multiple times,...
Definition ArrayMap_inl.h:67
void operator=(const plArrayMapBase &rhs)
Copy assignment operator.
Definition ArrayMap_inl.h:19
void Reserve(plUInt32 uiSize)
Reserves enough memory to store size elements.
Definition ArrayMap_inl.h:282
void Compact()
Compacts the internal memory to not waste any space.
Definition ArrayMap_inl.h:288
plUInt32 UpperBound(const CompatibleKeyType &key) const
Returns the index to the first element with a key that is LARGER than the given key....
Definition ArrayMap_inl.h:132
plUInt32 LowerBound(const CompatibleKeyType &key) const
Returns the index to the first element with a key equal or larger than the given key....
Definition ArrayMap_inl.h:100
See plArrayMapBase for details.
Definition ArrayMap.h:149
Definition DynamicArray.h:81
Base class for Pointer like reverse iterators.
Definition ArrayIterator.h:152
Non-Const class for Pointer like reverse iterators.
Definition ArrayIterator.h:216