refactor(*): make type alias identifiers conform to the style for general type identifiers
This commit is contained in:
@ -30,23 +30,23 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
using BlockType = InBlockType;
|
||||
using ElementType = bool;
|
||||
using AllocatorType = Allocator;
|
||||
using FBlockType = InBlockType;
|
||||
using FElementType = bool;
|
||||
using FAllocatorType = Allocator;
|
||||
|
||||
class Reference;
|
||||
using ConstReference = bool;
|
||||
class FReference;
|
||||
using FConstReference = bool;
|
||||
|
||||
using Iterator = TIteratorImpl<false>;
|
||||
using ConstIterator = TIteratorImpl<true >;
|
||||
using FIterator = TIteratorImpl<false>;
|
||||
using FConstIterator = TIteratorImpl<true >;
|
||||
|
||||
using ReverseIterator = TReverseIterator< Iterator>;
|
||||
using ConstReverseIterator = TReverseIterator<ConstIterator>;
|
||||
using FReverseIterator = TReverseIterator< FIterator>;
|
||||
using FConstReverseIterator = TReverseIterator<FConstIterator>;
|
||||
|
||||
static_assert(CRandomAccessIterator< Iterator>);
|
||||
static_assert(CRandomAccessIterator<ConstIterator>);
|
||||
static_assert(CRandomAccessIterator< FIterator>);
|
||||
static_assert(CRandomAccessIterator<FConstIterator>);
|
||||
|
||||
static constexpr size_t BlockWidth = sizeof(BlockType) * 8;
|
||||
static constexpr size_t BlockWidth = sizeof(FBlockType) * 8;
|
||||
|
||||
/** Default constructor. Constructs an empty bitset. */
|
||||
FORCEINLINE TBitset() : TBitset(0) { }
|
||||
@ -62,40 +62,40 @@ public:
|
||||
/** Constructs a bitset from an integer. */
|
||||
TBitset(size_t InCount, uint64 InValue) : TBitset(InCount > 64 ? InCount : 64)
|
||||
{
|
||||
static_assert(sizeof(BlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
static_assert(sizeof(FBlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
|
||||
if constexpr (sizeof(BlockType) == sizeof(uint8))
|
||||
if constexpr (sizeof(FBlockType) == sizeof(uint8))
|
||||
{
|
||||
Impl.Pointer[0] = static_cast<BlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<BlockType>(InValue >> 8);
|
||||
Impl.Pointer[2] = static_cast<BlockType>(InValue >> 16);
|
||||
Impl.Pointer[3] = static_cast<BlockType>(InValue >> 24);
|
||||
Impl.Pointer[4] = static_cast<BlockType>(InValue >> 32);
|
||||
Impl.Pointer[5] = static_cast<BlockType>(InValue >> 40);
|
||||
Impl.Pointer[6] = static_cast<BlockType>(InValue >> 48);
|
||||
Impl.Pointer[7] = static_cast<BlockType>(InValue >> 56);
|
||||
Impl.Pointer[0] = static_cast<FBlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<FBlockType>(InValue >> 8);
|
||||
Impl.Pointer[2] = static_cast<FBlockType>(InValue >> 16);
|
||||
Impl.Pointer[3] = static_cast<FBlockType>(InValue >> 24);
|
||||
Impl.Pointer[4] = static_cast<FBlockType>(InValue >> 32);
|
||||
Impl.Pointer[5] = static_cast<FBlockType>(InValue >> 40);
|
||||
Impl.Pointer[6] = static_cast<FBlockType>(InValue >> 48);
|
||||
Impl.Pointer[7] = static_cast<FBlockType>(InValue >> 56);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint16))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint16))
|
||||
{
|
||||
Impl.Pointer[0] = static_cast<BlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<BlockType>(InValue >> 16);
|
||||
Impl.Pointer[2] = static_cast<BlockType>(InValue >> 32);
|
||||
Impl.Pointer[3] = static_cast<BlockType>(InValue >> 48);
|
||||
Impl.Pointer[0] = static_cast<FBlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<FBlockType>(InValue >> 16);
|
||||
Impl.Pointer[2] = static_cast<FBlockType>(InValue >> 32);
|
||||
Impl.Pointer[3] = static_cast<FBlockType>(InValue >> 48);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint32))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint32))
|
||||
{
|
||||
Impl.Pointer[0] = static_cast<BlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<BlockType>(InValue >> 32);
|
||||
Impl.Pointer[0] = static_cast<FBlockType>(InValue >> 0);
|
||||
Impl.Pointer[1] = static_cast<FBlockType>(InValue >> 32);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint64))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint64))
|
||||
{
|
||||
Impl.Pointer[0] = static_cast<BlockType>(InValue >> 0);
|
||||
Impl.Pointer[0] = static_cast<FBlockType>(InValue >> 0);
|
||||
}
|
||||
else check_no_entry();
|
||||
|
||||
size_t BlockInteger = sizeof(uint64) / sizeof(BlockType);
|
||||
size_t BlockInteger = sizeof(uint64) / sizeof(FBlockType);
|
||||
|
||||
Memory::Memset(Impl.Pointer + BlockInteger, 0, (NumBlocks() - BlockInteger) * sizeof(BlockType));
|
||||
Memory::Memset(Impl.Pointer + BlockInteger, 0, (NumBlocks() - BlockInteger) * sizeof(FBlockType));
|
||||
|
||||
Impl.BitsetNum = InCount;
|
||||
}
|
||||
@ -112,9 +112,7 @@ public:
|
||||
|
||||
new (this) TBitset(InCount);
|
||||
|
||||
BlockType* CurrentBlock = Impl.Pointer - 1;
|
||||
|
||||
for (Reference Ref: *this) Ref = *First++;
|
||||
for (FReference Ref: *this) Ref = *First++;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -135,7 +133,7 @@ public:
|
||||
Impl.BlocksMax = Impl->CalculateSlackReserve(NumBlocks());
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(FBlockType));
|
||||
}
|
||||
|
||||
/** Move constructor. After the move, 'InValue' is guaranteed to be empty. */
|
||||
@ -157,7 +155,7 @@ public:
|
||||
Impl.BlocksMax = Impl->CalculateSlackReserve(NumBlocks());
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(FBlockType));
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,7 +186,7 @@ public:
|
||||
Impl.BlocksMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(FBlockType));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -197,7 +195,7 @@ public:
|
||||
|
||||
Impl.BitsetNum = InValue.Num();
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, InValue.Impl.Pointer, NumBlocks() * sizeof(FBlockType));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -247,14 +245,14 @@ public:
|
||||
Impl.BlocksMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
for (Reference Ref : *this) Ref = *First++;
|
||||
for (FReference Ref : *this) Ref = *First++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
Impl.BitsetNum = GetNum(IL);
|
||||
|
||||
for (Reference Ref : *this) Ref = *First++;
|
||||
for (FReference Ref : *this) Ref = *First++;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -271,7 +269,7 @@ public:
|
||||
if (LHS.Impl.Pointer[Index] != RHS.Impl.Pointer[Index]) return false;
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = LHS.Num() % BlockWidth != 0 ? (1ull << LHS.Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = LHS.Num() % BlockWidth != 0 ? (1ull << LHS.Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
return (LHS.Impl.Pointer[LHS.NumBlocks() - 1] & LastBlockBitmask) == (RHS.Impl.Pointer[LHS.NumBlocks() - 1] & LastBlockBitmask);
|
||||
}
|
||||
@ -301,7 +299,7 @@ public:
|
||||
Impl.Pointer[Index] &= InValue.Impl.Pointer[Index];
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
Impl.Pointer[LastBlock] &= InValue.Impl.Pointer[LastBlock] & LastBlockBitmask;
|
||||
|
||||
@ -339,7 +337,7 @@ public:
|
||||
Impl.Pointer[Index] |= InValue.Impl.Pointer[Index];
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
Impl.Pointer[LastBlock] |= InValue.Impl.Pointer[LastBlock] & LastBlockBitmask;
|
||||
}
|
||||
@ -372,7 +370,7 @@ public:
|
||||
Impl.Pointer[Index] ^= InValue.Impl.Pointer[Index];
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = InValue.Num() % BlockWidth != 0 ? (1ull << InValue.Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
Impl.Pointer[LastBlock] ^= InValue.Impl.Pointer[LastBlock] & LastBlockBitmask;
|
||||
}
|
||||
@ -473,7 +471,7 @@ public:
|
||||
if (Impl.Pointer[Index] != -1) return false;
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
return (Impl.Pointer[NumBlocks() - 1] | ~LastBlockBitmask) == -1;
|
||||
}
|
||||
@ -488,7 +486,7 @@ public:
|
||||
if (Impl.Pointer[Index] != 0) return true;
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
return (Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask) != 0;
|
||||
}
|
||||
@ -503,24 +501,24 @@ public:
|
||||
|
||||
size_t Result = 0;
|
||||
|
||||
constexpr auto BlockCount = [](BlockType Block)
|
||||
constexpr auto BlockCount = [](FBlockType Block)
|
||||
{
|
||||
static_assert(sizeof(BlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
static_assert(sizeof(FBlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
|
||||
if constexpr (sizeof(BlockType) == sizeof(uint8))
|
||||
if constexpr (sizeof(FBlockType) == sizeof(uint8))
|
||||
{
|
||||
Block = (Block & 0x55ull) + ((Block >> 1) & 0x55ull);
|
||||
Block = (Block & 0x33ull) + ((Block >> 2) & 0x33ull);
|
||||
Block = (Block & 0x0Full) + ((Block >> 4) & 0x0Full);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint16))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint16))
|
||||
{
|
||||
Block = (Block & 0x5555ull) + ((Block >> 1) & 0x5555ull);
|
||||
Block = (Block & 0x3333ull) + ((Block >> 2) & 0x3333ull);
|
||||
Block = (Block & 0x0F0Full) + ((Block >> 4) & 0x0F0Full);
|
||||
Block = (Block & 0x00FFull) + ((Block >> 8) & 0x00FFull);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint32))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint32))
|
||||
{
|
||||
Block = (Block & 0x55555555ull) + ((Block >> 1) & 0x55555555ull);
|
||||
Block = (Block & 0x33333333ull) + ((Block >> 2) & 0x33333333ull);
|
||||
@ -528,7 +526,7 @@ public:
|
||||
Block = (Block & 0x00FF00FFull) + ((Block >> 8) & 0x00FF00FFull);
|
||||
Block = (Block & 0x0000FFFFull) + ((Block >> 16) & 0x0000FFFFull);
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint64))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint64))
|
||||
{
|
||||
Block = (Block & 0x5555555555555555ull) + ((Block >> 1) & 0x5555555555555555ull);
|
||||
Block = (Block & 0x3333333333333333ull) + ((Block >> 2) & 0x3333333333333333ull);
|
||||
@ -547,7 +545,7 @@ public:
|
||||
Result += BlockCount(Impl.Pointer[Index]);
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
Result += BlockCount(Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask);
|
||||
|
||||
@ -557,7 +555,7 @@ public:
|
||||
/** Sets all bits to true. */
|
||||
TBitset& Set(bool InValue = true)
|
||||
{
|
||||
Memory::Memset(Impl.Pointer, static_cast<uint8>(InValue ? -1 : 0), NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memset(Impl.Pointer, static_cast<uint8>(InValue ? -1 : 0), NumBlocks() * sizeof(FBlockType));
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -591,17 +589,17 @@ public:
|
||||
checkf(Impl.Pointer[Index] != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const BlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask;
|
||||
const FBlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlock = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask;
|
||||
|
||||
checkf(LastBlock != 0, TEXT("The bitset can not be represented in uint64. Please check Num()."));
|
||||
}
|
||||
|
||||
uint64 Result = 0;
|
||||
|
||||
static_assert(sizeof(BlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
static_assert(sizeof(FBlockType) <= sizeof(uint64), "The block width of TBitset is unexpected");
|
||||
|
||||
if constexpr (sizeof(BlockType) == sizeof(uint8))
|
||||
if constexpr (sizeof(FBlockType) == sizeof(uint8))
|
||||
{
|
||||
Result |= static_cast<uint64>(Impl.Pointer[0]) << 0;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[1]) << 8;
|
||||
@ -612,19 +610,19 @@ public:
|
||||
Result |= static_cast<uint64>(Impl.Pointer[6]) << 48;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[7]) << 56;
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint16))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint16))
|
||||
{
|
||||
Result |= static_cast<uint64>(Impl.Pointer[0]) << 0;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[1]) << 16;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[2]) << 32;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[3]) << 48;
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint32))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint32))
|
||||
{
|
||||
Result |= static_cast<uint64>(Impl.Pointer[0]) << 0;
|
||||
Result |= static_cast<uint64>(Impl.Pointer[1]) << 32;
|
||||
}
|
||||
else if constexpr (sizeof(BlockType) == sizeof(uint64))
|
||||
else if constexpr (sizeof(FBlockType) == sizeof(uint64))
|
||||
{
|
||||
Result |= static_cast<uint64>(Impl.Pointer[0]) << 0;
|
||||
}
|
||||
@ -661,7 +659,7 @@ public:
|
||||
|
||||
if (NumToAllocate != MaxBlocks())
|
||||
{
|
||||
BlockType* OldAllocation = Impl.Pointer;
|
||||
FBlockType* OldAllocation = Impl.Pointer;
|
||||
const size_t NumToDestruct = NumBlocks();
|
||||
|
||||
Impl.BitsetNum = InCount;
|
||||
@ -670,11 +668,11 @@ public:
|
||||
|
||||
if (NumToDestruct <= Num())
|
||||
{
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumToDestruct * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumToDestruct * sizeof(FBlockType));
|
||||
}
|
||||
else
|
||||
{
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, BlocksCount * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, BlocksCount * sizeof(FBlockType));
|
||||
}
|
||||
|
||||
Impl->Deallocate(OldAllocation);
|
||||
@ -697,12 +695,12 @@ public:
|
||||
NumToAllocate = NumToAllocate > MaxBlocks() ? Impl->CalculateSlackGrow(BlocksCount, MaxBlocks()) : NumToAllocate;
|
||||
NumToAllocate = NumToAllocate < MaxBlocks() ? (bAllowShrinking ? Impl->CalculateSlackShrink(BlocksCount, MaxBlocks()) : MaxBlocks()) : NumToAllocate;
|
||||
|
||||
const BlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const BlockType BlocksValueToSet = static_cast<BlockType>(InValue ? -1 : 0);
|
||||
const FBlockType LastBlockBitmask = Num() % BlockWidth != 0 ? (1ull << Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType BlocksValueToSet = static_cast<FBlockType>(InValue ? -1 : 0);
|
||||
|
||||
if (NumToAllocate != MaxBlocks())
|
||||
{
|
||||
BlockType* OldAllocation = Impl.Pointer;
|
||||
FBlockType* OldAllocation = Impl.Pointer;
|
||||
const size_t NumToDestruct = NumBlocks();
|
||||
|
||||
Impl.BitsetNum = InCount;
|
||||
@ -713,16 +711,16 @@ public:
|
||||
{
|
||||
if (NumToDestruct != 0)
|
||||
{
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, (NumToDestruct - 1) * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, (NumToDestruct - 1) * sizeof(FBlockType));
|
||||
|
||||
Impl.Pointer[NumToDestruct - 1] = OldAllocation[NumToDestruct - 1] & LastBlockBitmask | BlocksValueToSet & ~LastBlockBitmask;
|
||||
}
|
||||
|
||||
Memory::Memset(Impl.Pointer + NumToDestruct, static_cast<uint8>(BlocksValueToSet), (BlocksCount - NumToDestruct) * sizeof(BlockType));
|
||||
Memory::Memset(Impl.Pointer + NumToDestruct, static_cast<uint8>(BlocksValueToSet), (BlocksCount - NumToDestruct) * sizeof(FBlockType));
|
||||
}
|
||||
else
|
||||
{
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, BlocksCount * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, BlocksCount * sizeof(FBlockType));
|
||||
}
|
||||
|
||||
Impl->Deallocate(OldAllocation);
|
||||
@ -739,7 +737,7 @@ public:
|
||||
Impl.Pointer[NumBlocks() - 1] = Impl.Pointer[NumBlocks() - 1] & LastBlockBitmask | BlocksValueToSet & ~LastBlockBitmask;
|
||||
}
|
||||
|
||||
Memory::Memset(Impl.Pointer + NumBlocks(), static_cast<uint8>(BlocksValueToSet), (BlocksCount - NumBlocks()) * sizeof(BlockType));
|
||||
Memory::Memset(Impl.Pointer + NumBlocks(), static_cast<uint8>(BlocksValueToSet), (BlocksCount - NumBlocks()) * sizeof(FBlockType));
|
||||
}
|
||||
|
||||
Impl.BitsetNum = InCount;
|
||||
@ -753,14 +751,14 @@ public:
|
||||
const size_t BlocksCount = (InCount + BlockWidth - 1) / BlockWidth;
|
||||
|
||||
const size_t NumToAllocate = Impl->CalculateSlackReserve(BlocksCount);
|
||||
BlockType* OldAllocation = Impl.Pointer;
|
||||
FBlockType* OldAllocation = Impl.Pointer;
|
||||
|
||||
check(NumToAllocate > MaxBlocks());
|
||||
|
||||
Impl.BlocksMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumBlocks() * sizeof(FBlockType));
|
||||
|
||||
Impl->Deallocate(OldAllocation);
|
||||
}
|
||||
@ -774,31 +772,31 @@ public:
|
||||
|
||||
if (NumToAllocate == MaxBlocks()) return;
|
||||
|
||||
BlockType* OldAllocation = Impl.Pointer;
|
||||
FBlockType* OldAllocation = Impl.Pointer;
|
||||
|
||||
Impl.BitsetNum = NumToAllocate * BlockWidth;
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumBlocks() * sizeof(BlockType));
|
||||
Memory::Memcpy(Impl.Pointer, OldAllocation, NumBlocks() * sizeof(FBlockType));
|
||||
|
||||
Impl->Deallocate(OldAllocation);
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE BlockType* GetData() { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE const BlockType* GetData() const { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE FBlockType* GetData() { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE const FBlockType* GetData() const { return Impl.Pointer; }
|
||||
|
||||
/** @return The iterator to the first or end bit. */
|
||||
NODISCARD FORCEINLINE Iterator Begin() { return Iterator(this, Impl.Pointer, 0); }
|
||||
NODISCARD FORCEINLINE ConstIterator Begin() const { return ConstIterator(this, Impl.Pointer, 0); }
|
||||
NODISCARD FORCEINLINE Iterator End() { return Iterator(this, Impl.Pointer, Num()); }
|
||||
NODISCARD FORCEINLINE ConstIterator End() const { return ConstIterator(this, Impl.Pointer, Num()); }
|
||||
NODISCARD FORCEINLINE FIterator Begin() { return FIterator(this, Impl.Pointer, 0); }
|
||||
NODISCARD FORCEINLINE FConstIterator Begin() const { return FConstIterator(this, Impl.Pointer, 0); }
|
||||
NODISCARD FORCEINLINE FIterator End() { return FIterator(this, Impl.Pointer, Num()); }
|
||||
NODISCARD FORCEINLINE FConstIterator End() const { return FConstIterator(this, Impl.Pointer, Num()); }
|
||||
|
||||
/** @return The reverse iterator to the first or end bit. */
|
||||
NODISCARD FORCEINLINE ReverseIterator RBegin() { return ReverseIterator(End()); }
|
||||
NODISCARD FORCEINLINE ConstReverseIterator RBegin() const { return ConstReverseIterator(End()); }
|
||||
NODISCARD FORCEINLINE ReverseIterator REnd() { return ReverseIterator(Begin()); }
|
||||
NODISCARD FORCEINLINE ConstReverseIterator REnd() const { return ConstReverseIterator(Begin()); }
|
||||
NODISCARD FORCEINLINE FReverseIterator RBegin() { return FReverseIterator(End()); }
|
||||
NODISCARD FORCEINLINE FConstReverseIterator RBegin() const { return FConstReverseIterator(End()); }
|
||||
NODISCARD FORCEINLINE FReverseIterator REnd() { return FReverseIterator(Begin()); }
|
||||
NODISCARD FORCEINLINE FConstReverseIterator REnd() const { return FConstReverseIterator(Begin()); }
|
||||
|
||||
/** @return The number of bits in the bitset. */
|
||||
NODISCARD FORCEINLINE size_t Num() const { return Impl.BitsetNum; }
|
||||
@ -816,17 +814,17 @@ public:
|
||||
NODISCARD FORCEINLINE bool IsEmpty() const { return Num() == 0; }
|
||||
|
||||
/** @return true if the iterator is valid, false otherwise. */
|
||||
NODISCARD FORCEINLINE bool IsValidIterator(ConstIterator Iter) const { return Begin() <= Iter && Iter <= End(); }
|
||||
NODISCARD FORCEINLINE bool IsValidIterator(FConstIterator Iter) const { return Begin() <= Iter && Iter <= End(); }
|
||||
|
||||
/** @return The reference to the requested bit. */
|
||||
NODISCARD FORCEINLINE Reference operator[](size_t Index) { checkf(Index < Num(), TEXT("Read access violation. Please check IsValidIterator().")); return *(Begin() + Index); }
|
||||
NODISCARD FORCEINLINE ConstReference operator[](size_t Index) const { checkf(Index < Num(), TEXT("Read access violation. Please check IsValidIterator().")); return *(Begin() + Index); }
|
||||
NODISCARD FORCEINLINE FReference operator[](size_t Index) { checkf(Index < Num(), TEXT("Read access violation. Please check IsValidIterator().")); return *(Begin() + Index); }
|
||||
NODISCARD FORCEINLINE FConstReference operator[](size_t Index) const { checkf(Index < Num(), TEXT("Read access violation. Please check IsValidIterator().")); return *(Begin() + Index); }
|
||||
|
||||
/** @return The reference to the first or last bit. */
|
||||
NODISCARD FORCEINLINE Reference Front() { return *Begin(); }
|
||||
NODISCARD FORCEINLINE ConstReference Front() const { return *Begin(); }
|
||||
NODISCARD FORCEINLINE Reference Back() { return *(End() - 1); }
|
||||
NODISCARD FORCEINLINE ConstReference Back() const { return *(End() - 1); }
|
||||
NODISCARD FORCEINLINE FReference Front() { return *Begin(); }
|
||||
NODISCARD FORCEINLINE FConstReference Front() const { return *Begin(); }
|
||||
NODISCARD FORCEINLINE FReference Back() { return *(End() - 1); }
|
||||
NODISCARD FORCEINLINE FConstReference Back() const { return *(End() - 1); }
|
||||
|
||||
/** Erases all bits from the bitset. After this call, Num() returns zero. */
|
||||
void Reset(bool bAllowShrinking = true)
|
||||
@ -859,7 +857,7 @@ public:
|
||||
Result = HashCombine(Result, GetTypeHash(A.Impl.Pointer[Index]));
|
||||
}
|
||||
|
||||
const BlockType LastBlockBitmask = A.Num() % BlockWidth != 0 ? (1ull << A.Num() % BlockWidth) - 1 : -1;
|
||||
const FBlockType LastBlockBitmask = A.Num() % BlockWidth != 0 ? (1ull << A.Num() % BlockWidth) - 1 : -1;
|
||||
|
||||
return HashCombine(Result, GetTypeHash(A.Impl.Pointer[A.NumBlocks() - 1] & LastBlockBitmask));
|
||||
}
|
||||
@ -889,27 +887,27 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
ALLOCATOR_WRAPPER_BEGIN(AllocatorType, BlockType, Impl)
|
||||
ALLOCATOR_WRAPPER_BEGIN(FAllocatorType, FBlockType, Impl)
|
||||
{
|
||||
size_t BitsetNum;
|
||||
size_t BlocksMax;
|
||||
BlockType* Pointer;
|
||||
FBlockType* Pointer;
|
||||
}
|
||||
ALLOCATOR_WRAPPER_END(AllocatorType, BlockType, Impl)
|
||||
ALLOCATOR_WRAPPER_END(FAllocatorType, FBlockType, Impl)
|
||||
|
||||
public:
|
||||
|
||||
class Reference final : private FSingleton
|
||||
class FReference final : private FSingleton
|
||||
{
|
||||
public:
|
||||
|
||||
FORCEINLINE Reference& operator=(bool InValue) { Data = (Data & ~Mask) | (InValue ? Mask : 0); return *this; }
|
||||
FORCEINLINE FReference& operator=(bool InValue) { Data = (Data & ~Mask) | (InValue ? Mask : 0); return *this; }
|
||||
|
||||
FORCEINLINE Reference& operator=(const Reference& InValue) { *this = static_cast<bool>(InValue); return *this; }
|
||||
FORCEINLINE FReference& operator=(const FReference& InValue) { *this = static_cast<bool>(InValue); return *this; }
|
||||
|
||||
FORCEINLINE Reference& operator&=(bool InValue) { Data &= InValue ? -1 : ~Mask; return *this; }
|
||||
FORCEINLINE Reference& operator|=(bool InValue) { Data |= InValue ? Mask : 0; return *this; }
|
||||
FORCEINLINE Reference& operator^=(bool InValue) { *this = InValue ^ *this; return *this; }
|
||||
FORCEINLINE FReference& operator&=(bool InValue) { Data &= InValue ? -1 : ~Mask; return *this; }
|
||||
FORCEINLINE FReference& operator|=(bool InValue) { Data |= InValue ? Mask : 0; return *this; }
|
||||
FORCEINLINE FReference& operator^=(bool InValue) { *this = InValue ^ *this; return *this; }
|
||||
|
||||
FORCEINLINE bool operator~() const { return !*this; }
|
||||
|
||||
@ -917,14 +915,14 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
FORCEINLINE Reference(BlockType& InData, BlockType InMask)
|
||||
FORCEINLINE FReference(FBlockType& InData, FBlockType InMask)
|
||||
: Data(InData), Mask(InMask)
|
||||
{ }
|
||||
|
||||
BlockType& Data;
|
||||
BlockType Mask;
|
||||
FBlockType& Data;
|
||||
FBlockType Mask;
|
||||
|
||||
friend Iterator;
|
||||
friend FIterator;
|
||||
|
||||
};
|
||||
|
||||
@ -935,7 +933,7 @@ private:
|
||||
{
|
||||
public:
|
||||
|
||||
using ElementType = bool;
|
||||
using FElementType = bool;
|
||||
|
||||
FORCEINLINE TIteratorImpl() = default;
|
||||
|
||||
@ -958,8 +956,8 @@ private:
|
||||
|
||||
NODISCARD friend FORCEINLINE strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset <=> RHS.BitOffset; }
|
||||
|
||||
NODISCARD FORCEINLINE Reference operator*() const requires (!bConst) { CheckThis(true); return Reference(*(Pointer + BitOffset / BlockWidth), 1ull << BitOffset % BlockWidth); }
|
||||
NODISCARD FORCEINLINE ConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + BitOffset / BlockWidth) & (1ull << BitOffset % BlockWidth)); }
|
||||
NODISCARD FORCEINLINE FReference operator*() const requires (!bConst) { CheckThis(true); return FReference(*(Pointer + BitOffset / BlockWidth), 1ull << BitOffset % BlockWidth); }
|
||||
NODISCARD FORCEINLINE FConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + BitOffset / BlockWidth) & (1ull << BitOffset % BlockWidth)); }
|
||||
|
||||
NODISCARD FORCEINLINE auto operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; }
|
||||
|
||||
@ -985,17 +983,17 @@ private:
|
||||
const TBitset* Owner = nullptr;
|
||||
# endif
|
||||
|
||||
using BlockPtr = TConditional<bConst, const BlockType*, BlockType*>;
|
||||
using FBlockPtr = TConditional<bConst, const FBlockType*, FBlockType*>;
|
||||
|
||||
BlockPtr Pointer = nullptr;
|
||||
size_t BitOffset = 0;
|
||||
FBlockPtr Pointer = nullptr;
|
||||
size_t BitOffset = 0;
|
||||
|
||||
# if DO_CHECK
|
||||
FORCEINLINE TIteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t Offset)
|
||||
FORCEINLINE TIteratorImpl(const TBitset* InContainer, FBlockPtr InPointer, size_t Offset)
|
||||
: Owner(InContainer), Pointer(InPointer), BitOffset(Offset)
|
||||
{ }
|
||||
# else
|
||||
FORCEINLINE TIteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t Offset)
|
||||
FORCEINLINE TIteratorImpl(const TBitset* InContainer, FBlockPtr InPointer, size_t Offset)
|
||||
: Pointer(InPointer), BitOffset(Offset)
|
||||
{ }
|
||||
# endif
|
||||
|
Reference in New Issue
Block a user