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 return emplace(a_pos, a_value);
532 return emplace(a_pos, std::move(a_value));
535 template <
class... Args>
538 if (a_pos ==
end()) {
539 return std::addressof(
emplace_back(std::forward<Args>(a_args)...));
542 const auto offset = a_pos -
begin();
543 const auto oldSize =
size();
544 const auto newSize = oldSize + 1;
547 const auto newCapacity = calculate_growth(newSize);
548 const auto newData = allocate(newCapacity);
549 const auto oldData =
data();
552 const auto bytesToCopy = offset *
sizeof(
value_type);
553 std::memcpy(newData, oldData, bytesToCopy);
555 const auto bytesToCopy = (oldSize - offset) *
sizeof(
value_type);
556 std::memcpy(newData + offset + 1, oldData + offset, bytesToCopy);
559 set_allocator_traits(newData, newCapacity);
561 const auto bytesToMove = (oldSize - offset) *
sizeof(
value_type);
562 std::memmove(
data() + offset + 1,
data() + offset, bytesToMove);
566 auto& elem =
data()[offset];
568 std::construct_at(std::addressof(elem), std::forward<Args>(a_args)...);
569 return std::addressof(elem);
574 auto pos =
const_cast<iterator>(a_pos);
575 std::optional<iterator> result;
576 if (pos !=
begin()) {
580 for (
auto prev = pos++; pos !=
cend(); prev = pos++) {
581 *prev = std::move(*pos);
585 return result ? *result + 1 :
begin();
591 template <
class... Args>
598 set_size(
size() + 1);
600 std::construct_at(std::addressof(elem), std::forward<Args>(a_args)...);
607 std::destroy_at(std::addressof(
back()));
608 set_size(
size() - 1);
613 if (a_count !=
size()) {
614 change_size(a_count);
620 if (a_count !=
size()) {
621 change_size(a_count, a_value);
627 static constexpr
float GROWTH_FACTOR = 2.0;
631 return static_cast<pointer>(allocator_type::allocate(a_num *
sizeof(
value_type)));
634 inline void deallocate(
void* a_ptr) { allocator_type::deallocate(a_ptr); }
636 constexpr
void set_allocator_traits(
void* a_data,
size_type a_capacity) noexcept
638 allocator_type::set_allocator_traits(a_data, a_capacity,
sizeof(
value_type));
643 inline void change_capacity(
size_type a_newCapacity)
645 const auto newData = a_newCapacity > 0 ? allocate(a_newCapacity) : nullptr;
646 const auto oldData =
data();
648 const auto oldCapacity =
capacity();
650 const auto bytesToCopy = std::min(oldCapacity, a_newCapacity) *
sizeof(
value_type);
651 std::memcpy(newData, oldData, bytesToCopy);
655 set_allocator_traits(newData, a_newCapacity);
658 template <
class... Args>
659 inline void change_size(
size_type a_newSize, Args&&... a_args)
662 grow_capacity(a_newSize);
665 const auto oldSize =
size();
666 if (a_newSize > oldSize) {
667 for (
size_type i = oldSize; i < a_newSize; ++i) {
668 std::construct_at(
data() + i, std::forward<Args>(a_args)...);
671 for (
size_type i = a_newSize; i < oldSize; ++i) {
672 std::destroy_at(
data() + i);
679 inline void grow_capacity() { grow_capacity(
capacity()); }
681 inline void grow_capacity(
size_type a_hint)
683 const auto cap = calculate_growth(a_hint);
684 change_capacity(cap);
689 return a_hint > 0 ?
static_cast<size_type>(std::ceil(
static_cast<float>(a_hint) * GROWTH_FACTOR)) : DF_CAP;
692 inline void release()
699 template <
class T, std::u
int32_t N = 1>
720 assert(a_pos < _size);
726 assert(a_pos < _size);
747 [[nodiscard]] constexpr
bool empty() const noexcept {
return size() == 0; }
754 std::uint32_t _size{ 0 };
772 assert(a_pos < _size);
773 return data()[a_pos];
778 assert(a_pos < _size);
779 return data()[a_pos];
784 return size() > 1 ? _data.heap : std::addressof(_data.local);
789 return size() > 1 ? _data.heap : std::addressof(_data.local);
800 [[nodiscard]] constexpr
bool empty() const noexcept {
return size() != 0; }
814 std::uint32_t _size{ 0 };
Definition: BSTArray.h:286
BSScrapArrayAllocator & operator=(const BSScrapArrayAllocator &a_rhs)
Definition: BSTArray.h:313
constexpr BSScrapArrayAllocator() noexcept=default
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:353
BSScrapArrayAllocator & operator=(BSScrapArrayAllocator &&a_rhs)
Definition: BSTArray.h:330
constexpr BSScrapArrayAllocator(BSScrapArrayAllocator &&a_rhs) noexcept
Definition: BSTArray.h:301
constexpr void * data() noexcept
Definition: BSTArray.h:350
std::uint32_t size_type
Definition: BSTArray.h:288
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
constexpr const void * data() const noexcept
Definition: BSTArray.h:351
void * allocate(std::size_t a_size)
Definition: BSTArray.h:707
std::uint32_t size_type
Definition: BSTArray.h:710
T value_type
Definition: BSTArray.h:709
constexpr const_iterator begin() const noexcept
Definition: BSTArray.h:740
const value_type * const_pointer
Definition: BSTArray.h:712
constexpr const_iterator cbegin() const noexcept
Definition: BSTArray.h:741
constexpr reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:718
const value_type & const_reference
Definition: BSTArray.h:714
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:724
constexpr const_pointer data() const noexcept
Definition: BSTArray.h:737
const_pointer const_iterator
Definition: BSTArray.h:716
constexpr const_reference front() const noexcept
Definition: BSTArray.h:731
constexpr const_reference back() const noexcept
Definition: BSTArray.h:734
constexpr reference back() noexcept
Definition: BSTArray.h:733
constexpr iterator begin() noexcept
Definition: BSTArray.h:739
constexpr bool empty() const noexcept
Definition: BSTArray.h:747
pointer iterator
Definition: BSTArray.h:715
value_type & reference
Definition: BSTArray.h:713
constexpr iterator end() noexcept
Definition: BSTArray.h:743
constexpr const_iterator cend() const noexcept
Definition: BSTArray.h:745
constexpr size_type size() const noexcept
Definition: BSTArray.h:749
constexpr reference front() noexcept
Definition: BSTArray.h:730
value_type * pointer
Definition: BSTArray.h:711
constexpr pointer data() noexcept
Definition: BSTArray.h:736
constexpr const_iterator end() const noexcept
Definition: BSTArray.h:744
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
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
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:52
constexpr void * data() noexcept
Definition: BSTArray.h:113
void deallocate(void *a_ptr)
Definition: BSTArray.h:130
std::uint32_t size_type
Definition: BSTArray.h:54
void * allocate(std::size_t a_size)
Definition: BSTArray.h:119
BSTArrayHeapAllocator & operator=(BSTArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:98
~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
BSTArrayHeapAllocator & operator=(const BSTArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:82
constexpr const void * data() const noexcept
Definition: BSTArray.h:114
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:618
void push_back(value_type &&a_value)
Definition: BSTArray.h:589
void resize(size_type a_count)
Definition: BSTArray.h:611
void pop_back()
Definition: BSTArray.h:604
constexpr pointer data() noexcept
Definition: BSTArray.h:486
iterator erase(const_iterator a_pos)
Definition: BSTArray.h:572
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
BSTArray & operator=(BSTArray &&a_rhs)
Definition: BSTArray.h:448
reference emplace_back(Args &&... a_args)
Definition: BSTArray.h:592
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
constexpr reference front() noexcept
Definition: BSTArray.h:480
BSTArray(BSTArray &&)=default
const value_type * const_pointer
Definition: BSTArray.h:383
void push_back(const value_type &a_value)
Definition: BSTArray.h:588
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
iterator emplace(const_iterator a_pos, Args &&... a_args)
Definition: BSTArray.h:536
BSTArray & operator=(const BSTArray &a_rhs)
Definition: BSTArray.h:429
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
iterator insert(const_iterator a_pos, const T &a_value)
Definition: BSTArray.h:525
iterator insert(const_iterator a_pos, T &&a_value)
Definition: BSTArray.h:530
constexpr iterator begin() noexcept
Definition: BSTArray.h:489
Definition: BSTArray.h:147
constexpr BSTSmallArrayHeapAllocator() noexcept
Definition: BSTArray.h:151
BSTSmallArrayHeapAllocator & operator=(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:180
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t a_typeSize) noexcept
Definition: BSTArray.h:218
BSTSmallArrayHeapAllocator(BSTSmallArrayHeapAllocator &&a_rhs)
Definition: BSTArray.h:163
std::uint32_t size_type
Definition: BSTArray.h:149
BSTSmallArrayHeapAllocator & operator=(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:172
~BSTSmallArrayHeapAllocator()
Definition: BSTArray.h:170
constexpr void * data() noexcept
Definition: BSTArray.h:190
constexpr const void * data() const noexcept
Definition: BSTArray.h:191
void * allocate(std::size_t a_size)
Definition: BSTArray.h:196
void deallocate(void *a_ptr)
Definition: BSTArray.h:211
BSTSmallArrayHeapAllocator(const BSTSmallArrayHeapAllocator &a_rhs)
Definition: BSTArray.h:156
constexpr size_type capacity() const noexcept
Definition: BSTArray.h:193
Definition: BSTArray.h:759
const value_type & const_reference
Definition: BSTArray.h:766
std::uint32_t size_type
Definition: BSTArray.h:762
const value_type * const_pointer
Definition: BSTArray.h:764
constexpr size_type size() const noexcept
Definition: BSTArray.h:802
iterator begin() noexcept
Definition: BSTArray.h:792
iterator end() noexcept
Definition: BSTArray.h:796
T value_type
Definition: BSTArray.h:761
const_iterator cbegin() const noexcept
Definition: BSTArray.h:794
const_pointer const_iterator
Definition: BSTArray.h:768
const_iterator begin() const noexcept
Definition: BSTArray.h:793
constexpr bool empty() const noexcept
Definition: BSTArray.h:800
reference operator[](size_type a_pos) noexcept
Definition: BSTArray.h:770
pointer data() noexcept
Definition: BSTArray.h:782
value_type & reference
Definition: BSTArray.h:765
pointer iterator
Definition: BSTArray.h:767
const_iterator end() const noexcept
Definition: BSTArray.h:797
const_iterator cend() const noexcept
Definition: BSTArray.h:798
value_type * pointer
Definition: BSTArray.h:763
const_reference operator[](size_type a_pos) const noexcept
Definition: BSTArray.h:776
const_pointer data() const noexcept
Definition: BSTArray.h:787
Definition: ScrapHeap.h:8
Definition: AbsorbEffect.h:6
constexpr REL::ID RTTI_BSTArrayBase__IAllocatorFunctor
Definition: Offsets_RTTI.h:2655
void * malloc(std::size_t a_size)
Definition: MemoryManager.h:66
void report_and_fail(std::string_view a_msg, std::source_location a_loc=std::source_location::current())
Definition: PCH.h:621