36 template <
class T_KEY,
class T_ITEM,
class U_POOL = ArrayPoolDefault, AkUInt32 TGrowBy = 1,
class TMovePolicy = AkAssignmentMovePolicy<MapStruct<T_KEY, T_ITEM> > >
37 class CAkKeyArray :
public AkArray< MapStruct<T_KEY, T_ITEM>, const MapStruct<T_KEY, T_ITEM>&, U_POOL, TGrowBy, TMovePolicy>
47 return (it != this->
End()) ? &(it.pItem->item) :
NULL;
55 T_ITEM *
Set(T_KEY in_Key,
const T_ITEM & in_Item)
57 T_ITEM* pSearchedItem =
Exists(in_Key);
60 *pSearchedItem = in_Item;
67 pStruct->
key = in_Key;
68 pStruct->
item = in_Item;
69 pSearchedItem = &(pStruct->
item);
75 T_ITEM *
SetFirst(T_KEY in_Key,
const T_ITEM & in_Item)
77 T_ITEM* pSearchedItem =
Exists(in_Key);
80 *pSearchedItem = in_Item;
87 pStruct->
key = in_Key;
88 pStruct->
item = in_Item;
89 pSearchedItem = &(pStruct->
item);
95 T_ITEM *
Set(T_KEY in_Key)
97 T_ITEM* pSearchedItem =
Exists(in_Key);
103 pStruct->
key = in_Key;
104 pSearchedItem = &(pStruct->
item);
107 return pSearchedItem;
118 for (; it != itEnd; ++it)
120 if ((*it).key == in_Item)
134 if (it != this->
End())
147 if (it != this->
End())
168 template<
class THIS_CLASS>
174 template<
class THIS_CLASS>
183 template <
class T_KEY,
class T_ITEM,
class U_POOL,
class U_KEY = AkGetArrayKey< T_KEY, T_ITEM >,
unsigned long TGrowBy = 1,
class TMovePolicy = AkAssignmentMovePolicy<T_ITEM>,
class TComparePolicy = AkDefaultSortedKeyCompare<T_KEY> >
189 return TComparePolicy::Greater((
void*)
this, a, b);
194 return TComparePolicy::Lesser((
void*)
this, a, b);
201 return bFound ? pItem :
NULL;
206 T_ITEM *
Add(T_KEY in_key)
212 U_KEY::Get(*pItem) = in_key;
225 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
226 pItem = this->
Insert(uIdx);
238 T_ITEM *
Set(T_KEY in_key)
241 return Set(in_key, bFound);
244 T_ITEM *
Set(T_KEY in_key,
bool & out_bExists)
252 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
253 pItem = this->
Insert(uIdx);
261 U_KEY::Get(*pItem) = in_key;
284 void Reorder(T_KEY in_OldKey, T_KEY in_NewKey,
const T_ITEM & in_item)
292 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
293 unsigned int uLastIdx = this->
Length() - 1;
297 bool bNeedReordering =
false;
300 T_ITEM * pPrevItem = this->
m_pItems + (uIdx - 1);
301 if (
Lesser(in_NewKey, U_KEY::Get(*pPrevItem)))
306 T_ITEM * pSecondPrevItem = this->
m_pItems + (uIdx - 2);
307 if (
Greater(in_NewKey, U_KEY::Get(*pSecondPrevItem)))
309 return Swap(pPrevItem, pItem);
313 bNeedReordering =
true;
318 return Swap(pPrevItem, pItem);
322 if (!bNeedReordering && uIdx < uLastIdx)
324 T_ITEM * pNextItem = this->
m_pItems + (uIdx + 1);
325 if (
Greater(in_NewKey, U_KEY::Get(*pNextItem)))
328 if (uIdx < (uLastIdx - 1))
330 T_ITEM * pSecondNextItem = this->
m_pItems + (uIdx + 2);
331 if (
Lesser(in_NewKey, U_KEY::Get(*pSecondNextItem)))
333 return Swap(pNextItem, pItem);
337 bNeedReordering =
true;
342 return Swap(pNextItem, pItem);
352 unsigned int uIdxToInsert;
356 uIdxToInsert = (
unsigned int)(pTargetItem - this->
m_pItems);
357 if (uIdxToInsert > uIdx)
364 uIdxToInsert = uLastIdx;
367 T_ITEM * pStartItem = this->
m_pItems + uIdx;
368 T_ITEM * pEndItem = this->
m_pItems + uIdxToInsert;
369 if (uIdxToInsert < uIdx)
372 while (pStartItem != pEndItem)
375 pStartItem[1] = pStartItem[0];
381 while (pStartItem != pEndItem)
383 pStartItem[0] = pStartItem[1];
387 pEndItem[0] = in_item;
397 if (NumItemsToReInsert != 0)
401 T_ITEM * pReinsertionItem = this->
m_pItems;
403 for (
AkInt32 idx = 0; idx < NumItemsToReInsert; ++idx)
405 T_ITEM ItemtoReinsert = pReinsertionItem[idx];
407 T_KEY keyToReinsert = U_KEY::Get(ItemtoReinsert);
409 T_ITEM* pInsertionEmplacement =
AddNoSetKey(keyToReinsert);
412 *pInsertionEmplacement = ItemtoReinsert;
423 while (uTop <= uBottom)
425 AkInt32 uThis = (uBottom - uTop) / 2 + uTop;
443 T_ITEM ItemTemp = *in_ItemA;
444 *in_ItemA = *in_ItemB;
445 *in_ItemB = ItemTemp;
450 #endif //_KEYARRAY_H_
T_ITEM * Set(T_KEY in_Key)
Iterator EraseSwap(Iterator &in_rIter)
static AkForceInline bool Lesser(THIS_CLASS *, T_KEY &a, T_KEY &b)
void Reorder(T_KEY in_OldKey, T_KEY in_NewKey, const T_ITEM &in_item)
void UnsetSwap(T_KEY in_Key)
AkForceInline AkUInt32 Length() const
Returns the numbers of items in the array.
T_ITEM * Set(T_KEY in_key)
AkForceInline bool Lesser(T_KEY &a, T_KEY &b) const
AkForceInline void Swap(T_ITEM *in_ItemA, T_ITEM *in_ItemB)
T_ITEM * Set(T_KEY in_key, bool &out_bExists)
Specific implementation of array.
MapStruct< T_KEY, T_ITEM > * AddLast()
T_ITEM * Add(T_KEY in_key)
#define AKASSERT(Condition)
T_ITEM * m_pItems
pointer to the beginning of the array.
Key policy for AkSortedKeyArray.
Iterator End() const
Returns the iterator to the end of the array.
AkUInt32 m_uLength
number of items in the array.
Iterator Begin() const
Returns the iterator to the first item of the array, will be End() if the array is empty.
T_ITEM * SetFirst(T_KEY in_Key, const T_ITEM &in_Item)
T_ITEM * BinarySearch(T_KEY in_key, bool &out_bFound) const
static AkForceInline bool Greater(THIS_CLASS *, T_KEY &a, T_KEY &b)
Iterator Erase(Iterator &in_rIter)
Erase the specified iterator from the array.
static AkForceInline T_KEY & Get(T_ITEM &in_item)
Default policy.
MapStruct< T_KEY, T_ITEM > * Insert(unsigned int in_uIndex)
T_ITEM * Exists(T_KEY in_key) const
T_ITEM * Set(T_KEY in_Key, const T_ITEM &in_Item)
T_ITEM * AddNoSetKey(T_KEY in_key)
AkArray< MapStruct< T_KEY, T_ITEM >, const MapStruct< T_KEY, T_ITEM > &, U_POOL, TGrowBy, TMovePolicy >::Iterator FindEx(T_KEY in_Item) const
T_ITEM * Exists(T_KEY in_Key)
AkForceInline bool Greater(T_KEY &a, T_KEY &b) const