35 template <
class T_KEY,
class T_ITEM,
class U_POOL = ArrayPoolDefault,
class TGrowBy = AkGrowByPolicy_DEFAULT,
class TMovePolicy = AkAssignmentMovePolicy<MapStruct<T_KEY, T_ITEM> > >
36 class CAkKeyArray :
public AkArray< MapStruct<T_KEY, T_ITEM>, const MapStruct<T_KEY, T_ITEM>&, U_POOL, TGrowBy, TMovePolicy>
46 return (it != this->
End()) ? &(it.pItem->item) :
NULL;
54 T_ITEM *
Set(T_KEY in_Key,
const T_ITEM & in_Item)
56 T_ITEM* pSearchedItem =
Exists(in_Key);
59 *pSearchedItem = in_Item;
66 pStruct->
key = in_Key;
67 pStruct->
item = in_Item;
68 pSearchedItem = &(pStruct->
item);
74 T_ITEM *
SetFirst(T_KEY in_Key,
const T_ITEM & in_Item)
76 T_ITEM* pSearchedItem =
Exists(in_Key);
79 *pSearchedItem = in_Item;
86 pStruct->
key = in_Key;
87 pStruct->
item = in_Item;
88 pSearchedItem = &(pStruct->
item);
94 T_ITEM *
Set(T_KEY in_Key)
96 T_ITEM* pSearchedItem =
Exists(in_Key);
102 pStruct->
key = in_Key;
103 pSearchedItem = &(pStruct->
item);
106 return pSearchedItem;
117 for (; it != itEnd; ++it)
119 if ((*it).key == in_Item)
133 if (it != this->
End())
146 if (it != this->
End())
168 return in_item.Key();
176 template <
class T_KEY>
187 template<
class THIS_CLASS>
193 template<
class THIS_CLASS>
202 template <
class T_KEY,
class T_ITEM,
class U_POOL = ArrayPoolDefault,
class U_KEY = AkGetArrayKey< T_KEY, T_ITEM >,
class TGrowBy = AkGrowByPolicy_DEFAULT,
class TMovePolicy = AkAssignmentMovePolicy<T_ITEM>,
class TComparePolicy = AkDefaultSortedKeyCompare<T_KEY> >
211 return TComparePolicy::Lesser((
void*)
this, a, b);
216 return TComparePolicy::Equal((
void*)
this, a, b);
223 return bFound ? pItem :
NULL;
228 T_ITEM *
Add(T_KEY in_key)
234 U_KEY::Get(*pItem) = in_key;
252 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
253 pItem = this->
Insert(uIdx);
265 T_ITEM *
Set(T_KEY in_key)
268 return Set(in_key, bFound);
271 T_ITEM *
Set(T_KEY in_key,
bool & out_bExists)
278 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
279 pItem = this->
Insert(uIdx);
287 U_KEY::Get(*pItem) = in_key;
296 T_ITEM * pItem =
Exists(in_key);
310 void Reorder(T_KEY in_OldKey, T_KEY in_NewKey,
const T_ITEM & in_item)
318 unsigned int uIdx = (
unsigned int)(pItem - this->
m_pItems);
319 unsigned int uLastIdx = this->
Length() - 1;
323 bool bNeedReordering =
false;
326 T_ITEM * pPrevItem = this->
m_pItems + (uIdx - 1);
327 if (
Lesser(in_NewKey, U_KEY::Get(*pPrevItem)))
332 T_ITEM * pSecondPrevItem = this->
m_pItems + (uIdx - 2);
333 if (
Lesser(U_KEY::Get(*pSecondPrevItem), in_NewKey))
335 return Swap(pPrevItem, pItem);
339 bNeedReordering =
true;
344 return Swap(pPrevItem, pItem);
348 if (!bNeedReordering && uIdx < uLastIdx)
350 T_ITEM * pNextItem = this->
m_pItems + (uIdx + 1);
351 if (
Lesser(U_KEY::Get(*pNextItem), in_NewKey))
354 if (uIdx < (uLastIdx - 1))
356 T_ITEM * pSecondNextItem = this->
m_pItems + (uIdx + 2);
357 if (
Lesser(in_NewKey, U_KEY::Get(*pSecondNextItem)))
359 return Swap(pNextItem, pItem);
363 bNeedReordering =
true;
368 return Swap(pNextItem, pItem);
378 unsigned int uIdxToInsert;
382 uIdxToInsert = (
unsigned int)(pTargetItem - this->
m_pItems);
383 if (uIdxToInsert > uIdx)
390 uIdxToInsert = uLastIdx;
393 T_ITEM * pStartItem = this->
m_pItems + uIdx;
394 T_ITEM * pEndItem = this->
m_pItems + uIdxToInsert;
395 if (uIdxToInsert < uIdx)
398 while (pStartItem != pEndItem)
401 pStartItem[1] = pStartItem[0];
407 while (pStartItem != pEndItem)
409 pStartItem[0] = pStartItem[1];
413 pEndItem[0] = in_item;
423 if (NumItemsToReInsert != 0)
427 T_ITEM * pReinsertionItem = this->
m_pItems;
429 for (
AkInt32 idx = 0; idx < NumItemsToReInsert; ++idx)
431 T_ITEM ItemtoReinsert = pReinsertionItem[idx];
433 T_KEY keyToReinsert = U_KEY::Get(ItemtoReinsert);
435 T_ITEM* pInsertionEmplacement =
AddNoSetKey(keyToReinsert);
438 *pInsertionEmplacement = ItemtoReinsert;
450 while ( uNumToSearch > 0 )
452 iPivot = iBase + ( uNumToSearch >> 1 );
453 T_KEY pivotKey = U_KEY::Get( this->
m_pItems[ iPivot ] );
454 if (
Equal( pivotKey, in_key ) )
460 if (
Lesser( pivotKey, in_key ) )
481 AKASSERT(in_to.pItem >= in_from.pItem);
486 while (uNumToSearch > 0)
488 uPivot = uBase + (
AkUInt32)(uNumToSearch >> 1);
489 T_KEY pivotKey = U_KEY::Get(this->
m_pItems[uPivot]);
490 if (
Lesser(pivotKey, in_key))
503 T_ITEM ItemTemp = *in_ItemA;
504 *in_ItemA = *in_ItemB;
505 *in_ItemB = ItemTemp;
510 #endif //_KEYARRAY_H_