21 virtual bool Allocate(std::uint32_t a_num, std::uint32_t a_elemSize) = 0;
22 virtual bool Reallocate(std::uint32_t a_minNewSizeInItems, std::uint32_t a_frontCopyCount, std::uint32_t a_shiftCount, std::uint32_t a_backCopyCount, std::uint32_t a_elemSize) = 0;
40 [[nodiscard]] constexpr
bool empty() const noexcept {
return _size == 0; }
41 [[nodiscard]] constexpr
size_type size() const noexcept {
return _size; }
48 std::uint32_t _size{ 0 };
50 static_assert(
sizeof(BSTArrayBase) == 0x4);
62 _capacity = a_rhs.capacity();
70 _capacity(a_rhs.capacity())
72 a_rhs._data =
nullptr;
85 if (
this != std::addressof(a_rhs)) {
101 if (
this != std::addressof(a_rhs)) {
103 _data = a_rhs.data();
104 _capacity = a_rhs.capacity();
106 a_rhs._data =
nullptr;
114 [[nodiscard]] constexpr
void*
data() noexcept {
return _data; }
115 [[nodiscard]] constexpr
const void*
data() const noexcept {
return _data; }
122 const auto mem =
malloc(a_size);
126 std::memset(mem, 0, a_size);
136 _capacity = a_capacity;
141 void* _data{
nullptr };
142 std::uint32_t _capacity{ 0 };
144 static_assert(
sizeof(BSTArrayHeapAllocator) == 0x10);
146 template <std::u
int32_t N>
168 copy(std::move(a_rhs));
175 if (
this != std::addressof(a_rhs)) {
183 if (
this != std::addressof(a_rhs)) {
184 copy(std::move(a_rhs));
191 [[nodiscard]] constexpr
void*
data() noexcept {
return local() ? _data.local : _data.heap; }
192 [[nodiscard]] constexpr
const void*
data() const noexcept {
return local() ? _data.local : _data.heap; }
200 const auto mem =
malloc(a_size);
204 std::memset(mem, 0, a_size);
214 if (a_ptr != _data.local) {
221 _capacity = a_capacity;
222 if (a_capacity * a_typeSize > N) {
239 _capacity = a_rhs._capacity;
240 _local = a_rhs._local;
258 _capacity = a_rhs._capacity;
259 _local = a_rhs._local;
262 std::memset(a_rhs.data(), 0, a_rhs.capacity());
267 [[nodiscard]] constexpr
bool local() const noexcept {
return _local != 0; }
269 inline void release()
281 std::uint32_t _capacity: 31;
282 std::uint32_t _local: 1;
294 _capacity(a_rhs._capacity)
303 _allocator(a_rhs._allocator),
305 _capacity(a_rhs._capacity)
307 a_rhs._allocator =
nullptr;
308 a_rhs._data =
nullptr;
316 if (
this != std::addressof(a_rhs)) {
333 if (
this != std::addressof(a_rhs)) {
338 _allocator = a_rhs._allocator;
340 _capacity = a_rhs._capacity;
342 a_rhs._allocator =
nullptr;
343 a_rhs._data =
nullptr;
351 [[nodiscard]] constexpr
void*
data() noexcept {
return _data; }
352 [[nodiscard]] constexpr
const void*
data() const noexcept {
return _data; }
363 _capacity = a_capacity;
369 void* _data{
nullptr };
372 static_assert(
sizeof(BSScrapArrayAllocator) == 0x18);
374 template <
class T,
class Allocator = BSTArrayHeapAllocator>
394 const auto newCapacity = a_rhs.
capacity();
395 if (newCapacity == 0) {
399 const auto newSize = a_rhs.
size();
400 const auto newData = allocate(newCapacity);
401 for (
size_type i = 0; i < newSize; ++i) {
402 std::construct_at(newData + i, a_rhs[i]);
405 set_allocator_traits(newData, newCapacity);
417 const auto newCapacity = a_count;
418 const auto newSize = a_count;
419 const auto newData = allocate(newCapacity);
420 for (
size_type i = 0; i < newSize; ++i) {
421 std::construct_at(newData + i);
424 set_allocator_traits(newData, newCapacity);
432 if (
this != std::addressof(a_rhs)) {
435 const auto newCapacity = a_rhs.
capacity();
436 change_capacity(newCapacity);
438 const auto newSize = a_rhs.
size();
441 const auto newData =
data();
442 for (
size_type i = 0; i < newSize; ++i) {
443 std::construct_at(newData + i, a_rhs[i]);
451 if (
this != std::addressof(a_rhs)) {
454 const auto newCapacity = a_rhs.capacity();
455 const auto newSize = a_rhs.size();
456 const auto newData = a_rhs.data();
458 set_allocator_traits(newData, newCapacity);
459 a_rhs.set_allocator_traits(0, 0);
471 assert(a_pos <
size());
472 return data()[a_pos];
477 assert(a_pos <
size());
478 return data()[a_pos];
487 [[nodiscard]] constexpr
pointer data() noexcept {
return static_cast<pointer>(allocator_type::data()); }
505 change_capacity(a_newCap);
509 [[nodiscard]] constexpr
size_type capacity() const noexcept {
return allocator_type::capacity(); }
513 const auto newCapacity =
size();
515 change_capacity(newCapacity);
528 auto pos =
const_cast<iterator>(a_pos);
529 std::optional<iterator> result;
530 if (pos !=
begin()) {
534 for (
auto prev = pos++; pos !=
cend(); prev = pos++) {
535 *prev = std::move(*pos);
539 return result ? *result + 1 :
begin();
545 template <
class... Args>
552 set_size(
size() + 1);
554 std::construct_at(std::addressof(elem), std::forward<Args>(a_args)...);
561 std::destroy_at(std::addressof(
back()));
562 set_size(
size() - 1);
567 if (a_count !=
size()) {
568 change_size(a_count);
574 if (a_count !=
size()) {
575 change_size(a_count, a_value);
581 static constexpr
float GROWTH_FACTOR = 2.0;
585 return static_cast<pointer>(allocator_type::allocate(a_num *
sizeof(
value_type)));
588 inline void deallocate(
void* a_ptr) { allocator_type::deallocate(a_ptr); }
590 constexpr
void set_allocator_traits(
void* a_data,
size_type a_capacity) noexcept
592 allocator_type::set_allocator_traits(a_data, a_capacity,
sizeof(
value_type));
597 inline void change_capacity(
size_type a_newCapacity)
599 const auto newData = a_newCapacity > 0 ? allocate(a_newCapacity) : nullptr;
600 const auto oldData =
data();
602 const auto oldCapacity =
capacity();
605 std::memcpy(newData, oldData, bytesToCopy);
609 set_allocator_traits(newData, a_newCapacity);
612 template <
class... Args>
613 inline void change_size(
size_type a_newSize, Args&&... a_args)
616 grow_capacity(a_newSize);
619 const auto oldSize =
size();
620 if (a_newSize > oldSize) {
621 for (
size_type i = oldSize; i < a_newSize; ++i) {
622 std::construct_at(
data() + i, std::forward<Args>(a_args)...);
625 for (
size_type i = a_newSize; i < oldSize; ++i) {
626 std::destroy_at(
data() + i);
633 inline void grow_capacity() { grow_capacity(
capacity()); }
635 inline void grow_capacity(
size_type a_hint)
638 cap = cap > 0 ?
static_cast<size_type>(std::ceil(
static_cast<float>(cap) * GROWTH_FACTOR)) : DF_CAP;
639 change_capacity(cap);
642 inline void release()
649 template <
class T, std::u
int32_t N = 1>
670 assert(a_pos < _size);
676 assert(a_pos < _size);
697 [[nodiscard]] constexpr
bool empty() const noexcept {
return size() == 0; }
704 std::uint32_t _size{ 0 };
722 assert(a_pos < _size);
723 return data()[a_pos];
728 assert(a_pos < _size);
729 return data()[a_pos];
734 return size() > 1 ? _data.heap : std::addressof(_data.local);
739 return size() > 1 ? _data.heap : std::addressof(_data.local);
750 [[nodiscard]] constexpr
bool empty() const noexcept {
return size() != 0; }
764 std::uint32_t _size{ 0 };
Definition: BSTArray.h:287
BSScrapArrayAllocator & operator=(const BSScrapArrayAllocator &a_rhs)
Definition: BSTArray.h:314
constexpr BSScrapArrayAllocator() noexcept=default
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:354
BSScrapArrayAllocator & operator=(BSScrapArrayAllocator &&a_rhs)
Definition: BSTArray.h:331
constexpr BSScrapArrayAllocator(BSScrapArrayAllocator &&a_rhs) noexcept
Definition: BSTArray.h:302
constexpr void * data() noexcept
Definition: BSTArray.h:351
std::uint32_t size_type
Definition: BSTArray.h:289
void deallocate(void *a_ptr)
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t) noexcept
Definition: BSTArray.h:360
constexpr const void * data() const noexcept
Definition: BSTArray.h:352
void * allocate(std::size_t a_size)
Definition: BSTArray.h:657
std::uint32_t size_type
Definition: BSTArray.h:660
T value_type
Definition: BSTArray.h:659
constexpr const_iterator begin() const noexcept
Definition: BSTArray.h:690
const value_type * const_pointer
Definition: BSTArray.h:662
constexpr const_iterator cbegin() const noexcept
Definition: BSTArray.h:691
constexpr reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:668
const value_type & const_reference
Definition: BSTArray.h:664
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:674
constexpr const_pointer data() const noexcept
Definition: BSTArray.h:687
const_pointer const_iterator
Definition: BSTArray.h:666
constexpr const_reference front() const noexcept
Definition: BSTArray.h:681
constexpr const_reference back() const noexcept
Definition: BSTArray.h:684
constexpr reference back() noexcept
Definition: BSTArray.h:683
constexpr iterator begin() noexcept
Definition: BSTArray.h:689
constexpr bool empty() const noexcept
Definition: BSTArray.h:697
pointer iterator
Definition: BSTArray.h:665
value_type & reference
Definition: BSTArray.h:663
constexpr iterator end() noexcept
Definition: BSTArray.h:693
constexpr const_iterator cend() const noexcept
Definition: BSTArray.h:695
constexpr size_type size() const noexcept
Definition: BSTArray.h:699
constexpr reference front() noexcept
Definition: BSTArray.h:680
value_type * pointer
Definition: BSTArray.h:661
constexpr pointer data() noexcept
Definition: BSTArray.h:686
constexpr const_iterator end() const noexcept
Definition: BSTArray.h:694
Definition: BSTArray.h:15
virtual bool Allocate(std::uint32_t a_num, std::uint32_t a_elemSize)=0
static constexpr auto VTABLE
Definition: BSTArray.h:18
virtual ~IAllocatorFunctor()=default
virtual bool Reallocate(std::uint32_t a_minNewSizeInItems, std::uint32_t a_frontCopyCount, std::uint32_t a_shiftCount, std::uint32_t a_backCopyCount, std::uint32_t a_elemSize)=0
static constexpr auto RTTI
Definition: BSTArray.h:17
virtual void Deallocate()=0
Definition: BSTArray.h:10
constexpr size_type size() const noexcept
Definition: BSTArray.h:41
constexpr void set_size(size_type a_size) noexcept
Definition: BSTArray.h:44
constexpr bool empty() const noexcept
Definition: BSTArray.h:40
BSTArrayBase & operator=(BSTArrayBase &&) noexcept=default
BSTArrayBase & operator=(const BSTArrayBase &) noexcept=default
constexpr BSTArrayBase() noexcept=default
std::uint32_t size_type
Definition: BSTArray.h:12
Definition: BSTArray.h:53
constexpr void * data() noexcept
Definition: BSTArray.h:114
void deallocate(void *a_ptr)
Definition: BSTArray.h:131
std::uint32_t size_type
Definition: BSTArray.h:55
void * allocate(std::size_t a_size)
Definition: BSTArray.h:120
BSTArrayHeapAllocator & operator=(BSTArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:99
~BSTArrayHeapAllocator()
Definition: BSTArray.h:76
constexpr BSTArrayHeapAllocator(BSTArrayHeapAllocator &&a_rhs) noexcept
Definition: BSTArray.h:68
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t) noexcept
Definition: BSTArray.h:133
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:117
constexpr BSTArrayHeapAllocator() noexcept=default
BSTArrayHeapAllocator & operator=(const BSTArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:83
constexpr const void * data() const noexcept
Definition: BSTArray.h:115
Definition: BSTArray.h:378
value_type & reference
Definition: BSTArray.h:385
const_pointer const_iterator
Definition: BSTArray.h:388
void resize(size_type a_count, const value_type &a_value)
Definition: BSTArray.h:572
void push_back(value_type &&a_value)
Definition: BSTArray.h:543
void resize(size_type a_count)
Definition: BSTArray.h:565
void pop_back()
Definition: BSTArray.h:558
constexpr pointer data() noexcept
Definition: BSTArray.h:487
iterator erase(const_iterator a_pos)
Definition: BSTArray.h:526
constexpr size_type size() const noexcept
Definition: BSTArray.h:500
constexpr reference back() noexcept
Definition: BSTArray.h:484
constexpr const_iterator cbegin() const noexcept
Definition: BSTArray.h:492
void clear()
Definition: BSTArray.h:519
constexpr reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:469
Allocator allocator_type
Definition: BSTArray.h:380
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:475
~BSTArray()
Definition: BSTArray.h:428
BSTArray & operator=(BSTArray &&a_rhs)
Definition: BSTArray.h:449
reference emplace_back(Args &&... a_args)
Definition: BSTArray.h:546
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:509
T value_type
Definition: BSTArray.h:382
constexpr const_reference back() const noexcept
Definition: BSTArray.h:485
void reserve(size_type a_newCap)
Definition: BSTArray.h:502
typename BSTArrayBase::size_type size_type
Definition: BSTArray.h:381
void shrink_to_fit()
Definition: BSTArray.h:511
const value_type & const_reference
Definition: BSTArray.h:386
constexpr const_pointer data() const noexcept
Definition: BSTArray.h:488
BSTArray(const BSTArray &a_rhs)
Definition: BSTArray.h:392
constexpr iterator end() noexcept
Definition: BSTArray.h:494
constexpr reference front() noexcept
Definition: BSTArray.h:481
BSTArray(BSTArray &&)=default
const value_type * const_pointer
Definition: BSTArray.h:384
void push_back(const value_type &a_value)
Definition: BSTArray.h:542
BSTArray(size_type a_count)
Definition: BSTArray.h:411
constexpr bool empty() const noexcept
Definition: BSTArray.h:498
value_type * pointer
Definition: BSTArray.h:383
BSTArray & operator=(const BSTArray &a_rhs)
Definition: BSTArray.h:430
constexpr const_iterator end() const noexcept
Definition: BSTArray.h:495
constexpr const_iterator begin() const noexcept
Definition: BSTArray.h:491
constexpr const_reference front() const noexcept
Definition: BSTArray.h:482
constexpr const_iterator cend() const noexcept
Definition: BSTArray.h:496
pointer iterator
Definition: BSTArray.h:387
constexpr iterator begin() noexcept
Definition: BSTArray.h:490
Definition: BSTArray.h:148
constexpr BSTSmallArrayHeapAllocator() noexcept
Definition: BSTArray.h:152
BSTSmallArrayHeapAllocator & operator=(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:181
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t a_typeSize) noexcept
Definition: BSTArray.h:219
BSTSmallArrayHeapAllocator(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:164
std::uint32_t size_type
Definition: BSTArray.h:150
BSTSmallArrayHeapAllocator & operator=(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:173
~BSTSmallArrayHeapAllocator()
Definition: BSTArray.h:171
constexpr void * data() noexcept
Definition: BSTArray.h:191
constexpr const void * data() const noexcept
Definition: BSTArray.h:192
void * allocate(std::size_t a_size)
Definition: BSTArray.h:197
void deallocate(void *a_ptr)
Definition: BSTArray.h:212
BSTSmallArrayHeapAllocator(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:157
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:194
Definition: BSTArray.h:709
const value_type & const_reference
Definition: BSTArray.h:716
std::uint32_t size_type
Definition: BSTArray.h:712
const value_type * const_pointer
Definition: BSTArray.h:714
constexpr size_type size() const noexcept
Definition: BSTArray.h:752
iterator begin() noexcept
Definition: BSTArray.h:742
iterator end() noexcept
Definition: BSTArray.h:746
T value_type
Definition: BSTArray.h:711
const_iterator cbegin() const noexcept
Definition: BSTArray.h:744
const_pointer const_iterator
Definition: BSTArray.h:718
const_iterator begin() const noexcept
Definition: BSTArray.h:743
constexpr bool empty() const noexcept
Definition: BSTArray.h:750
reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:720
pointer data() noexcept
Definition: BSTArray.h:732
value_type & reference
Definition: BSTArray.h:715
pointer iterator
Definition: BSTArray.h:717
const_iterator end() const noexcept
Definition: BSTArray.h:747
const_iterator cend() const noexcept
Definition: BSTArray.h:748
value_type * pointer
Definition: BSTArray.h:713
const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:726
const_pointer data() const noexcept
Definition: BSTArray.h:737
Definition: ScrapHeap.h:10
NiColor min(const NiColor &a_lhs, const NiColor &a_rhs)
Definition: ColorUtil.h:63
Definition: AbsorbEffect.h:6
void * malloc(std::size_t a_size)
Definition: MemoryManager.h:98
constexpr std::array< REL::ID, 1 > VTABLE_BSTArrayBase__IAllocatorFunctor
Definition: Offsets_VTABLE.h:9923
constexpr REL::ID RTTI_BSTArrayBase__IAllocatorFunctor(static_cast< std::uint64_t >(684604))
void free(void *a_ptr)
Definition: MemoryManager.h:187
void report_and_fail(std::string_view a_msg, std::source_location a_loc=std::source_location::current())
Definition: PCH.h:588