27Â
#ifndef _AKHASHLIST_H
28Â
#define _AKHASHLIST_H
40Â
template <
class T_KEY >
43Â
#define AK_HASH_SIZE_VERY_SMALL 11
44Â
extern const AK_SELECTANY AkHashType kHashSizes[] = { 29, 53, 97, 193, 389, 769, 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741 };
48Â
template <
class T_KEY,
class T_ITEM,
typename T_ALLOC = ArrayPoolDefault >
151Â pPrevItem = this->
pItem;
172Â pPrevItem = this->
pItem;
187Â Iterator returnedIt;
192Â returnedIt.uiTable = 0;
193Â returnedIt.pItem =
m_table[0];
195Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
196Â returnedIt.pItem =
m_table[returnedIt.uiTable];
200Â returnedIt.pTable =
NULL;
201Â returnedIt.uiTable = 0;
202Â returnedIt.pItem =
NULL;
210Â ConstIterator returnedIt;
215Â returnedIt.uiTable = 0;
216Â returnedIt.pItem =
m_table[0];
218Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
219Â returnedIt.pItem =
m_table[returnedIt.uiTable];
223Â returnedIt.pTable =
NULL;
224Â returnedIt.uiTable = 0;
225Â returnedIt.pItem =
NULL;
233Â IteratorEx returnedIt;
238Â returnedIt.uiTable = 0;
240Â returnedIt.pPrevItem =
NULL;
242Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
243Â returnedIt.pItem =
m_table[returnedIt.uiTable];
247Â returnedIt.pTable =
NULL;
248Â returnedIt.uiTable = 0;
249Â returnedIt.pItem =
NULL;
257Â ConstIteratorEx returnedIt;
262Â returnedIt.uiTable = 0;
264Â returnedIt.pPrevItem =
NULL;
266Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
267Â returnedIt.pItem =
m_table[returnedIt.uiTable];
271Â returnedIt.pTable =
NULL;
272Â returnedIt.uiTable = 0;
273Â returnedIt.pItem =
NULL;
281Â Iterator returnedIt;
286Â
inline ConstIterator
End()
const
288Â ConstIterator returnedIt;
295Â IteratorEx returnedIt;
302Â ConstIteratorEx returnedIt;
309Â IteratorEx returnedIt;
316Â returnedIt.pPrevItem =
NULL;
318Â
while (returnedIt.pItem !=
NULL)
320Â
if (returnedIt.pItem->Assoc.key == in_Key)
323Â returnedIt.pPrevItem = returnedIt.pItem;
324Â returnedIt.pItem = returnedIt.pItem->pNextItem;
329Â returnedIt.pTable =
NULL;
330Â returnedIt.uiTable = 0;
331Â returnedIt.pItem =
NULL;
332Â returnedIt.pPrevItem =
NULL;
338Â ConstIteratorEx
FindEx(T_KEY in_Key)
const
340Â ConstIteratorEx returnedIt;
347Â returnedIt.pPrevItem =
NULL;
349Â
while (returnedIt.pItem !=
NULL)
351Â
if (returnedIt.pItem->Assoc.key == in_Key)
354Â returnedIt.pPrevItem = returnedIt.pItem;
355Â returnedIt.pItem = returnedIt.pItem->pNextItem;
360Â returnedIt.pTable =
NULL;
361Â returnedIt.uiTable = 0;
362Â returnedIt.pItem =
NULL;
363Â returnedIt.pPrevItem =
NULL;
390Â
while ( pItem !=
NULL )
392Â Item * pNextItem = pItem->pNextItem;
393Â pItem->Assoc.item.~T_ITEM();
415Â T_ITEM *
Set( Item * in_pItem )
425Â in_pItem->pNextItem =
m_table[uiTable];
430Â
return &(in_pItem->Assoc.item);
436Â T_ITEM *
Set( T_KEY in_Key )
451Â T_ITEM *
Set( T_KEY in_Key,
bool& out_bWasAlreadyThere )
459Â out_bWasAlreadyThere =
true;
464Â out_bWasAlreadyThere =
false;
478Â Item * pItem =
m_table[uiTable];
479Â Item * pPrevItem =
NULL;
480Â
while (pItem !=
NULL)
482Â
if (pItem->Assoc.key == in_Key)
486Â pItem = pItem->pNextItem;
494Â IteratorEx
Erase(
const IteratorEx& in_rIter )
496Â IteratorEx returnedIt;
497Â returnedIt.
pTable = in_rIter.pTable;
498Â returnedIt.uiTable = in_rIter.uiTable;
499Â returnedIt.pItem = in_rIter.pItem->pNextItem;
500Â returnedIt.pPrevItem = in_rIter.pPrevItem;
502Â
while ( ( returnedIt.pItem ==
NULL ) && ( ++returnedIt.uiTable <
HashSize() ) )
504Â returnedIt.pPrevItem =
NULL;
505Â returnedIt.pItem = (*returnedIt.pTable)[returnedIt.uiTable];
508Â
RemoveItem( in_rIter.uiTable, in_rIter.pItem, in_rIter.pPrevItem );
516Â in_pPrevItem->pNextItem = in_pItem->pNextItem;
518Â
m_table[ in_uiTable ] = in_pItem->pNextItem;
520Â in_pItem->Assoc.item.~T_ITEM();
546Â
if (
kHashSizes[i] > in_uExpectedNumberOfEntires)
560Â
for (
AkUInt32 i = 0; i < uNewSize; i++)
565Â Item * pItem = oldArray[i];
566Â
while (pItem !=
NULL)
568Â Item * pNextItem = pItem->pNextItem;
571Â pItem->pNextItem =
m_table[uiTable];
621Â
while (pItem !=
NULL)
623Â
if (pItem->Assoc.key == in_Key)
624Â
return &(pItem->Assoc.item);
626Â pItem = pItem->pNextItem;
634Â Item * pNewItem = (Item *)T_ALLOC::Alloc(
sizeof(Item));
635Â
if ( pNewItem ==
NULL )
639Â pNewItem->Assoc.key = in_Key;
647Â
return &(pNewItem->Assoc.item);
657Â
template <
class T_KEY,
class T_MAPSTRUCT>
660Â
static const T_KEY&
Key(
const T_MAPSTRUCT* in_pItem) {
return in_pItem->key;}
661Â
static T_MAPSTRUCT*&
Next(T_MAPSTRUCT* in_pItem) {
return (*in_pItem).pNextItem; }
664Â
template <
class T_KEY,
class T_MAPSTRUCT>
667Â
static const T_KEY&
Key(
const T_MAPSTRUCT* in_pItem) {
return in_pItem->Key(); }
668Â
static T_MAPSTRUCT*&
Next(T_MAPSTRUCT* in_pItem) {
return (*in_pItem).pNextItem; }
671Â
template <
class T_KEY,
class T_MAPSTRUCT>
674Â
template <
class T_KEY,
class T_MAPSTRUCT,
typename T_ALLOC = ArrayPoolDefault,
class KEY_POLICY = AkDefaultHashListBarePolicy<T_KEY, T_MAPSTRUCT>,
class LIST_POLICY = AkDefaultHashListBarePolicy<T_KEY, T_MAPSTRUCT>>
769Â pPrevItem = this->
pItem;
790Â pPrevItem = this->
pItem;
791Â this->
pItem = LIST_POLICY::Next(this->
pItem);
805Â Iterator returnedIt;
810Â returnedIt.uiTable = 0;
811Â returnedIt.pItem =
m_table[0];
813Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
814Â returnedIt.pItem =
m_table[returnedIt.uiTable];
818Â returnedIt.pTable =
NULL;
819Â returnedIt.uiTable = 0;
820Â returnedIt.pItem =
NULL;
828Â ConstIterator returnedIt;
833Â returnedIt.uiTable = 0;
834Â returnedIt.pItem =
m_table[0];
836Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
837Â returnedIt.pItem =
m_table[returnedIt.uiTable];
841Â returnedIt.pTable =
NULL;
842Â returnedIt.uiTable = 0;
843Â returnedIt.pItem =
NULL;
851Â IteratorEx returnedIt;
856Â returnedIt.uiTable = 0;
857Â returnedIt.pItem =
m_table[0];
858Â returnedIt.pPrevItem =
NULL;
860Â
while ( ( returnedIt.pItem ==
NULL ) && ( ++returnedIt.uiTable <
HashSize() ) )
861Â returnedIt.pItem =
m_table[ returnedIt.uiTable ];
865Â returnedIt.pTable =
NULL;
866Â returnedIt.uiTable = 0;
867Â returnedIt.pItem =
NULL;
868Â returnedIt.pPrevItem =
NULL;
876Â ConstIteratorEx returnedIt;
881Â returnedIt.uiTable = 0;
882Â returnedIt.pItem =
m_table[0];
883Â returnedIt.pPrevItem =
NULL;
885Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable <
HashSize()))
886Â returnedIt.pItem =
m_table[returnedIt.uiTable];
890Â returnedIt.pTable =
NULL;
891Â returnedIt.uiTable = 0;
892Â returnedIt.pItem =
NULL;
893Â returnedIt.pPrevItem =
NULL;
901Â Iterator returnedIt;
906Â
inline ConstIterator
End()
const
908Â ConstIterator returnedIt;
915Â IteratorEx returnedIt;
921Â returnedIt.pItem =
m_table[returnedIt.uiTable];
922Â returnedIt.pPrevItem =
NULL;
924Â
while (returnedIt.pItem !=
NULL)
926Â
if (KEY_POLICY::Key(returnedIt.pItem) == in_Key)
929Â returnedIt.pPrevItem = returnedIt.pItem;
930Â returnedIt.pItem = LIST_POLICY::Next(returnedIt.pItem);
935Â returnedIt.pTable =
NULL;
936Â returnedIt.uiTable = 0;
937Â returnedIt.pItem =
NULL;
938Â returnedIt.pPrevItem =
NULL;
944Â ConstIteratorEx
FindEx(T_KEY in_Key)
const
946Â ConstIteratorEx returnedIt;
952Â returnedIt.pItem =
m_table[returnedIt.uiTable];
953Â returnedIt.pPrevItem =
NULL;
955Â
while (returnedIt.pItem !=
NULL)
957Â
if (KEY_POLICY::Key(returnedIt.pItem) == in_Key)
960Â returnedIt.pPrevItem = returnedIt.pItem;
961Â returnedIt.pItem = returnedIt.pItem->pNextItem;
966Â returnedIt.pTable =
NULL;
967Â returnedIt.uiTable = 0;
968Â returnedIt.pItem =
NULL;
969Â returnedIt.pPrevItem =
NULL;
1035Â
bool Set( T_MAPSTRUCT * in_pItem,
bool& out_exists )
1037Â out_exists =
false;
1047Â _Set(in_pItem, uiTable);
1054Â
bool Set( T_MAPSTRUCT * in_pItem )
1060Â _Set(in_pItem, uiTable);
1068Â
void _Set( T_MAPSTRUCT * in_pItem,
AkHashType in_uiTable )
1070Â LIST_POLICY::Next(in_pItem) =
m_table[in_uiTable];
1071Â
m_table[in_uiTable] = in_pItem;
1076Â T_MAPSTRUCT *
Unset(
const T_KEY &in_Key )
1078Â T_MAPSTRUCT * pItem =
NULL;
1084Â T_MAPSTRUCT * pPrevItem =
NULL;
1085Â
while (pItem !=
NULL)
1087Â
if (KEY_POLICY::Key(pItem) == in_Key)
1091Â pItem = LIST_POLICY::Next(pItem);
1101Â IteratorEx
Erase(
const IteratorEx& in_rIter )
1103Â IteratorEx returnedIt;
1104Â returnedIt.
pTable = in_rIter.pTable;
1105Â returnedIt.uiTable = in_rIter.uiTable;
1106Â returnedIt.pItem = LIST_POLICY::Next(in_rIter.pItem);
1107Â returnedIt.pPrevItem = in_rIter.pPrevItem;
1109Â
while ((returnedIt.pItem ==
NULL) && (++returnedIt.uiTable < returnedIt.pTable->Length()))
1111Â returnedIt.pPrevItem =
NULL;
1112Â returnedIt.pItem = (*returnedIt.pTable)[ returnedIt.uiTable ];
1115Â
RemoveItem( in_rIter.uiTable, in_rIter.pItem, in_rIter.pPrevItem );
1140Â
if (
kHashSizes[i] > in_uExpectedNumberOfEntires)
1154Â
for (
AkUInt32 i = 0; i < uNewSize; i++)
1159Â T_MAPSTRUCT* pItem = oldArray[i];
1160Â
while (pItem !=
NULL)
1162Â T_MAPSTRUCT* pNextItem = LIST_POLICY::Next(pItem);
1165Â LIST_POLICY::Next(pItem) =
m_table[uiTable];
1204Â LIST_POLICY::Next(in_pPrevItem) = LIST_POLICY::Next(in_pItem);
1206Â
m_table[ in_uiTable ] = LIST_POLICY::Next(in_pItem);
1213Â T_MAPSTRUCT * pItem =
m_table[in_uiTable];
1214Â
while (pItem !=
NULL)
1216Â
if (KEY_POLICY::Key(pItem) == in_Key)
1219Â pItem = LIST_POLICY::Next(pItem);
1231Â
#endif // _AKHASHLIST_H