20 virtual bool Allocate(std::uint32_t a_num, std::uint32_t a_elemSize) = 0;
21 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;
39 [[nodiscard]] constexpr
bool empty() const noexcept {
return _size == 0; }
40 [[nodiscard]]
constexpr size_type size() const noexcept {
return _size; }
47 std::uint32_t _size{ 0 };
49 static_assert(
sizeof(BSTArrayBase) == 0x4);
61 _capacity = a_rhs.capacity();
69 _capacity(a_rhs.capacity())
71 a_rhs._data =
nullptr;
84 if (
this != std::addressof(a_rhs)) {
100 if (
this != std::addressof(a_rhs)) {
102 _data = a_rhs.data();
103 _capacity = a_rhs.capacity();
105 a_rhs._data =
nullptr;
113 [[nodiscard]]
constexpr void*
data() noexcept {
return _data; }
114 [[nodiscard]]
constexpr const void*
data() const noexcept {
return _data; }
121 const auto mem =
malloc(a_size);
125 std::memset(mem, 0, a_size);
135 _capacity = a_capacity;
140 void* _data{
nullptr };
141 std::uint32_t _capacity{ 0 };
143 static_assert(
sizeof(BSTArrayHeapAllocator) == 0x10);
145 template <std::u
int32_t N>
167 copy(std::move(a_rhs));
174 if (
this != std::addressof(a_rhs)) {
182 if (
this != std::addressof(a_rhs)) {
183 copy(std::move(a_rhs));
190 [[nodiscard]]
constexpr void*
data() noexcept {
return local() ? _data.local : _data.heap; }
191 [[nodiscard]]
constexpr const void*
data() const noexcept {
return local() ? _data.local : _data.heap; }
199 const auto mem =
malloc(a_size);
203 std::memset(mem, 0, a_size);
213 if (a_ptr != _data.local) {
220 _capacity = a_capacity;
221 if (a_capacity * a_typeSize > N) {
238 _capacity = a_rhs._capacity;
239 _local = a_rhs._local;
257 _capacity = a_rhs._capacity;
258 _local = a_rhs._local;
261 std::memset(a_rhs.data(), 0, a_rhs.capacity());
266 [[nodiscard]]
constexpr bool local() const noexcept {
return _local != 0; }
268 inline void release()
280 std::uint32_t _capacity: 31;
281 std::uint32_t _local: 1;
293 _capacity(a_rhs._capacity)
302 _allocator(a_rhs._allocator),
304 _capacity(a_rhs._capacity)
306 a_rhs._allocator =
nullptr;
307 a_rhs._data =
nullptr;
315 if (
this != std::addressof(a_rhs)) {
332 if (
this != std::addressof(a_rhs)) {
337 _allocator = a_rhs._allocator;
339 _capacity = a_rhs._capacity;
341 a_rhs._allocator =
nullptr;
342 a_rhs._data =
nullptr;
350 [[nodiscard]]
constexpr void*
data() noexcept {
return _data; }
351 [[nodiscard]]
constexpr const void*
data() const noexcept {
return _data; }
362 _capacity = a_capacity;
368 void* _data{
nullptr };
371 static_assert(
sizeof(BSScrapArrayAllocator) == 0x18);
373 template <
class T,
class Allocator = BSTArrayHeapAllocator>
393 const auto newCapacity = a_rhs.
capacity();
394 if (newCapacity == 0) {
398 const auto newSize = a_rhs.
size();
399 const auto newData = allocate(newCapacity);
400 for (
size_type i = 0; i < newSize; ++i) {
401 std::construct_at(newData + i, a_rhs[i]);
404 set_allocator_traits(newData, newCapacity);
416 const auto newCapacity = a_count;
417 const auto newSize = a_count;
418 const auto newData = allocate(newCapacity);
419 for (
size_type i = 0; i < newSize; ++i) {
420 std::construct_at(newData + i);
423 set_allocator_traits(newData, newCapacity);
431 if (
this != std::addressof(a_rhs)) {
434 const auto newCapacity = a_rhs.
capacity();
435 change_capacity(newCapacity);
437 const auto newSize = a_rhs.
size();
440 const auto newData =
data();
441 for (
size_type i = 0; i < newSize; ++i) {
442 std::construct_at(newData + i, a_rhs[i]);
450 if (
this != std::addressof(a_rhs)) {
453 const auto newCapacity = a_rhs.capacity();
454 const auto newSize = a_rhs.size();
455 const auto newData = a_rhs.data();
457 set_allocator_traits(newData, newCapacity);
458 a_rhs.set_allocator_traits(0, 0);
470 assert(a_pos <
size());
471 return data()[a_pos];
476 assert(a_pos <
size());
477 return data()[a_pos];
486 [[nodiscard]]
constexpr pointer data() noexcept {
return static_cast<pointer>(allocator_type::data()); }
504 change_capacity(a_newCap);
508 [[nodiscard]]
constexpr size_type capacity() const noexcept {
return allocator_type::capacity(); }
512 const auto newCapacity =
size();
514 change_capacity(newCapacity);
527 auto pos =
const_cast<iterator>(a_pos);
528 std::optional<iterator> result;
529 if (pos !=
begin()) {
533 for (
auto prev = pos++; pos !=
cend(); prev = pos++) {
534 *prev = std::move(*pos);
538 return result ? *result + 1 :
begin();
544 template <
class... Args>
551 set_size(
size() + 1);
553 std::construct_at(std::addressof(elem), std::forward<Args>(a_args)...);
560 std::destroy_at(std::addressof(
back()));
561 set_size(
size() - 1);
566 if (a_count !=
size()) {
567 change_size(a_count);
573 if (a_count !=
size()) {
574 change_size(a_count, a_value);
580 static constexpr float GROWTH_FACTOR = 2.0;
584 return static_cast<pointer>(allocator_type::allocate(a_num *
sizeof(
value_type)));
587 inline void deallocate(
void* a_ptr) { allocator_type::deallocate(a_ptr); }
589 constexpr void set_allocator_traits(
void* a_data,
size_type a_capacity)
noexcept
591 allocator_type::set_allocator_traits(a_data, a_capacity,
sizeof(
value_type));
596 inline void change_capacity(
size_type a_newCapacity)
598 const auto newData = a_newCapacity > 0 ? allocate(a_newCapacity) : nullptr;
599 const auto oldData =
data();
601 const auto oldCapacity =
capacity();
603 const auto bytesToCopy = std::min(oldCapacity, a_newCapacity) *
sizeof(
value_type);
604 std::memcpy(newData, oldData, bytesToCopy);
608 set_allocator_traits(newData, a_newCapacity);
611 template <
class... Args>
612 inline void change_size(
size_type a_newSize, Args&&... a_args)
615 grow_capacity(a_newSize);
618 const auto oldSize =
size();
619 if (a_newSize > oldSize) {
620 for (
size_type i = oldSize; i < a_newSize; ++i) {
621 std::construct_at(
data() + i, std::forward<Args>(a_args)...);
624 for (
size_type i = a_newSize; i < oldSize; ++i) {
625 std::destroy_at(
data() + i);
632 inline void grow_capacity() { grow_capacity(
capacity()); }
634 inline void grow_capacity(
size_type a_hint)
637 cap = cap > 0 ?
static_cast<size_type>(std::ceil(
static_cast<float>(cap) * GROWTH_FACTOR)) : DF_CAP;
638 change_capacity(cap);
641 inline void release()
648 template <
class T, std::u
int32_t N = 1>
669 assert(a_pos < _size);
675 assert(a_pos < _size);
696 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
703 std::uint32_t _size{ 0 };
721 assert(a_pos < _size);
722 return data()[a_pos];
727 assert(a_pos < _size);
728 return data()[a_pos];
733 return size() > 1 ? _data.heap : std::addressof(_data.local);
738 return size() > 1 ? _data.heap : std::addressof(_data.local);
749 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() != 0; }
763 std::uint32_t _size{ 0 };
Definition: BSTArray.h:286
BSScrapArrayAllocator & operator=(const BSScrapArrayAllocator &a_rhs)
Definition: BSTArray.h:313
constexpr BSScrapArrayAllocator() noexcept=default
constexpr const void * data() const noexcept
Definition: BSTArray.h:351
constexpr void * data() noexcept
Definition: BSTArray.h:350
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:353
constexpr BSScrapArrayAllocator(BSScrapArrayAllocator &&a_rhs) noexcept
Definition: BSTArray.h:301
std::uint32_t size_type
Definition: BSTArray.h:288
BSScrapArrayAllocator & operator=(BSScrapArrayAllocator &&a_rhs)
Definition: BSTArray.h:330
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:359
void * allocate(std::size_t a_size)
Definition: BSTArray.h:656
std::uint32_t size_type
Definition: BSTArray.h:659
T value_type
Definition: BSTArray.h:658
constexpr const_iterator begin() const noexcept
Definition: BSTArray.h:689
const value_type * const_pointer
Definition: BSTArray.h:661
constexpr const_iterator cbegin() const noexcept
Definition: BSTArray.h:690
constexpr reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:667
const value_type & const_reference
Definition: BSTArray.h:663
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:673
constexpr const_pointer data() const noexcept
Definition: BSTArray.h:686
const_pointer const_iterator
Definition: BSTArray.h:665
constexpr const_reference front() const noexcept
Definition: BSTArray.h:680
constexpr const_reference back() const noexcept
Definition: BSTArray.h:683
constexpr reference back() noexcept
Definition: BSTArray.h:682
constexpr iterator begin() noexcept
Definition: BSTArray.h:688
constexpr bool empty() const noexcept
Definition: BSTArray.h:696
pointer iterator
Definition: BSTArray.h:664
value_type & reference
Definition: BSTArray.h:662
constexpr iterator end() noexcept
Definition: BSTArray.h:692
constexpr const_iterator cend() const noexcept
Definition: BSTArray.h:694
constexpr size_type size() const noexcept
Definition: BSTArray.h:698
constexpr reference front() noexcept
Definition: BSTArray.h:679
value_type * pointer
Definition: BSTArray.h:660
constexpr pointer data() noexcept
Definition: BSTArray.h:685
constexpr const_iterator end() const noexcept
Definition: BSTArray.h:693
Definition: BSTArray.h:15
virtual bool Allocate(std::uint32_t a_num, std::uint32_t a_elemSize)=0
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
BSTArrayBase & operator=(BSTArrayBase &&) noexcept=default
constexpr size_type size() const noexcept
Definition: BSTArray.h:40
constexpr void set_size(size_type a_size) noexcept
Definition: BSTArray.h:43
constexpr bool empty() const noexcept
Definition: BSTArray.h:39
constexpr BSTArrayBase() noexcept=default
BSTArrayBase & operator=(const BSTArrayBase &) noexcept=default
std::uint32_t size_type
Definition: BSTArray.h:12
Definition: BSTArray.h:52
void deallocate(void *a_ptr)
Definition: BSTArray.h:130
std::uint32_t size_type
Definition: BSTArray.h:54
constexpr void * data() noexcept
Definition: BSTArray.h:113
BSTArrayHeapAllocator & operator=(BSTArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:98
BSTArrayHeapAllocator & operator=(const BSTArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:82
constexpr const void * data() const noexcept
Definition: BSTArray.h:114
void * allocate(std::size_t a_size)
Definition: BSTArray.h:119
~BSTArrayHeapAllocator()
Definition: BSTArray.h:75
constexpr BSTArrayHeapAllocator(BSTArrayHeapAllocator &&a_rhs) noexcept
Definition: BSTArray.h:67
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t) noexcept
Definition: BSTArray.h:132
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:116
constexpr BSTArrayHeapAllocator() noexcept=default
Definition: BSTArray.h:377
value_type & reference
Definition: BSTArray.h:384
const_pointer const_iterator
Definition: BSTArray.h:387
void resize(size_type a_count, const value_type &a_value)
Definition: BSTArray.h:571
void push_back(value_type &&a_value)
Definition: BSTArray.h:542
void resize(size_type a_count)
Definition: BSTArray.h:564
void pop_back()
Definition: BSTArray.h:557
constexpr pointer data() noexcept
Definition: BSTArray.h:486
iterator erase(const_iterator a_pos)
Definition: BSTArray.h:525
constexpr size_type size() const noexcept
Definition: BSTArray.h:499
constexpr reference back() noexcept
Definition: BSTArray.h:483
constexpr const_iterator cbegin() const noexcept
Definition: BSTArray.h:491
void clear()
Definition: BSTArray.h:518
constexpr reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:468
Allocator allocator_type
Definition: BSTArray.h:379
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:474
~BSTArray()
Definition: BSTArray.h:427
reference emplace_back(Args &&... a_args)
Definition: BSTArray.h:545
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:508
T value_type
Definition: BSTArray.h:381
constexpr const_reference back() const noexcept
Definition: BSTArray.h:484
void reserve(size_type a_newCap)
Definition: BSTArray.h:501
typename BSTArrayBase::size_type size_type
Definition: BSTArray.h:380
void shrink_to_fit()
Definition: BSTArray.h:510
const value_type & const_reference
Definition: BSTArray.h:385
constexpr const_pointer data() const noexcept
Definition: BSTArray.h:487
BSTArray(const BSTArray &a_rhs)
Definition: BSTArray.h:391
constexpr iterator end() noexcept
Definition: BSTArray.h:493
BSTArray & operator=(const BSTArray &a_rhs)
Definition: BSTArray.h:429
constexpr reference front() noexcept
Definition: BSTArray.h:480
BSTArray & operator=(BSTArray &&a_rhs)
Definition: BSTArray.h:448
BSTArray(BSTArray &&)=default
const value_type * const_pointer
Definition: BSTArray.h:383
void push_back(const value_type &a_value)
Definition: BSTArray.h:541
BSTArray(size_type a_count)
Definition: BSTArray.h:410
constexpr bool empty() const noexcept
Definition: BSTArray.h:497
value_type * pointer
Definition: BSTArray.h:382
constexpr const_iterator end() const noexcept
Definition: BSTArray.h:494
constexpr const_iterator begin() const noexcept
Definition: BSTArray.h:490
constexpr const_reference front() const noexcept
Definition: BSTArray.h:481
constexpr const_iterator cend() const noexcept
Definition: BSTArray.h:495
pointer iterator
Definition: BSTArray.h:386
constexpr iterator begin() noexcept
Definition: BSTArray.h:489
Definition: BSTArray.h:147
constexpr BSTSmallArrayHeapAllocator() noexcept
Definition: BSTArray.h:151
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t a_typeSize) noexcept
Definition: BSTArray.h:218
constexpr void * data() noexcept
Definition: BSTArray.h:190
BSTSmallArrayHeapAllocator(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:163
std::uint32_t size_type
Definition: BSTArray.h:149
BSTSmallArrayHeapAllocator & operator=(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:180
BSTSmallArrayHeapAllocator & operator=(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:172
void * allocate(std::size_t a_size)
Definition: BSTArray.h:196
~BSTSmallArrayHeapAllocator()
Definition: BSTArray.h:170
void deallocate(void *a_ptr)
Definition: BSTArray.h:211
BSTSmallArrayHeapAllocator(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:156
constexpr const void * data() const noexcept
Definition: BSTArray.h:191
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:193
Definition: BSTArray.h:708
const value_type & const_reference
Definition: BSTArray.h:715
std::uint32_t size_type
Definition: BSTArray.h:711
const value_type * const_pointer
Definition: BSTArray.h:713
constexpr size_type size() const noexcept
Definition: BSTArray.h:751
iterator begin() noexcept
Definition: BSTArray.h:741
iterator end() noexcept
Definition: BSTArray.h:745
T value_type
Definition: BSTArray.h:710
const_iterator cbegin() const noexcept
Definition: BSTArray.h:743
const_pointer const_iterator
Definition: BSTArray.h:717
const_iterator begin() const noexcept
Definition: BSTArray.h:742
constexpr bool empty() const noexcept
Definition: BSTArray.h:749
reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:719
pointer data() noexcept
Definition: BSTArray.h:731
value_type & reference
Definition: BSTArray.h:714
pointer iterator
Definition: BSTArray.h:716
const_iterator end() const noexcept
Definition: BSTArray.h:746
const_iterator cend() const noexcept
Definition: BSTArray.h:747
value_type * pointer
Definition: BSTArray.h:712
const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:725
const_pointer data() const noexcept
Definition: BSTArray.h:736
Definition: ScrapHeap.h:8
Definition: AbsorbEffect.h:6
constexpr REL::ID RTTI_BSTArrayBase__IAllocatorFunctor
Definition: Offsets_RTTI.h:2655
T * malloc()
Definition: MemoryManager.h:113
void free(void *a_ptr)
Definition: MemoryManager.h:183
void report_and_fail(std::string_view a_msg, std::source_location a_loc=std::source_location::current())
Definition: PCH.h:580