3template <
typename KEY,
typename VALUE>
10template <
typename KEY,
typename VALUE>
12 : m_bSorted(rhs.m_bSorted)
18template <
typename KEY,
typename VALUE>
21 m_bSorted = rhs.m_bSorted;
25template <
typename KEY,
typename VALUE>
28 return m_Data.GetCount();
31template <
typename KEY,
typename VALUE>
34 return m_Data.IsEmpty();
37template <
typename KEY,
typename VALUE>
44template <
typename KEY,
typename VALUE>
45template <
typename CompatibleKeyType,
typename CompatibleValueType>
48 Pair& ref = m_Data.ExpandAndGetRef();
49 ref.key = std::forward<CompatibleKeyType>(key);
50 ref.value = std::forward<CompatibleValueType>(value);
52 return m_Data.GetCount() - 1;
55template <
typename KEY,
typename VALUE>
65template <
typename KEY,
typename VALUE>
66template <
typename CompatibleKeyType>
75 plUInt32 ub = m_Data.GetCount();
79 const plUInt32 middle = lb + ((ub - lb) >> 1);
81 if (m_Data[middle].key < key)
85 else if (key < m_Data[middle].key)
95 return plInvalidIndex;
98template <
typename KEY,
typename VALUE>
99template <
typename CompatibleKeyType>
108 plUInt32 ub = m_Data.GetCount();
112 const plUInt32 middle = lb + ((ub - lb) >> 1);
114 if (m_Data[middle].key < key)
124 if (lb == m_Data.GetCount())
125 return plInvalidIndex;
130template <
typename KEY,
typename VALUE>
131template <
typename CompatibleKeyType>
140 plUInt32 ub = m_Data.GetCount();
144 const plUInt32 middle = lb + ((ub - lb) >> 1);
146 if (key < m_Data[middle].key)
156 if (ub == m_Data.GetCount())
157 return plInvalidIndex;
162template <
typename KEY,
typename VALUE>
165 return m_Data[uiIndex].key;
168template <
typename KEY,
typename VALUE>
171 return m_Data[uiIndex].value;
174template <
typename KEY,
typename VALUE>
177 return m_Data[uiIndex].value;
180template <
typename KEY,
typename VALUE>
187template <
typename KEY,
typename VALUE>
193template <
typename KEY,
typename VALUE>
194template <
typename CompatibleKeyType>
197 plUInt32 index = Find<CompatibleKeyType>(key);
200 *out_pExisted = index != plInvalidIndex;
202 if (index == plInvalidIndex)
204 index = Insert(key, VALUE());
207 return GetValue(index);
210template <
typename KEY,
typename VALUE>
211template <
typename CompatibleKeyType>
214 return FindOrAdd(key);
217template <
typename KEY,
typename VALUE>
220 return m_Data[uiIndex];
223template <
typename KEY,
typename VALUE>
226 if (bKeepSorted && m_bSorted)
228 m_Data.RemoveAtAndCopy(uiIndex);
232 m_Data.RemoveAtAndSwap(uiIndex);
237template <
typename KEY,
typename VALUE>
238template <
typename CompatibleKeyType>
241 const plUInt32 uiIndex = Find(key);
243 if (uiIndex == plInvalidIndex)
246 RemoveAtAndCopy(uiIndex, bKeepSorted);
250template <
typename KEY,
typename VALUE>
251template <
typename CompatibleKeyType>
254 return Find(key) != plInvalidIndex;
257template <
typename KEY,
typename VALUE>
258template <
typename CompatibleKeyType>
261 plUInt32 atpos = LowerBound(key);
263 if (atpos == plInvalidIndex)
266 while (atpos < m_Data.GetCount())
268 if (m_Data[atpos].key != key)
271 if (m_Data[atpos].value == value)
281template <
typename KEY,
typename VALUE>
284 m_Data.Reserve(uiSize);
287template <
typename KEY,
typename VALUE>
293template <
typename KEY,
typename VALUE>
299 return m_Data == rhs.m_Data;
302template <
typename KEY,
typename VALUE,
typename A>
308template <
typename KEY,
typename VALUE,
typename A>
314template <
typename KEY,
typename VALUE,
typename A>
320template <
typename KEY,
typename VALUE,
typename A>
326template <
typename KEY,
typename VALUE,
typename A>
332template <
typename KEY,
typename VALUE,
typename A>
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
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