14#ifndef WPIUTIL_WPI_DENSEMAP_H
15#define WPIUTIL_WPI_DENSEMAP_H
20#include "wpi/util/Compiler.hpp"
30#include <initializer_list>
42template <
typename KeyT,
typename ValueT>
44 using std::pair<KeyT, ValueT>::pair;
46 KeyT &
getFirst() {
return std::pair<KeyT, ValueT>::first; }
47 const KeyT &
getFirst()
const {
return std::pair<KeyT, ValueT>::first; }
48 ValueT &
getSecond() {
return std::pair<KeyT, ValueT>::second; }
49 const ValueT &
getSecond()
const {
return std::pair<KeyT, ValueT>::second; }
54template <
typename KeyT,
typename ValueT,
55 typename KeyInfoT = DenseMapInfo<KeyT>,
58class DenseMapIterator;
60template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
82 return makeIterator(getBucketsEnd() - 1, getBuckets(), *
this);
83 return makeIterator(getBuckets(), getBucketsEnd(), *
this);
86 return makeIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
92 return makeConstIterator(getBucketsEnd() - 1, getBuckets(), *
this);
93 return makeConstIterator(getBuckets(), getBucketsEnd(), *
this);
96 return makeConstIterator(getBucketsEnd(), getBucketsEnd(), *
this,
true);
99 [[nodiscard]]
bool empty()
const {
return getNumEntries() == 0; }
100 unsigned size()
const {
return getNumEntries(); }
107 if (NumBuckets > getNumBuckets())
113 if (getNumEntries() == 0 && getNumTombstones() == 0)
118 if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
124 if constexpr (std::is_trivially_destructible_v<ValueT>) {
126 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P)
127 P->getFirst() = EmptyKey;
130 [[maybe_unused]]
unsigned NumEntries = getNumEntries();
131 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
132 if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
133 if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
134 P->getSecond().~ValueT();
137 P->getFirst() = EmptyKey;
140 assert(NumEntries == 0 &&
"Node count imbalance!");
149 return doFind(Val) !=
nullptr;
158 if (BucketT *Bucket = doFind(Val))
165 if (
const BucketT *Bucket = doFind(Val))
166 return makeConstIterator(
178 if (BucketT *Bucket = doFind(Val))
184 template <
class LookupKeyT>
186 if (
const BucketT *Bucket = doFind(Val))
187 return makeConstIterator(
195 ValueT
lookup(const_arg_type_t<KeyT> Val)
const {
196 if (
const BucketT *Bucket = doFind(Val))
197 return Bucket->getSecond();
203 const ValueT &
at(const_arg_type_t<KeyT> Val)
const {
204 auto Iter = this->
find(std::move(Val));
205 assert(Iter != this->
end() &&
"DenseMap::at failed due to a missing key");
212 std::pair<iterator, bool>
insert(
const std::pair<KeyT, ValueT> &KV) {
219 std::pair<iterator, bool>
insert(std::pair<KeyT, ValueT> &&KV) {
220 return try_emplace(std::move(KV.first), std::move(KV.second));
226 template <
typename... Ts>
229 if (LookupBucketFor(Key, TheBucket))
230 return std::make_pair(makeIterator(TheBucket,
239 InsertIntoBucket(TheBucket, std::move(Key), std::forward<Ts>(Args)...);
240 return std::make_pair(makeIterator(TheBucket,
251 template <
typename... Ts>
252 std::pair<iterator, bool>
try_emplace(
const KeyT &Key, Ts &&...Args) {
254 if (LookupBucketFor(Key, TheBucket))
255 return std::make_pair(makeIterator(TheBucket,
263 TheBucket = InsertIntoBucket(TheBucket, Key, std::forward<Ts>(Args)...);
264 return std::make_pair(makeIterator(TheBucket,
277 template <
typename LookupKeyT>
278 std::pair<iterator, bool>
insert_as(std::pair<KeyT, ValueT> &&KV,
279 const LookupKeyT &Val) {
281 if (LookupBucketFor(Val, TheBucket))
282 return std::make_pair(makeIterator(TheBucket,
290 TheBucket = InsertIntoBucketWithLookup(TheBucket, std::move(KV.first),
291 std::move(KV.second), Val);
292 return std::make_pair(makeIterator(TheBucket,
301 template <
typename InputIt>
void insert(InputIt I, InputIt E) {
306 template <
typename V>
310 Ret.first->second = std::forward<V>(Val);
314 template <
typename V>
316 auto Ret =
try_emplace(std::move(Key), std::forward<V>(Val));
318 Ret.first->second = std::forward<V>(Val);
323 BucketT *TheBucket = doFind(Val);
327 TheBucket->getSecond().~ValueT();
329 decrementNumEntries();
330 incrementNumTombstones();
334 BucketT *TheBucket = &*I;
335 TheBucket->getSecond().~ValueT();
337 decrementNumEntries();
338 incrementNumTombstones();
343 if (LookupBucketFor(Key, TheBucket))
344 return TheBucket->second;
346 return InsertIntoBucket(TheBucket, Key)->second;
351 if (LookupBucketFor(Key, TheBucket))
352 return TheBucket->second;
354 return InsertIntoBucket(TheBucket, std::move(Key))->second;
361 return Ptr >= getBuckets() && Ptr < getBucketsEnd();
373 if (getNumBuckets() == 0)
377 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
378 if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey) &&
379 !KeyInfoT::isEqual(P->getFirst(), TombstoneKey))
380 P->getSecond().~ValueT();
381 P->getFirst().~KeyT();
389 assert((getNumBuckets() & (getNumBuckets() - 1)) == 0 &&
390 "# initial buckets must be a power of two!");
392 for (BucketT *B = getBuckets(), *E = getBucketsEnd(); B != E; ++B)
393 ::new (&B->getFirst()) KeyT(EmptyKey);
404 return static_cast<unsigned>(
NextPowerOf2(NumEntries * 4 / 3 + 1));
413 for (BucketT *B = OldBucketsBegin, *E = OldBucketsEnd; B != E; ++B) {
414 if (!KeyInfoT::isEqual(B->getFirst(), EmptyKey) &&
415 !KeyInfoT::isEqual(B->getFirst(), TombstoneKey)) {
418 bool FoundVal = LookupBucketFor(B->getFirst(), DestBucket);
420 assert(!FoundVal &&
"Key already in new map?");
421 DestBucket->getFirst() = std::move(B->getFirst());
422 ::new (&DestBucket->getSecond()) ValueT(std::move(B->getSecond()));
423 incrementNumEntries();
426 B->getSecond().~ValueT();
428 B->getFirst().~KeyT();
432 template <
typename OtherBaseT>
435 assert(&other !=
this);
436 assert(getNumBuckets() == other.getNumBuckets());
438 setNumEntries(other.getNumEntries());
439 setNumTombstones(other.getNumTombstones());
441 BucketT *Buckets = getBuckets();
442 const BucketT *OtherBuckets = other.getBuckets();
443 const size_t NumBuckets = getNumBuckets();
444 if constexpr (std::is_trivially_copyable_v<KeyT> &&
445 std::is_trivially_copyable_v<ValueT>) {
446 memcpy(
reinterpret_cast<void *
>(Buckets), OtherBuckets,
447 NumBuckets *
sizeof(BucketT));
451 for (
size_t I = 0; I < NumBuckets; ++I) {
452 ::new (&Buckets[I].getFirst()) KeyT(OtherBuckets[I].getFirst());
453 if (!KeyInfoT::isEqual(Buckets[I].getFirst(), EmptyKey) &&
454 !KeyInfoT::isEqual(Buckets[I].getFirst(), TombstoneKey))
455 ::new (&Buckets[I].getSecond()) ValueT(OtherBuckets[I].getSecond());
461 return KeyInfoT::getHashValue(Val);
464 template <
typename LookupKeyT>
466 return KeyInfoT::getHashValue(Val);
470 static_assert(std::is_base_of_v<DenseMapBase, DerivedT>,
471 "Must pass the derived type to this template!");
472 return KeyInfoT::getEmptyKey();
479 bool NoAdvance =
false) {
481 BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
482 return iterator(B, E, Epoch, NoAdvance);
484 return iterator(P, E, Epoch, NoAdvance);
487 const_iterator makeConstIterator(
const BucketT *P,
const BucketT *E,
488 const DebugEpochBase &Epoch,
489 const bool NoAdvance =
false)
const {
491 const BucketT *B = P == getBucketsEnd() ? getBuckets() : P + 1;
497 unsigned getNumEntries()
const {
498 return static_cast<const DerivedT *
>(
this)->getNumEntries();
501 void setNumEntries(
unsigned Num) {
502 static_cast<DerivedT *
>(
this)->setNumEntries(Num);
505 void incrementNumEntries() { setNumEntries(getNumEntries() + 1); }
507 void decrementNumEntries() { setNumEntries(getNumEntries() - 1); }
509 unsigned getNumTombstones()
const {
510 return static_cast<const DerivedT *
>(
this)->getNumTombstones();
513 void setNumTombstones(
unsigned Num) {
514 static_cast<DerivedT *
>(
this)->setNumTombstones(Num);
517 void incrementNumTombstones() { setNumTombstones(getNumTombstones() + 1); }
519 void decrementNumTombstones() { setNumTombstones(getNumTombstones() - 1); }
521 const BucketT *getBuckets()
const {
522 return static_cast<const DerivedT *
>(
this)->getBuckets();
525 BucketT *getBuckets() {
return static_cast<DerivedT *
>(
this)->getBuckets(); }
527 unsigned getNumBuckets()
const {
528 return static_cast<const DerivedT *
>(
this)->getNumBuckets();
531 BucketT *getBucketsEnd() {
return getBuckets() + getNumBuckets(); }
533 const BucketT *getBucketsEnd()
const {
534 return getBuckets() + getNumBuckets();
537 void grow(
unsigned AtLeast) {
static_cast<DerivedT *
>(
this)->grow(AtLeast); }
539 void shrink_and_clear() {
static_cast<DerivedT *
>(
this)->shrink_and_clear(); }
541 template <
typename KeyArg,
typename... ValueArgs>
542 BucketT *InsertIntoBucket(BucketT *TheBucket, KeyArg &&Key,
543 ValueArgs &&...Values) {
544 TheBucket = InsertIntoBucketImpl(Key, TheBucket);
546 TheBucket->getFirst() = std::forward<KeyArg>(Key);
547 ::new (&TheBucket->getSecond()) ValueT(std::forward<ValueArgs>(Values)...);
551 template <typename LookupKeyT>
552 BucketT *InsertIntoBucketWithLookup(BucketT *TheBucket, KeyT &&Key,
553 ValueT &&Value, LookupKeyT &Lookup) {
554 TheBucket = InsertIntoBucketImpl(Lookup, TheBucket);
556 TheBucket->getFirst() = std::move(Key);
557 ::new (&TheBucket->getSecond()) ValueT(std::move(Value));
561 template <typename LookupKeyT>
562 BucketT *InsertIntoBucketImpl(const LookupKeyT &Lookup, BucketT *TheBucket) {
574 unsigned NewNumEntries = getNumEntries() + 1;
575 unsigned NumBuckets = getNumBuckets();
576 if (LLVM_UNLIKELY(NewNumEntries * 4 >= NumBuckets * 3)) {
577 this->grow(NumBuckets * 2);
578 LookupBucketFor(Lookup, TheBucket);
579 NumBuckets = getNumBuckets();
580 }
else if (LLVM_UNLIKELY(NumBuckets -
581 (NewNumEntries + getNumTombstones()) <=
583 this->grow(NumBuckets);
584 LookupBucketFor(Lookup, TheBucket);
590 incrementNumEntries();
594 if (!KeyInfoT::isEqual(TheBucket->getFirst(), EmptyKey))
595 decrementNumTombstones();
600 template <
typename LookupKeyT> BucketT *doFind(
const LookupKeyT &Val) {
601 BucketT *BucketsPtr = getBuckets();
602 const unsigned NumBuckets = getNumBuckets();
607 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
608 unsigned ProbeAmt = 1;
610 BucketT *Bucket = BucketsPtr + BucketNo;
611 if (LLVM_LIKELY(KeyInfoT::isEqual(Val, Bucket->getFirst())))
613 if (LLVM_LIKELY(KeyInfoT::isEqual(Bucket->getFirst(), EmptyKey)))
618 BucketNo += ProbeAmt++;
619 BucketNo &= NumBuckets - 1;
623 template <
typename LookupKeyT>
624 const BucketT *doFind(
const LookupKeyT &Val)
const {
632 template <
typename LookupKeyT>
633 bool LookupBucketFor(
const LookupKeyT &Val, BucketT *&FoundBucket) {
634 BucketT *BucketsPtr = getBuckets();
635 const unsigned NumBuckets = getNumBuckets();
637 if (NumBuckets == 0) {
638 FoundBucket =
nullptr;
643 BucketT *FoundTombstone =
nullptr;
646 assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
647 !KeyInfoT::isEqual(Val, TombstoneKey) &&
648 "Empty/Tombstone value shouldn't be inserted into map!");
650 unsigned BucketNo =
getHashValue(Val) & (NumBuckets - 1);
651 unsigned ProbeAmt = 1;
653 BucketT *ThisBucket = BucketsPtr + BucketNo;
655 if (LLVM_LIKELY(KeyInfoT::isEqual(Val, ThisBucket->getFirst()))) {
656 FoundBucket = ThisBucket;
662 if (LLVM_LIKELY(KeyInfoT::isEqual(ThisBucket->getFirst(), EmptyKey))) {
665 FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
671 if (KeyInfoT::isEqual(ThisBucket->getFirst(), TombstoneKey) &&
673 FoundTombstone = ThisBucket;
677 BucketNo += ProbeAmt++;
678 BucketNo &= (NumBuckets - 1);
696template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
704 for (
auto &KV : LHS) {
705 auto I = RHS.
find(KV.first);
706 if (I == RHS.
end() || I->second != KV.second)
716template <
typename DerivedT,
typename KeyT,
typename ValueT,
typename KeyInfoT,
721 return !(LHS == RHS);
724template <
typename KeyT,
typename ValueT,
725 typename KeyInfoT = DenseMapInfo<KeyT>,
728 KeyT, ValueT, KeyInfoT, BucketT> {
737 unsigned NumTombstones;
743 explicit DenseMap(
unsigned InitialReserve = 0) {
init(InitialReserve); }
755 template <
typename InputIt>
DenseMap(
const InputIt &I,
const InputIt &E) {
756 init(std::distance(I, E));
760 DenseMap(std::initializer_list<typename BaseT::value_type> Vals) {
762 this->
insert(Vals.begin(), Vals.end());
775 std::swap(NumTombstones, RHS.NumTombstones);
796 if (allocateBuckets(other.NumBuckets)) {
804 void init(
unsigned InitNumEntries) {
806 if (allocateBuckets(InitBuckets)) {
815 unsigned OldNumBuckets = NumBuckets;
816 BucketT *OldBuckets = Buckets;
818 allocateBuckets(std::max<unsigned>(
834 unsigned OldNumBuckets = NumBuckets;
835 unsigned OldNumEntries = NumEntries;
839 unsigned NewNumBuckets = 0;
841 NewNumBuckets = (std::max)(64, 1 << (
Log2_32_Ceil(OldNumEntries) + 1));
842 if (NewNumBuckets == NumBuckets) {
853 unsigned getNumEntries()
const {
return NumEntries; }
855 void setNumEntries(
unsigned Num) { NumEntries = Num; }
857 unsigned getNumTombstones()
const {
return NumTombstones; }
859 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
861 BucketT *getBuckets()
const {
return Buckets; }
863 unsigned getNumBuckets()
const {
return NumBuckets; }
865 bool allocateBuckets(
unsigned Num) {
867 if (NumBuckets == 0) {
872 Buckets =
static_cast<BucketT *
>(
878template <
typename KeyT,
typename ValueT,
unsigned InlineBuckets = 4,
879 typename KeyInfoT = DenseMapInfo<KeyT>,
883 SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
884 ValueT, KeyInfoT, BucketT> {
892 "InlineBuckets must be a power of 2.");
895 unsigned NumEntries : 31;
896 unsigned NumTombstones;
909 if (NumInitBuckets > InlineBuckets)
910 NumInitBuckets = std::bit_ceil(NumInitBuckets);
911 init(NumInitBuckets);
924 template <
typename InputIt>
939 unsigned TmpNumEntries = RHS.NumEntries;
940 RHS.NumEntries = NumEntries;
941 NumEntries = TmpNumEntries;
942 std::swap(NumTombstones, RHS.NumTombstones);
946 if (Small && RHS.Small) {
951 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
952 BucketT *LHSB = &getInlineBuckets()[i],
953 *RHSB = &RHS.getInlineBuckets()[i];
954 bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->getFirst(), EmptyKey) &&
955 !KeyInfoT::isEqual(LHSB->getFirst(), TombstoneKey));
956 bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->getFirst(), EmptyKey) &&
957 !KeyInfoT::isEqual(RHSB->getFirst(), TombstoneKey));
958 if (hasLHSValue && hasRHSValue) {
964 std::swap(LHSB->getFirst(), RHSB->getFirst());
966 ::new (&RHSB->getSecond()) ValueT(std::move(LHSB->getSecond()));
967 LHSB->getSecond().~ValueT();
968 }
else if (hasRHSValue) {
969 ::new (&LHSB->getSecond()) ValueT(std::move(RHSB->getSecond()));
970 RHSB->getSecond().~ValueT();
975 if (!Small && !RHS.Small) {
976 std::swap(getLargeRep()->Buckets, RHS.getLargeRep()->Buckets);
977 std::swap(getLargeRep()->NumBuckets, RHS.getLargeRep()->NumBuckets);
985 LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
986 LargeSide.getLargeRep()->~LargeRep();
987 LargeSide.Small =
true;
992 for (
unsigned i = 0, e = InlineBuckets; i != e; ++i) {
993 BucketT *NewB = &LargeSide.getInlineBuckets()[i],
994 *OldB = &SmallSide.getInlineBuckets()[i];
995 ::new (&NewB->getFirst()) KeyT(std::move(OldB->getFirst()));
996 OldB->getFirst().~KeyT();
997 if (!KeyInfoT::isEqual(NewB->getFirst(), EmptyKey) &&
998 !KeyInfoT::isEqual(NewB->getFirst(), TombstoneKey)) {
999 ::new (&NewB->getSecond()) ValueT(std::move(OldB->getSecond()));
1000 OldB->getSecond().~ValueT();
1006 SmallSide.Small =
false;
1007 new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
1018 deallocateBuckets();
1026 deallocateBuckets();
1028 if (other.getNumBuckets() > InlineBuckets) {
1030 new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
1037 if (InitBuckets > InlineBuckets) {
1039 new (getLargeRep()) LargeRep(allocateBuckets(InitBuckets));
1045 if (AtLeast > InlineBuckets)
1046 AtLeast = std::max<unsigned>(64,
NextPowerOf2(AtLeast - 1));
1051 BucketT *TmpBegin =
reinterpret_cast<BucketT *
>(&TmpStorage);
1052 BucketT *TmpEnd = TmpBegin;
1058 for (BucketT *P = getBuckets(), *E = P + InlineBuckets; P != E; ++P) {
1059 if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey) &&
1060 !KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
1061 assert(
size_t(TmpEnd - TmpBegin) < InlineBuckets &&
1062 "Too many inline buckets!");
1063 ::new (&TmpEnd->getFirst()) KeyT(std::move(P->getFirst()));
1064 ::new (&TmpEnd->getSecond()) ValueT(std::move(P->getSecond()));
1066 P->getSecond().~ValueT();
1068 P->getFirst().~KeyT();
1074 if (AtLeast > InlineBuckets) {
1076 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1082 LargeRep OldRep = std::move(*getLargeRep());
1083 getLargeRep()->~LargeRep();
1084 if (AtLeast <= InlineBuckets) {
1087 new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
1091 OldRep.Buckets + OldRep.NumBuckets);
1099 unsigned OldSize = this->
size();
1103 unsigned NewNumBuckets = 0;
1106 if (NewNumBuckets > InlineBuckets && NewNumBuckets < 64u)
1109 if ((Small && NewNumBuckets <= InlineBuckets) ||
1110 (!Small && NewNumBuckets == getLargeRep()->NumBuckets)) {
1115 deallocateBuckets();
1116 init(NewNumBuckets);
1120 unsigned getNumEntries()
const {
return NumEntries; }
1122 void setNumEntries(
unsigned Num) {
1124 assert(Num < (1U << 31) &&
"Cannot support more than 1<<31 entries");
1128 unsigned getNumTombstones()
const {
return NumTombstones; }
1130 void setNumTombstones(
unsigned Num) { NumTombstones = Num; }
1132 const BucketT *getInlineBuckets()
const {
1137 return reinterpret_cast<const BucketT *
>(&storage);
1140 BucketT *getInlineBuckets() {
1141 return const_cast<BucketT *
>(
1142 const_cast<const SmallDenseMap *
>(
this)->getInlineBuckets());
1145 const LargeRep *getLargeRep()
const {
1148 return reinterpret_cast<const LargeRep *
>(&storage);
1151 LargeRep *getLargeRep() {
1152 return const_cast<LargeRep *
>(
1153 const_cast<const SmallDenseMap *
>(
this)->getLargeRep());
1156 const BucketT *getBuckets()
const {
1157 return Small ? getInlineBuckets() : getLargeRep()->Buckets;
1160 BucketT *getBuckets() {
1161 return const_cast<BucketT *
>(
1162 const_cast<const SmallDenseMap *
>(
this)->getBuckets());
1165 unsigned getNumBuckets()
const {
1166 return Small ? InlineBuckets : getLargeRep()->NumBuckets;
1169 void deallocateBuckets() {
1174 sizeof(BucketT) * getLargeRep()->NumBuckets,
1176 getLargeRep()->~LargeRep();
1179 LargeRep allocateBuckets(
unsigned Num) {
1180 assert(Num > InlineBuckets &&
"Must allocate more buckets than are inline");
1182 sizeof(BucketT) * Num,
alignof(BucketT))),
1188template <
typename KeyT,
typename ValueT,
typename KeyInfoT,
typename Bucket,
1196 using value_type = std::conditional_t<IsConst, const Bucket, Bucket>;
1209 bool NoAdvance =
false)
1216 RetreatPastEmptyBuckets();
1219 AdvancePastEmptyBuckets();
1225 template <
bool IsConstSrc,
1226 typename = std::enable_if_t<!IsConstSrc && IsConst>>
1233 assert(Ptr != End &&
"dereferencing end() iterator");
1240 assert(Ptr != End &&
"dereferencing end() iterator");
1248 assert((!LHS.Ptr || LHS.isHandleInSync()) &&
"handle not in sync!");
1249 assert((!RHS.Ptr || RHS.isHandleInSync()) &&
"handle not in sync!");
1250 assert(LHS.getEpochAddress() == RHS.getEpochAddress() &&
1251 "comparing incomparable iterators!");
1252 return LHS.Ptr == RHS.Ptr;
1257 return !(LHS == RHS);
1262 assert(Ptr != End &&
"incrementing end() iterator");
1265 RetreatPastEmptyBuckets();
1269 AdvancePastEmptyBuckets();
1280 void AdvancePastEmptyBuckets() {
1282 const KeyT Empty = KeyInfoT::getEmptyKey();
1283 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1285 while (Ptr != End && (KeyInfoT::isEqual(Ptr->getFirst(), Empty) ||
1286 KeyInfoT::isEqual(Ptr->getFirst(), Tombstone)))
1290 void RetreatPastEmptyBuckets() {
1292 const KeyT Empty = KeyInfoT::getEmptyKey();
1293 const KeyT Tombstone = KeyInfoT::getTombstoneKey();
1295 while (Ptr != End && (KeyInfoT::isEqual(Ptr[-1].getFirst(), Empty) ||
1296 KeyInfoT::isEqual(Ptr[-1].getFirst(), Tombstone)))
1301template <
typename KeyT,
typename ValueT,
typename KeyInfoT>
This file defines DenseMapInfo traits for DenseMap.
This file defines the DebugEpochBase and DebugEpochBase::HandleBase classes.
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
Definition EpochTracker.hpp:91
bool isHandleInSync() const
Definition EpochTracker.hpp:95
Definition EpochTracker.hpp:87
void incrementEpoch()
Definition EpochTracker.hpp:89
Definition DenseMap.hpp:62
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
Definition DenseMap.hpp:367
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive,...
Definition DenseMap.hpp:177
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.hpp:157
size_t getMemorySize() const
Return the approximate size (in bytes) of the actual map.
Definition DenseMap.hpp:687
bool erase(const KeyT &Val)
Definition DenseMap.hpp:322
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
Definition DenseMap.hpp:252
static unsigned getHashValue(const KeyT &Val)
Definition DenseMap.hpp:460
iterator begin()
Definition DenseMap.hpp:76
std::pair< iterator, bool > insert_or_assign(const KeyT &Key, V &&Val)
Definition DenseMap.hpp:307
const ValueT & at(const_arg_type_t< KeyT > Val) const
at - Return the entry for the specified key, or abort if no such entry exists.
Definition DenseMap.hpp:203
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition DenseMap.hpp:212
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd)
Definition DenseMap.hpp:407
const_iterator end() const
Definition DenseMap.hpp:95
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
Definition DenseMap.hpp:360
const_iterator find(const_arg_type_t< KeyT > Val) const
Definition DenseMap.hpp:164
std::pair< iterator, bool > insert(std::pair< KeyT, ValueT > &&KV)
Definition DenseMap.hpp:219
std::pair< iterator, bool > insert_or_assign(KeyT &&Key, V &&Val)
Definition DenseMap.hpp:315
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
Definition DenseMap.hpp:148
void erase(iterator I)
Definition DenseMap.hpp:333
ValueT & operator[](const KeyT &Key)
Definition DenseMap.hpp:341
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition DenseMap.hpp:195
const_iterator find_as(const LookupKeyT &Val) const
Definition DenseMap.hpp:185
iterator end()
Definition DenseMap.hpp:85
std::pair< iterator, bool > insert_as(std::pair< KeyT, ValueT > &&KV, const LookupKeyT &Val)
Alternate version of insert() which allows a different, and possibly less expensive,...
Definition DenseMap.hpp:278
ValueT mapped_type
Definition DenseMap.hpp:69
unsigned size() const
Definition DenseMap.hpp:100
const_iterator begin() const
Definition DenseMap.hpp:88
static const KeyT getTombstoneKey()
Definition DenseMap.hpp:475
static const KeyT getEmptyKey()
Definition DenseMap.hpp:469
void destroyAll()
Definition DenseMap.hpp:372
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
Definition DenseMap.hpp:72
void clear()
Definition DenseMap.hpp:111
void copyFrom(const DenseMapBase< OtherBaseT, KeyT, ValueT, KeyInfoT, BucketT > &other)
Definition DenseMap.hpp:433
BucketT value_type
Definition DenseMap.hpp:70
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.hpp:73
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again.
Definition DenseMap.hpp:104
ValueT & operator[](KeyT &&Key)
Definition DenseMap.hpp:349
void initEmpty()
Definition DenseMap.hpp:385
void insert(InputIt I, InputIt E)
insert - Range insertion of pairs.
Definition DenseMap.hpp:301
unsigned getMinBucketToReserveForEntries(unsigned NumEntries)
Returns the number of buckets to allocate to ensure that the DenseMap can accommodate NumEntries with...
Definition DenseMap.hpp:398
KeyT key_type
Definition DenseMap.hpp:68
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition DenseMap.hpp:153
unsigned size_type
Definition DenseMap.hpp:67
static unsigned getHashValue(const LookupKeyT &Val)
Definition DenseMap.hpp:465
bool empty() const
Definition DenseMap.hpp:99
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.hpp:227
Definition DenseMap.hpp:728
~DenseMap()
Definition DenseMap.hpp:765
void shrink_and_clear()
Definition DenseMap.hpp:833
DenseMap(const DenseMap &other)
Definition DenseMap.hpp:745
DenseMap(std::initializer_list< typename BaseT::value_type > Vals)
Definition DenseMap.hpp:760
DenseMap & operator=(DenseMap &&other)
Definition DenseMap.hpp:785
void swap(DenseMap &RHS)
Definition DenseMap.hpp:770
DenseMap(const InputIt &I, const InputIt &E)
Definition DenseMap.hpp:755
DenseMap & operator=(const DenseMap &other)
Definition DenseMap.hpp:779
DenseMap(DenseMap &&other)
Definition DenseMap.hpp:750
void grow(unsigned AtLeast)
Definition DenseMap.hpp:814
void init(unsigned InitNumEntries)
Definition DenseMap.hpp:804
void copyFrom(const DenseMap &other)
Definition DenseMap.hpp:793
DenseMap(unsigned InitialReserve=0)
Create a DenseMap with an optional InitialReserve that guarantee that this number of elements can be ...
Definition DenseMap.hpp:743
Definition DenseMap.hpp:1190
friend bool operator!=(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
Definition DenseMap.hpp:1255
value_type * pointer
Definition DenseMap.hpp:1197
DenseMapIterator(pointer Pos, pointer E, const DebugEpochBase &Epoch, bool NoAdvance=false)
Definition DenseMap.hpp:1208
DenseMapIterator(const DenseMapIterator< KeyT, ValueT, KeyInfoT, Bucket, IsConstSrc > &I)
Definition DenseMap.hpp:1227
pointer operator->() const
Definition DenseMap.hpp:1238
DenseMapIterator operator++(int)
Definition DenseMap.hpp:1272
std::conditional_t< IsConst, const BucketT, BucketT > value_type
Definition DenseMap.hpp:1196
reference operator*() const
Definition DenseMap.hpp:1231
DenseMapIterator & operator++()
Definition DenseMap.hpp:1260
ptrdiff_t difference_type
Definition DenseMap.hpp:1195
std::forward_iterator_tag iterator_category
Definition DenseMap.hpp:1199
friend bool operator==(const DenseMapIterator &LHS, const DenseMapIterator &RHS)
Definition DenseMap.hpp:1246
value_type & reference
Definition DenseMap.hpp:1198
DenseMapIterator()=default
SmallDenseMap & operator=(const SmallDenseMap &other)
Definition DenseMap.hpp:1010
SmallDenseMap & operator=(SmallDenseMap &&other)
Definition DenseMap.hpp:1016
SmallDenseMap(const InputIt &I, const InputIt &E)
Definition DenseMap.hpp:925
void init(unsigned InitBuckets)
Definition DenseMap.hpp:1035
SmallDenseMap(const SmallDenseMap &other)
Definition DenseMap.hpp:914
SmallDenseMap(SmallDenseMap &&other)
Definition DenseMap.hpp:919
void swap(SmallDenseMap &RHS)
Definition DenseMap.hpp:938
SmallDenseMap(unsigned NumInitBuckets=0)
Definition DenseMap.hpp:908
void grow(unsigned AtLeast)
Definition DenseMap.hpp:1044
SmallDenseMap(std::initializer_list< typename BaseT::value_type > Vals)
Definition DenseMap.hpp:930
~SmallDenseMap()
Definition DenseMap.hpp:933
void shrink_and_clear()
Definition DenseMap.hpp:1098
void copyFrom(const SmallDenseMap &other)
Definition DenseMap.hpp:1024
void swap(wpi::util::StringMap< T > &lhs, wpi::util::StringMap< T > &rhs)
Definition StringMap.hpp:775
These are wrappers over isa* function that allow them to be used in generic algorithms such as wpi::u...
Definition type_traits.hpp:71
Definition raw_os_ostream.hpp:19
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.).
Definition MathExtras.hpp:270
void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
constexpr bool operator!=(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:180
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
Definition MathExtras.hpp:327
size_t capacity_in_bytes(const DenseMap< KeyT, ValueT, KeyInfoT > &X)
Definition DenseMap.hpp:1302
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)
Allocate a buffer of memory with the given size and alignment.
bool shouldReverseIterate()
Definition ReverseIteration.hpp:9
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition MathExtras.hpp:356
constexpr bool operator==(const unexpected< E > &lhs, const unexpected< E > &rhs)
Definition expected:176
A suitably aligned and sized character array member which can hold elements of any type.
Definition AlignOf.hpp:23
const T & type
Definition type_traits.hpp:64
Definition DenseMap.hpp:43
KeyT & getFirst()
Definition DenseMap.hpp:46
const ValueT & getSecond() const
Definition DenseMap.hpp:49
const KeyT & getFirst() const
Definition DenseMap.hpp:47
ValueT & getSecond()
Definition DenseMap.hpp:48