17 #ifndef INC_KY_Kernel_Hash_H
18 #define INC_KY_Kernel_Hash_H
61 UPInt operator()(
const C& data)
const
62 {
return (UPInt) data; }
74 static KY_INLINE UPInt SDBM_Hash(
const void* data_in, UPInt size, UPInt seed = 5381)
81 h = (h << 16) + (h << 6) - h + (UPInt)data[size];
86 UPInt operator()(
const C& data)
const
88 unsigned char* p = (
unsigned char*) &data;
91 return SDBM_Hash(p, size);
101 template<
class C,
class HashF>
110 : NextInChain(-2) { }
111 HashsetEntry(
const HashsetEntry& e)
112 : NextInChain(e.NextInChain), Value(e.Value) { }
113 HashsetEntry(
const C& key, SPInt next)
114 : NextInChain(next), Value(key) { }
116 bool IsEmpty()
const {
return NextInChain == -2; }
117 bool IsEndOfChain()
const {
return NextInChain == -1; }
121 UPInt GetCachedHash(UPInt maskValue)
const {
return HashF()(Value) & maskValue; }
122 void SetCachedHash(UPInt) {}
131 void Free() { Clear(); }
136 template<
class C,
class HashF>
137 class HashsetCachedEntry
146 : NextInChain(-2) { }
147 HashsetCachedEntry(
const HashsetCachedEntry& e)
148 : NextInChain(e.NextInChain), HashValue(e.HashValue), Value(e.Value) { }
149 HashsetCachedEntry(
const C& key, SPInt next)
150 : NextInChain(next), Value(key) { }
152 bool IsEmpty()
const {
return NextInChain == -2; }
153 bool IsEndOfChain()
const {
return NextInChain == -1; }
157 UPInt GetCachedHash(UPInt maskValue)
const { KY_UNUSED(maskValue);
return HashValue; }
158 void SetCachedHash(UPInt hashValue) { HashValue = hashValue; }
167 void Free() { Clear(); }
178 template<
class C,
class HashF = FixedSizeHash<C>,
179 class AltHashF = HashF,
180 class Allocator = AllocatorGH<C>,
181 class Entry = HashsetCachedEntry<C, HashF> >
184 enum { HashMinSize = 8 };
187 KY_MEMORY_REDEFINE_NEW(HashSetBase, Allocator::StatId)
189 typedef HashSetBase<C, HashF, AltHashF, Allocator, Entry> SelfType;
191 HashSetBase() : pTable(NULL) { }
192 HashSetBase(
int sizeHint) : pTable(NULL) { SetCapacity(
this, sizeHint); }
193 explicit HashSetBase(
void* pmemAddr) : pTable(NULL){ KY_UNUSED(pmemAddr); }
194 HashSetBase(
void* pmemAddr,
int sizeHint) : pTable(NULL) { SetCapacity(pmemAddr, sizeHint); }
195 HashSetBase(
const SelfType& src) : pTable(NULL) { Assign(
this, src); }
201 for (UPInt i = 0, n = pTable->SizeMask; i <= n; i++)
208 Allocator::Free(pTable);
214 void Assign(
void* pmemAddr,
const SelfType& src)
217 if (src.IsEmpty() ==
false)
219 SetCapacity(pmemAddr, src.GetSize());
221 for (ConstIterator it = src.Begin(); it != src.End(); ++it)
235 for (UPInt i = 0, n = pTable->SizeMask; i <= n; i++)
242 Allocator::Free(pTable);
250 return pTable == NULL || pTable->EntryCount == 0;
258 void Set(
void* pmemAddr,
const CRef& key)
260 UPInt hashValue = HashF()(key);
261 SPInt index = (SPInt)-1;
264 index = findIndexCore(key, hashValue & pTable->SizeMask);
268 E(index).Value = key;
273 add(pmemAddr, key, hashValue);
278 inline void Add(
void* pmemAddr,
const CRef& key)
280 UPInt hashValue = HashF()(key);
281 add(pmemAddr, key, hashValue);
286 void RemoveAlt(
const K& key)
291 UPInt hashValue = AltHashF()(key);
292 SPInt index = hashValue & pTable->SizeMask;
294 Entry* e = &E(index);
297 if (e->IsEmpty() || (e->GetCachedHash(pTable->SizeMask) != (UPInt)index))
301 SPInt naturalIndex = index;
302 SPInt prevIndex = -1;
304 while ((e->GetCachedHash(pTable->SizeMask) != (UPInt)naturalIndex) || !(e->Value == key))
308 index = e->NextInChain;
315 if (naturalIndex == index)
318 if (!e->IsEndOfChain())
320 Entry* enext = &E(e->NextInChain);
322 new (e) Entry(*enext);
330 E(prevIndex).NextInChain = e->NextInChain;
335 pTable->EntryCount --;
341 void Remove(
const CRef& key)
352 SPInt index = findIndex(key);
354 return &E(index).Value;
359 const C* Get(
const K& key)
const
361 SPInt index = findIndex(key);
363 return &E(index).Value;
369 const C* GetAlt(
const K& key)
const
371 SPInt index = findIndexAlt(key);
373 return &E(index).Value;
378 C* GetAlt(
const K& key)
380 SPInt index = findIndexAlt(key);
382 return &E(index).Value;
387 bool GetAlt(
const K& key, C* pval)
const
389 SPInt index = findIndexAlt(key);
393 *pval = E(index).Value;
400 UPInt GetSize()
const
402 return pTable == NULL ? 0 : (UPInt)pTable->EntryCount;
408 void CheckExpand(
void* pmemAddr)
413 setRawCapacity(pmemAddr, HashMinSize);
415 else if (pTable->EntryCount * 5 > (pTable->SizeMask + 1) * 4)
418 setRawCapacity(pmemAddr, (pTable->SizeMask + 1) * 2);
423 void Resize(
void* pmemAddr, UPInt n)
431 SetCapacity(pmemAddr, n);
437 void SetCapacity(
void* pmemAddr, UPInt newSize)
439 UPInt newRawSize = (newSize * 5) / 4;
440 if (newRawSize <= GetSize())
442 setRawCapacity(pmemAddr, newRawSize);
455 KY_ASSERT(Index >= 0 && Index <= (SPInt)pHash->pTable->SizeMask);
456 return pHash->E(Index).Value;
459 const C* operator -> ()
const
461 KY_ASSERT(Index >= 0 && Index <= (SPInt)pHash->pTable->SizeMask);
462 return &pHash->E(Index).Value;
468 if (Index <= (SPInt)pHash->pTable->SizeMask)
471 while ((UPInt)Index <= pHash->pTable->SizeMask &&
472 pHash->E(Index).IsEmpty())
479 bool operator == (
const ConstIterator& it)
const
481 if (IsEnd() && it.IsEnd())
487 return (pHash == it.pHash) && (Index == it.Index);
491 bool operator != (
const ConstIterator& it)
const
493 return ! (*
this == it);
499 return (pHash == NULL) ||
500 (pHash->pTable == NULL) ||
501 (Index > (SPInt)pHash->pTable->SizeMask);
505 : pHash(NULL), Index(0)
511 ConstIterator(
const SelfType* h, SPInt index)
512 : pHash(h), Index(index)
515 const SelfType* GetContainer()
const
519 SPInt GetIndex()
const
525 friend class HashSetBase<C, HashF, AltHashF, Allocator, Entry>;
527 const SelfType* pHash;
531 friend struct ConstIterator;
535 struct Iterator :
public ConstIterator
540 KY_ASSERT(ConstIterator::Index >= 0 && ConstIterator::Index <= (SPInt)ConstIterator::pHash->pTable->SizeMask);
541 return const_cast<SelfType*
>(ConstIterator::pHash)->E(ConstIterator::Index).Value;
544 C* operator->()
const
550 : ConstIterator(NULL, 0)
556 RemoveAlt(
operator*());
560 void RemoveAlt(
const K& key)
562 SelfType* phash =
const_cast<SelfType*
>(ConstIterator::pHash);
566 UPInt hashValue = AltHashF()(key);
567 SPInt index = hashValue & phash->pTable->SizeMask;
569 Entry* e = &phash->E(index);
572 if (e->IsEmpty() || (e->GetCachedHash(phash->pTable->SizeMask) != (UPInt)index))
576 SPInt naturalIndex = index;
577 SPInt prevIndex = -1;
579 while ((e->GetCachedHash(phash->pTable->SizeMask) != (UPInt)naturalIndex) || !(e->Value == key))
583 index = e->NextInChain;
586 e = &phash->E(index);
589 if (index == (SPInt)ConstIterator::Index)
592 if (naturalIndex == index)
595 if (!e->IsEndOfChain())
597 Entry* enext = &phash->E(e->NextInChain);
599 new (e) Entry(*enext);
602 --ConstIterator::Index;
608 phash->E(prevIndex).NextInChain = e->NextInChain;
613 phash->pTable->EntryCount --;
620 friend class HashSetBase<C, HashF, AltHashF, Allocator, Entry>;
622 Iterator(SelfType* h, SPInt i0)
623 : ConstIterator(h, i0)
627 friend struct Iterator;
632 return Iterator(NULL, 0);
636 while (i0 <= pTable->SizeMask && E(i0).IsEmpty())
640 return Iterator(
this, i0);
642 Iterator End() {
return Iterator(NULL, 0); }
644 ConstIterator Begin()
const {
return const_cast<SelfType*
>(
this)->Begin(); }
645 ConstIterator End()
const {
return const_cast<SelfType*
>(
this)->End(); }
648 Iterator Find(
const K& key)
650 SPInt index = findIndex(key);
652 return Iterator(
this, index);
653 return Iterator(NULL, 0);
657 Iterator FindAlt(
const K& key)
659 SPInt index = findIndexAlt(key);
661 return Iterator(
this, index);
662 return Iterator(NULL, 0);
666 ConstIterator Find(
const K& key)
const {
return const_cast<SelfType*
>(
this)->Find(key); }
669 ConstIterator FindAlt(
const K& key)
const {
return const_cast<SelfType*
>(
this)->FindAlt(key); }
674 SPInt findIndex(
const K& key)
const
678 UPInt hashValue = HashF()(key) & pTable->SizeMask;
679 return findIndexCore(key, hashValue);
683 SPInt findIndexAlt(
const K& key)
const
687 UPInt hashValue = AltHashF()(key) & pTable->SizeMask;
688 return findIndexCore(key, hashValue);
693 SPInt findIndexCore(
const K& key, UPInt hashValue)
const
696 KY_ASSERT(pTable != 0);
698 KY_ASSERT((hashValue & ~pTable->SizeMask) == 0);
700 UPInt index = hashValue;
701 const Entry* e = &E(index);
704 if (e->IsEmpty() || (e->GetCachedHash(pTable->SizeMask) != index))
709 KY_ASSERT(e->GetCachedHash(pTable->SizeMask) == hashValue);
711 if (e->GetCachedHash(pTable->SizeMask) == hashValue && e->Value == key)
718 KY_ASSERT(!(e->Value == key));
721 index = e->NextInChain;
722 if (index == (UPInt)-1)
726 KY_ASSERT(!e->IsEmpty());
734 void add(
void* pmemAddr,
const CRef& key, UPInt hashValue)
736 CheckExpand(pmemAddr);
737 hashValue &= pTable->SizeMask;
739 pTable->EntryCount++;
741 SPInt index = hashValue;
742 Entry* naturalEntry = &(E(index));
744 if (naturalEntry->IsEmpty())
747 new (naturalEntry) Entry(key, -1);
752 SPInt blankIndex = index;
754 blankIndex = (blankIndex + 1) & pTable->SizeMask;
755 }
while(!E(blankIndex).IsEmpty());
757 Entry* blankEntry = &E(blankIndex);
759 if (naturalEntry->GetCachedHash(pTable->SizeMask) == (UPInt)index)
764 new (blankEntry) Entry(*naturalEntry);
767 naturalEntry->Value = key;
768 naturalEntry->NextInChain = blankIndex;
777 SPInt collidedIndex = naturalEntry->GetCachedHash(pTable->SizeMask);
778 KY_ASSERT(collidedIndex >= 0 && collidedIndex <= (SPInt)pTable->SizeMask);
781 Entry* e = &E(collidedIndex);
782 if (e->NextInChain == index)
785 new (blankEntry) Entry(*naturalEntry);
786 e->NextInChain = blankIndex;
789 collidedIndex = e->NextInChain;
790 KY_ASSERT(collidedIndex >= 0 && collidedIndex <= (SPInt)pTable->SizeMask);
794 naturalEntry->Value = key;
795 naturalEntry->NextInChain = -1;
800 naturalEntry->SetCachedHash(hashValue);
804 Entry& E(UPInt index)
807 KY_ASSERT(index <= pTable->SizeMask);
808 return *(((Entry*) (pTable + 1)) + index);
810 const Entry& E(UPInt index)
const
812 KY_ASSERT(index <= pTable->SizeMask);
813 return *(((Entry*) (pTable + 1)) + index);
821 void setRawCapacity(
void* pheapAddr, UPInt newSize)
833 if (newSize < HashMinSize)
834 newSize = HashMinSize;
838 int bits = Alg::UpperBit(newSize-1) + 1;
839 KY_ASSERT((UPInt(1) << bits) >= newSize);
840 newSize = UPInt(1) << bits;
844 newHash.pTable = (TableType*)
847 sizeof(TableType) +
sizeof(Entry) * newSize,
850 KY_ASSERT(newHash.pTable);
852 newHash.pTable->EntryCount = 0;
853 newHash.pTable->SizeMask = newSize - 1;
857 for (i = 0; i < newSize; i++)
858 newHash.E(i).NextInChain = -2;
863 for (i = 0, n = pTable->SizeMask; i <= n; i++)
866 if (e->IsEmpty() ==
false)
869 newHash.Add(pheapAddr, e->Value);
876 Allocator::Free(pTable);
880 pTable = newHash.pTable;
881 newHash.pTable = NULL;
897 template<
class C,
class HashF = FixedSizeHash<C>,
898 class AltHashF = HashF,
899 class Allocator = AllocatorGH<C>,
900 class Entry = HashsetCachedEntry<C, HashF> >
901 class HashSet :
public HashSetBase<C, HashF, AltHashF, Allocator, Entry>
904 typedef HashSetBase<C, HashF, AltHashF, Allocator, Entry> BaseType;
905 typedef HashSet<C, HashF, AltHashF, Allocator, Entry> SelfType;
908 HashSet(
int sizeHint) : BaseType(sizeHint) { }
909 explicit HashSet(
void* pheap) : BaseType(pheap) { }
910 HashSet(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint) { }
911 HashSet(
const SelfType& src) : BaseType(src) { }
914 void operator = (
const SelfType& src) { BaseType::Assign(
this, src); }
920 void Set(
const CRef& key)
922 BaseType::Set(
this, key);
926 inline void Add(
const CRef& key)
928 BaseType::Add(
this, key);
935 BaseType::CheckExpand(
this);
941 BaseType::SetCapacity(
this, n);
947 void SetCapacity(UPInt newSize)
949 BaseType::SetCapacity(
this, newSize);
955 template<
class C,
class HashF = FixedSizeHash<C>,
956 class AltHashF = HashF,
957 int SID = Stat_Default_Mem,
958 class Entry = HashsetCachedEntry<C, HashF> >
959 class HashSetLH :
public HashSet<C, HashF, AltHashF, AllocatorLH<C, SID>, Entry>
962 typedef HashSetLH<C, HashF, AltHashF, SID, Entry> SelfType;
963 typedef HashSet<C, HashF, AltHashF, AllocatorLH<C, SID>, Entry > BaseType;
967 HashSetLH(
int sizeHint) : BaseType(sizeHint) { }
968 HashSetLH(
const SelfType& src) : BaseType(src) { }
971 void operator = (
const SelfType& src)
973 BaseType::operator = (src);
977 template<
class C,
class HashF = FixedSizeHash<C>,
978 class AltHashF = HashF,
979 int SID = Stat_Default_Mem,
980 class Entry = HashsetCachedEntry<C, HashF> >
981 class HashSetDH :
public HashSetBase<C, HashF, AltHashF, AllocatorDH<C, SID>, Entry>
985 typedef HashSetDH<C, HashF, AltHashF, SID, Entry> SelfType;
986 typedef HashSetBase<C, HashF, AltHashF, AllocatorDH<C, SID>, Entry> BaseType;
988 explicit HashSetDH(
void* pheap) : pHeap(pheap) { }
989 HashSetDH(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint), pHeap(pheap) { }
990 HashSetDH(
const SelfType& src) : BaseType(src), pHeap(src.pHeap) { }
993 void operator = (
const SelfType& src)
995 BaseType::Assign(src.pHeap, src);
1002 template<
class CRef>
1003 void Set(
const CRef& key)
1005 BaseType::Set(pHeap, key);
1008 template<
class CRef>
1009 inline void Add(
const CRef& key)
1011 BaseType::Add(pHeap, key);
1018 BaseType::CheckExpand(
this);
1022 void Resize(UPInt n)
1024 BaseType::SetCapacity(pHeap, n);
1030 void SetCapacity(UPInt newSize)
1032 BaseType::SetCapacity(pHeap, newSize);
1038 template<
class C,
class HashF = FixedSizeHash<C>,
1039 class AltHashF = HashF,
1040 class Allocator = AllocatorGH<C> >
1041 class HashSetUncached :
public HashSet<C, HashF, AltHashF, Allocator, HashsetEntry<C, HashF> >
1045 typedef HashSetUncached<C, HashF, AltHashF, Allocator> SelfType;
1046 typedef HashSet<C, HashF, AltHashF, Allocator, HashsetEntry<C, HashF> > BaseType;
1049 HashSetUncached() { }
1050 HashSetUncached(
int sizeHint) : BaseType(sizeHint) { }
1051 HashSetUncached(
const SelfType& src) : BaseType(src) { }
1052 ~HashSetUncached() { }
1054 void operator = (
const SelfType& src)
1056 BaseType::operator = (src);
1061 template<
class C,
class HashF = FixedSizeHash<C>,
1062 class AltHashF = HashF,
1063 int SID = Stat_Default_Mem >
1064 class HashSetUncachedLH :
public HashSet<C, HashF, AltHashF, AllocatorLH<C, SID>, HashsetEntry<C, HashF> >
1068 typedef HashSetUncachedLH<C, HashF, AltHashF, SID> SelfType;
1069 typedef HashSet<C, HashF, AltHashF, AllocatorLH<C, SID>, HashsetEntry<C, HashF> > BaseType;
1072 HashSetUncachedLH() { }
1073 HashSetUncachedLH(
int sizeHint) : BaseType(sizeHint) { }
1074 HashSetUncachedLH(
const SelfType& src) : BaseType(src) { }
1075 ~HashSetUncachedLH() { }
1077 void operator = (
const SelfType& src)
1079 BaseType::operator = (src);
1085 class HashF = FixedSizeHash<C>,
1086 class AltHashF = HashF,
1087 int SID = Stat_Default_Mem >
1088 class HashSetUncachedDH :
public HashSetDH<C, HashF, AltHashF, SID, HashsetEntry<C, HashF> >
1092 typedef HashSetUncachedDH<C, HashF, AltHashF, SID> SelfType;
1093 typedef HashSetDH<C, HashF, AltHashF, SID, HashsetEntry<C, HashF> > BaseType;
1096 explicit HashSetUncachedDH(
void* pheap) : BaseType(pheap) { }
1097 HashSetUncachedDH(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint) { }
1098 HashSetUncachedDH(
const SelfType& src) : BaseType(src) { }
1099 ~HashSetUncachedDH() { }
1101 void operator = (
const SelfType& src)
1103 BaseType::operator = (src);
1113 template<
class C,
class U,
class HashF>
1116 typedef HashNode<C, U, HashF> SelfType;
1117 typedef C FirstType;
1118 typedef U SecondType;
1130 NodeRef(
const C& f,
const U& s) : pFirst(&f), pSecond(&s) { }
1131 NodeRef(
const NodeRef& src) : pFirst(src.pFirst), pSecond(src.pSecond) { }
1134 inline UPInt GetHash()
const {
return HashF()(*pFirst); }
1136 operator const C& ()
const {
return *pFirst; }
1140 HashNode(
const HashNode& src) : First(src.First), Second(src.Second) { }
1141 HashNode(
const NodeRef& src) : First(*src.pFirst), Second(*src.pSecond) { }
1142 void operator = (
const NodeRef& src) { First = *src.pFirst; Second = *src.pSecond; }
1146 bool operator == (
const K& src)
const {
return (First == src); }
1149 static UPInt CalcHash(
const K& data) {
return HashF()(data); }
1150 inline UPInt GetHash()
const {
return HashF()(First); }
1157 UPInt operator()(
const K& data)
const {
return data.GetHash(); }
1162 UPInt operator()(
const K& data)
const {
return HashNode<C,U,HashF>::CalcHash(data); }
1176 template<
class C,
class HashF>
1177 class HashsetNodeEntry
1185 : NextInChain(-2) { }
1186 HashsetNodeEntry(
const HashsetNodeEntry& e)
1187 : NextInChain(e.NextInChain), Value(e.Value) { }
1188 HashsetNodeEntry(
const C& key, SPInt next)
1189 : NextInChain(next), Value(key) { }
1190 HashsetNodeEntry(
const typename C::NodeRef& keyRef, SPInt next)
1191 : NextInChain(next), Value(keyRef) { }
1193 bool IsEmpty()
const {
return NextInChain == -2; }
1194 bool IsEndOfChain()
const {
return NextInChain == -1; }
1195 UPInt GetCachedHash(UPInt maskValue)
const {
return HashF()(Value) & maskValue; }
1196 void SetCachedHash(UPInt hashValue) { KY_UNUSED(hashValue); }
1205 void Free() { Clear(); }
1210 template<
class C,
class HashF>
1211 class HashsetCachedNodeEntry
1219 HashsetCachedNodeEntry()
1220 : NextInChain(-2) { }
1221 HashsetCachedNodeEntry(
const HashsetCachedNodeEntry& e)
1222 : NextInChain(e.NextInChain), HashValue(e.HashValue), Value(e.Value) { }
1223 HashsetCachedNodeEntry(
const C& key, SPInt next)
1224 : NextInChain(next), Value(key) { }
1225 HashsetCachedNodeEntry(
const typename C::NodeRef& keyRef, SPInt next)
1226 : NextInChain(next), Value(keyRef) { }
1228 bool IsEmpty()
const {
return NextInChain == -2; }
1229 bool IsEndOfChain()
const {
return NextInChain == -1; }
1230 UPInt GetCachedHash(UPInt maskValue)
const { KY_UNUSED(maskValue);
return HashValue; }
1231 void SetCachedHash(UPInt hashValue) { HashValue = hashValue; }
1240 void Free() { Clear(); }
1244 template<
class C,
class U,
1245 class HashF = FixedSizeHash<C>,
1246 class Allocator = AllocatorGH<C>,
1247 class HashNode = Kaim::HashNode<C,U,HashF>,
1248 class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF>,
1249 class Container = HashSet<HashNode,
typename HashNode::NodeHashF,
1250 typename HashNode::NodeAltHashF, Allocator,
1255 KY_MEMORY_REDEFINE_NEW(Hash, Allocator::StatId)
1258 typedef U ValueType;
1259 typedef Hash<C, U, HashF, Allocator, HashNode, Entry, Container> SelfType;
1266 Hash(
int sizeHint) : mHash(sizeHint) { }
1267 explicit Hash(
void* pheap) : mHash(pheap) { }
1268 Hash(
void* pheap,
int sizeHint) : mHash(pheap, sizeHint) { }
1269 Hash(
const SelfType& src) : mHash(src.mHash) { }
1272 void operator = (
const SelfType& src) { mHash = src.mHash; }
1275 inline void Clear() { mHash.Clear(); }
1277 inline bool IsEmpty()
const {
return mHash.IsEmpty(); }
1280 inline void Set(
const C& key,
const U& value)
1282 typename HashNode::NodeRef e(key, value);
1285 inline void Add(
const C& key,
const U& value)
1287 typename HashNode::NodeRef e(key, value);
1292 inline void Remove(
const C& key)
1294 mHash.RemoveAlt(key);
1297 inline void RemoveAlt(
const K& key)
1299 mHash.RemoveAlt(key);
1306 bool Get(
const C& key, U* pvalue)
const
1308 const HashNode* p = mHash.GetAlt(key);
1312 *pvalue = p->Second;
1319 bool GetAlt(
const K& key, U* pvalue)
const
1321 const HashNode* p = mHash.GetAlt(key);
1325 *pvalue = p->Second;
1334 inline U* Get(
const C& key)
1336 HashNode* p = mHash.GetAlt(key);
1337 return p ? &p->Second : 0;
1339 inline const U* Get(
const C& key)
const
1341 const HashNode* p = mHash.GetAlt(key);
1342 return p ? &p->Second : 0;
1346 inline U* GetAlt(
const K& key)
1348 HashNode* p = mHash.GetAlt(key);
1349 return p ? &p->Second : 0;
1352 inline const U* GetAlt(
const K& key)
const
1354 const HashNode* p = mHash.GetAlt(key);
1355 return p ? &p->Second : 0;
1359 inline UPInt GetSize()
const {
return mHash.GetSize(); }
1360 inline void Resize(UPInt n) { mHash.Resize(n); }
1361 inline void SetCapacity(UPInt newSize) { mHash.SetCapacity(newSize); }
1364 typedef typename Container::ConstIterator ConstIterator;
1365 typedef typename Container::Iterator Iterator;
1367 inline Iterator Begin() {
return mHash.Begin(); }
1368 inline Iterator End() {
return mHash.End(); }
1369 inline ConstIterator Begin()
const {
return mHash.Begin(); }
1370 inline ConstIterator End()
const {
return mHash.End(); }
1372 Iterator Find(
const C& key) {
return mHash.FindAlt(key); }
1373 ConstIterator Find(
const C& key)
const {
return mHash.FindAlt(key); }
1376 Iterator FindAlt(
const K& key) {
return mHash.FindAlt(key); }
1378 ConstIterator FindAlt(
const K& key)
const {
return mHash.FindAlt(key); }
1384 template<
class C,
class U,
1385 class HashF = FixedSizeHash<C>,
1386 int SID = Stat_Default_Mem,
1387 class HashNode = Kaim::HashNode<C,U,HashF>,
1388 class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF> >
1390 :
public Hash<C, U, HashF, AllocatorLH<C, SID>, HashNode, Entry>
1393 typedef HashLH<C, U, HashF, SID, HashNode, Entry> SelfType;
1394 typedef Hash<C, U, HashF, AllocatorLH<C, SID>, HashNode, Entry> BaseType;
1398 HashLH(
int sizeHint) : BaseType(sizeHint) { }
1399 HashLH(
const SelfType& src) : BaseType(src) { }
1401 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1406 template<
class C,
class U,
1407 class HashF = FixedSizeHash<C>,
1408 int SID = Stat_Default_Mem,
1409 class HashNode = Kaim::HashNode<C,U,HashF>,
1410 class Entry = HashsetCachedNodeEntry<HashNode, typename HashNode::NodeHashF> >
1412 :
public Hash<C, U, HashF, AllocatorDH<C, SID>, HashNode, Entry,
1413 HashSetDH<HashNode, typename HashNode::NodeHashF,
1414 typename HashNode::NodeAltHashF, SID, Entry> >
1417 typedef HashDH<C, U, HashF, SID, HashNode, Entry> SelfType;
1418 typedef Hash<C, U, HashF, AllocatorDH<C, SID>, HashNode, Entry,
1419 HashSetDH<HashNode,
typename HashNode::NodeHashF,
1420 typename HashNode::NodeAltHashF, SID, Entry> > BaseType;
1423 explicit HashDH(
void* pheap) : BaseType(pheap) { }
1424 HashDH(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint) { }
1425 HashDH(
const SelfType& src) : BaseType(src) { }
1427 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1432 template<
class C,
class U,
class HashF = FixedSizeHash<C>,
class Allocator = AllocatorGH<C> >
1434 :
public Hash<C, U, HashF, Allocator, HashNode<C,U,HashF>,
1435 HashsetNodeEntry<HashNode<C,U,HashF>, typename HashNode<C,U,HashF>::NodeHashF> >
1438 typedef HashUncached<C, U, HashF, Allocator> SelfType;
1439 typedef Hash<C, U, HashF, Allocator, HashNode<C,U,HashF>,
1440 HashsetNodeEntry<HashNode<C,U,HashF>,
typename HashNode<C,U,HashF>::NodeHashF> > BaseType;
1444 HashUncached(
int sizeHint) : BaseType(sizeHint) { }
1445 HashUncached(
const SelfType& src) : BaseType(src) { }
1447 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1452 template<
class C,
class U,
class HashF = FixedSizeHash<C>,
int StatId = Stat_Default_Mem>
1453 class HashUncachedLH
1454 :
public HashLH<C, U, HashF, StatId, HashNode<C,U,HashF>,
1455 HashsetNodeEntry<HashNode<C,U,HashF>, typename HashNode<C,U,HashF>::NodeHashF> >
1458 typedef HashUncachedLH<C, U, HashF, StatId> SelfType;
1459 typedef HashLH<C, U, HashF, StatId, HashNode<C,U,HashF>,
1460 HashsetNodeEntry<HashNode<C,U,HashF>,
typename HashNode<C,U,HashF>::NodeHashF> > BaseType;
1463 HashUncachedLH() { }
1464 HashUncachedLH(
int sizeHint) : BaseType(sizeHint) { }
1465 HashUncachedLH(
const SelfType& src) : BaseType(src) { }
1466 ~HashUncachedLH() { }
1467 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1471 template<
class C,
class U,
class HashF = FixedSizeHash<C>,
int StatId = Stat_Default_Mem>
1472 class HashUncachedDH
1473 :
public HashDH<C, U, HashF, StatId, HashNode<C,U,HashF>,
1474 HashsetNodeEntry<HashNode<C,U,HashF>, typename HashNode<C,U,HashF>::NodeHashF> >
1477 typedef HashUncachedDH<C, U, HashF, StatId> SelfType;
1478 typedef HashDH<C, U, HashF, StatId, HashNode<C,U,HashF>,
1479 HashsetNodeEntry<HashNode<C,U,HashF>,
typename HashNode<C,U,HashF>::NodeHashF> > BaseType;
1482 explicit HashUncachedDH(
void* pheap) : BaseType(pheap) { }
1483 HashUncachedDH(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint) { }
1484 HashUncachedDH(
const SelfType& src) : BaseType(src) { }
1485 ~HashUncachedDH() { }
1486 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1491 template<
class C,
class U,
class Allocator = AllocatorGH<C>,
class HashF = IdentityHash<C> >
1493 :
public HashUncached<C, U, HashF, Allocator>
1496 typedef HashIdentity<C, U, Allocator, HashF> SelfType;
1497 typedef HashUncached<C, U, HashF, Allocator> BaseType;
1501 HashIdentity(
int sizeHint) : BaseType(sizeHint) { }
1502 HashIdentity(
const SelfType& src) : BaseType(src) { }
1504 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1510 template<
class C,
class U,
int SID = Stat_Default_Mem,
class HashF = IdentityHash<C> >
1511 class HashIdentityLH
1512 :
public HashUncachedLH<C, U, HashF, SID>
1515 typedef HashIdentityLH<C, U, SID, HashF> SelfType;
1516 typedef HashUncachedLH<C, U, HashF, SID> BaseType;
1519 HashIdentityLH() { }
1520 HashIdentityLH(
int sizeHint) : BaseType(sizeHint) { }
1521 HashIdentityLH(
const SelfType& src) : BaseType(src) { }
1522 ~HashIdentityLH() { }
1523 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1527 template<
class C,
class U,
int SID = Stat_Default_Mem,
class HashF = IdentityHash<C> >
1528 class HashIdentityDH
1529 :
public HashUncachedDH<C, U, HashF, SID>
1532 typedef HashIdentityDH<C, U, SID, HashF> SelfType;
1533 typedef HashUncachedDH<C, U, HashF, SID> BaseType;
1536 explicit HashIdentityDH(
void* pheap) : BaseType(pheap) { }
1537 HashIdentityDH(
void* pheap,
int sizeHint) : BaseType(pheap, sizeHint) { }
1538 HashIdentityDH(
const SelfType& src) : BaseType(src) { }
1539 ~HashIdentityDH() { }
1540 void operator = (
const SelfType& src) { BaseType::operator = (src); }
1546 #if defined(KY_DEFINE_NEW)
1547 #define new KY_DEFINE_NEW
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
Vec2f operator*(KyFloat32 s, const Vec2f &v)
scalar * vec operator
Definition: vec2f.h:120