7#include "Containers/Array.h"
12template<
typename T,
int32 InlineSize>
13struct TDynamicSparseBitSetBucketStorage;
16struct TFixedSparseBitSetBucketStorage;
18template<
typename HashType,
typename BucketStorage = TDynamicSparseBitSetBucketStorage<u
int8, 4>>
19struct TFixedSparseBitSet;
21template<
typename HashType,
typename BucketStorage = TDynamicSparseBitSetBucketStorage<u
int8, 4>>
22struct TDynamicSparseBitSet;
35 return FMath::CountTrailingZeros(
X);
40 return FMath::CountTrailingZeros(
X);
44 return FMath::CountTrailingZeros(In);
48 return static_cast<uint32>(FMath::CountTrailingZeros64(In));
52 template<
typename T,
typename U>
53 static T BitOffsetToLowBitMask(U BitOffset)
56 const T
Index =
static_cast<T
>(BitOffset);
61 template<
typename T,
typename U>
62 static T BitOffsetToHighBitMask(U BitOffset)
78template<
typename HashType,
typename BucketStorage>
90 template<
typename ...StorageArgs>
102 template<
typename OtherHashType,
typename OtherStorageType>
114 template<
typename OtherHashType,
typename OtherStorageType>
123 Other.BucketHash = this->BucketHash;
145 if ((BucketHash & HashBit) == 0)
154 BucketHash |= HashBit;
171 return FMath::CountBits(this->BucketHash);
180 Total += FMath::CountBits(Buckets.Get(
Index));
192 return this->BucketHash == 0;
203 CheckIndex(BitIndex);
205 FBitOffsets Offsets(BucketHash, BitIndex);
208 if ( (BucketHash & Offsets.HashBit) == 0)
210 BucketHash |= Offsets.HashBit;
211 Buckets.Insert(Offsets.BitMaskWithinBucket, Offsets.BucketIndex);
214 else if ((Buckets.Get(Offsets.BucketIndex) & Offsets.BitMaskWithinBucket) == 0)
216 Buckets.Get(Offsets.BucketIndex) |= Offsets.BitMaskWithinBucket;
228 CheckIndex(BitIndex);
231 const HashType HashBit = (HashType(1) <<
Hash);
232 if (BucketHash & HashBit)
234 const uint32 BucketIndex = FMath::CountBits(BucketHash & (HashBit-1));
248 CheckIndex(BitIndex);
251 const HashType HashBit = (HashType(1) <<
Hash);
252 if (BucketHash & HashBit)
254 uint32 BucketIndex = FMath::CountBits(BucketHash & (HashBit-1));
266 while (BucketIndex > 0)
269 SparseIndex += FMath::CountBits(Buckets.Get(BucketIndex));
282 , IndexWithinBucket(0)
291 It.CurrentBucket = 0;
295 It.BucketBitIndex = Private::CountTrailingZeros(
InBitSet->BucketHash);
296 It.CurrentBucket =
InBitSet->Buckets.Get(0);
297 It.IndexWithinBucket = Private::CountTrailingZeros(It.CurrentBucket);
302 It.IndexWithinBucket = 0;
310 It.CurrentBucket = 0;
312 It.IndexWithinBucket = 0;
321 CurrentBucket = CurrentBucket & (CurrentBucket - 1);
323 if (CurrentBucket != 0)
325 IndexWithinBucket = CountTrailingZeros(CurrentBucket);
332 IndexWithinBucket = 0;
343 IndexWithinBucket = 0;
349 IndexWithinBucket = CountTrailingZeros(CurrentBucket);
356 return BucketSize*BucketBitIndex + IndexWithinBucket;
366 return A.BitSet ==
B.BitSet &&
A.BucketBitIndex ==
B.BucketBitIndex &&
A.IndexWithinBucket ==
B.IndexWithinBucket;
375 uint8 BucketBitIndex;
376 uint8 IndexWithinBucket;
386 template<
typename,
typename>
389 inline void CheckIndex(
uint32 BitIndex)
const
402 HashBit = HashType(1) <<
Hash;
404 BucketIndex = FMath::CountBits(
InBucketHash & (HashBit-1u));
417template<
typename T,
int32 InlineSize = 8>
486template<
typename HashType,
typename BucketStorage>
506 const uint32 Bucket = Bit / NumBitsInBucket;
508 Bit -= Bucket*NumBitsInBucket;
513 for (
int32 EntryIndex = 0; EntryIndex <
Num; ++EntryIndex)
517 return EntrPtr[EntryIndex].Bits.SetBit(Bit);
522 new(&
Entries[EntryIndex]) FEntry(Bucket, Bit);
546 const uint32 Bucket = Bit / NumBitsInBucket;
551 for (
int32 EntryIndex = 0; EntryIndex <
Num; ++EntryIndex)
555 return EntrPtr[EntryIndex].Bits.IsBitSet(Bit);
572 for (
const FEntry& Entry :
Entries)
574 SetBits += Entry.Bits.CountSetBits();
582 if (
Other.Entries.Num() == 0)
660 It.Entries =
InBitSet->Entries.GetData();
661 It.NumEntries =
InBitSet->Entries.Num();
663 It.CurrentOffsetInBits = 0;
665 if (It.NumEntries != 0)
667 It.CurrentOffsetInBits = It.Entries[0].Offset * NumBitsInBucket;
668 It.BucketIt = BucketIterator::Begin(&It.Entries[0].Bits);
675 It.Entries =
InBitSet->Entries.GetData();
676 It.NumEntries =
InBitSet->Entries.Num();
677 It.EntryIndex = It.NumEntries;
678 It.CurrentOffsetInBits = 0;
690 if (EntryIndex < NumEntries)
692 CurrentOffsetInBits = Entries[EntryIndex].Offset * NumBitsInBucket;
693 BucketIt = BucketIterator::Begin(&Entries[EntryIndex].Bits);
697 CurrentOffsetInBits = 0;
698 BucketIt = BucketIterator();
705 return CurrentOffsetInBits + *BucketIt;
710 return EntryIndex < NumEntries;
715 return A.Entries ==
B.Entries &&
A.EntryIndex ==
B.EntryIndex &&
A.BucketIt ==
B.BucketIt;
727 BucketIterator BucketIt;
730 int32 CurrentOffsetInBits;
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define checkfSlow(expr, format,...)
Definition AssertionMacros.h:333
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
#define MAX_uint32
Definition NumericLimits.h:21
@ One
Definition PropertyPathHelpersTest.h:16
uint32 Offset
Definition VulkanMemory.cpp:4033
UE_REWRITE SizeType Num() const
Definition Array.h:1144
UE_NODEBUG UE_FORCEINLINE_HINT void InsertUninitialized(SizeType Index)
Definition Array.h:1782
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
UE_FORCEINLINE_HINT SizeType Emplace(ArgsType &&... Args)
Definition Array.h:2561
SizeType Insert(std::initializer_list< ElementType > InitList, const SizeType InIndex)
Definition Array.h:1875
Definition OverriddenPropertySet.cpp:45
Definition ConstraintsManager.h:14
ESparseBitSetBitResult
Definition SparseBitSet.h:25
U16 Index
Definition radfft.cpp:71
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
void Insert(BucketType InitialValue, int32 Index)
Definition SparseBitSet.h:442
BucketType Get(int32 Index) const
Definition SparseBitSet.h:450
BucketType * GetData()
Definition SparseBitSet.h:447
BucketType & Get(int32 Index)
Definition SparseBitSet.h:449
TArray< BucketType > Storage
Definition SparseBitSet.h:440
T BucketType
Definition SparseBitSet.h:438
Definition SparseBitSet.h:419
T BucketType
Definition SparseBitSet.h:420
BucketType * GetData()
Definition SparseBitSet.h:429
void Insert(BucketType InitialValue, int32 Index)
Definition SparseBitSet.h:424
BucketType & Get(int32 Index)
Definition SparseBitSet.h:431
BucketType Get(int32 Index) const
Definition SparseBitSet.h:432
TArray< BucketType, TInlineAllocator< InlineSize > > Storage
Definition SparseBitSet.h:422
Definition SparseBitSet.h:656
friend bool operator!=(const FIterator &A, const FIterator &B)
Definition SparseBitSet.h:717
static FIterator Begin(const TDynamicSparseBitSet< HashType, BucketStorage > *InBitSet)
Definition SparseBitSet.h:657
friend bool operator==(const FIterator &A, const FIterator &B)
Definition SparseBitSet.h:713
static FIterator End(const TDynamicSparseBitSet< HashType, BucketStorage > *InBitSet)
Definition SparseBitSet.h:672
int32 operator*() const
Definition SparseBitSet.h:703
void operator++()
Definition SparseBitSet.h:682
Definition SparseBitSet.h:488
bool IsEmpty() const
Definition SparseBitSet.h:535
TDynamicSparseBitSet< HashType, BucketStorage > & operator|=(const TDynamicSparseBitSet< HashType, BucketStorage > &Other)
Definition SparseBitSet.h:580
uint32 CountSetBits() const
Definition SparseBitSet.h:569
bool IsBitSet(uint32 Bit) const
Definition SparseBitSet.h:544
ESparseBitSetBitResult SetBit(uint32 Bit)
Definition SparseBitSet.h:504
friend FIterator end(const TDynamicSparseBitSet< HashType, BucketStorage > &In)
Definition SparseBitSet.h:734
uint32 GetMaxNumBits() const
Definition SparseBitSet.h:492
TArray< FEntry > Entries
Definition SparseBitSet.h:736
friend FIterator begin(const TDynamicSparseBitSet< HashType, BucketStorage > &In)
Definition SparseBitSet.h:733
Definition SparseBitSet.h:455
TFixedSparseBitSetBucketStorage(TFixedSparseBitSetBucketStorage &&)=delete
BucketType Get(int32 Index) const
Definition SparseBitSet.h:477
BucketType * GetData()
Definition SparseBitSet.h:474
BucketType * Storage
Definition SparseBitSet.h:472
TFixedSparseBitSetBucketStorage()
Definition SparseBitSet.h:458
T BucketType
Definition SparseBitSet.h:456
void operator=(TFixedSparseBitSetBucketStorage &&)=delete
void operator=(const TFixedSparseBitSetBucketStorage &)=delete
TFixedSparseBitSetBucketStorage(BucketType *StoragePtr)
Definition SparseBitSet.h:462
TFixedSparseBitSetBucketStorage(const TFixedSparseBitSetBucketStorage &)=delete
BucketType & Get(int32 Index)
Definition SparseBitSet.h:476
Definition SparseBitSet.h:278
friend bool operator!=(const FIterator &A, const FIterator &B)
Definition SparseBitSet.h:368
static FIterator End(const TFixedSparseBitSet< HashType, BucketStorage > *InBitSet)
Definition SparseBitSet.h:306
FIterator()
Definition SparseBitSet.h:279
static FIterator Begin(const TFixedSparseBitSet< HashType, BucketStorage > *InBitSet)
Definition SparseBitSet.h:287
friend bool operator==(const FIterator &A, const FIterator &B)
Definition SparseBitSet.h:364
void operator++()
Definition SparseBitSet.h:316
int32 operator*() const
Definition SparseBitSet.h:354
Definition SparseBitSet.h:80
uint32 GetMaxNumBits() const
Definition SparseBitSet.h:185
static constexpr uint32 HashSize
Definition SparseBitSet.h:82
TFixedSparseBitSet & operator=(TFixedSparseBitSet &&)=default
TFixedSparseBitSet(const TFixedSparseBitSet &)=default
bool IsBitSet(uint32 BitIndex) const
Definition SparseBitSet.h:226
friend FIterator begin(const TFixedSparseBitSet< HashType, BucketStorage > &In)
Definition SparseBitSet.h:381
static constexpr uint32 MaxNumBits
Definition SparseBitSet.h:84
bool IsEmpty() const
Definition SparseBitSet.h:190
void CopyToUnsafe(TFixedSparseBitSet< OtherHashType, OtherStorageType > &Other, uint32 OtherBucketCapacity) const
Definition SparseBitSet.h:115
friend FIterator end(const TFixedSparseBitSet< HashType, BucketStorage > &In)
Definition SparseBitSet.h:382
uint32 CountSetBits() const
Definition SparseBitSet.h:174
typename BucketStorage::BucketType BucketType
Definition SparseBitSet.h:81
static constexpr uint32 BucketSize
Definition SparseBitSet.h:83
TFixedSparseBitSet & operator|=(const TFixedSparseBitSet &Other)
Definition SparseBitSet.h:129
TFixedSparseBitSet & operator=(const TFixedSparseBitSet &)=default
TFixedSparseBitSet(TFixedSparseBitSet &&)=default
TFixedSparseBitSet(StorageArgs &&...Storage)
Definition SparseBitSet.h:91
ESparseBitSetBitResult SetBit(uint32 BitIndex)
Definition SparseBitSet.h:201
TFixedSparseBitSet()
Definition SparseBitSet.h:86
void CopyTo(TFixedSparseBitSet< OtherHashType, OtherStorageType > &Other) const
Definition SparseBitSet.h:103
uint32 NumBuckets() const
Definition SparseBitSet.h:169
int32 GetSparseBucketIndex(uint32 BitIndex) const
Definition SparseBitSet.h:246