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);
409 inline BSTArray(
const std::initializer_list<T> a_list)
411 if (a_list.size() == 0) {
415 const auto newSize = a_list.size();
416 const auto newData = allocate(newSize);
418 for (
const auto& elem : a_list) {
419 std::construct_at(newData + i++, elem);
422 set_allocator_traits(newData, newSize);
434 const auto newCapacity = a_count;
435 const auto newSize = a_count;
436 const auto newData = allocate(newCapacity);
437 for (
size_type i = 0; i < newSize; ++i) {
438 std::construct_at(newData + i);
441 set_allocator_traits(newData, newCapacity);
449 if (
this != std::addressof(a_rhs)) {
452 const auto newCapacity = a_rhs.
capacity();
453 change_capacity(newCapacity);
455 const auto newSize = a_rhs.
size();
458 const auto newData =
data();
459 for (
size_type i = 0; i < newSize; ++i) {
460 std::construct_at(newData + i, a_rhs[i]);
468 if (
this != std::addressof(a_rhs)) {
471 const auto newCapacity = a_rhs.capacity();
472 const auto newSize = a_rhs.size();
473 const auto newData = a_rhs.data();
475 set_allocator_traits(newData, newCapacity);
476 a_rhs.set_allocator_traits(0, 0);
488 assert(a_pos <
size());
489 return data()[a_pos];
494 assert(a_pos <
size());
495 return data()[a_pos];
504 [[nodiscard]]
constexpr pointer data() noexcept {
return static_cast<pointer>(allocator_type::data()); }
522 change_capacity(a_newCap);
526 [[nodiscard]]
constexpr size_type capacity() const noexcept {
return allocator_type::capacity(); }
530 const auto newCapacity =
size();
532 change_capacity(newCapacity);
545 auto pos =
const_cast<iterator>(a_pos);
546 std::optional<iterator> result;
547 if (pos !=
begin()) {
551 for (
auto prev = pos++; pos !=
cend(); prev = pos++) {
552 *prev = std::move(*pos);
556 return result ? *result + 1 :
begin();
562 template <
class... Args>
569 set_size(
size() + 1);
571 std::construct_at(std::addressof(elem), std::forward<Args>(a_args)...);
581 template <
class... Args>
584 assert(position >=
cbegin() && position <=
cend());
586 if (position ==
cend()) {
595 newCapacity = next_capacity();
596 newData = allocate(newCapacity);
604 const auto headPartToCopy = position -
cbegin();
605 const auto tailPartToCopy =
cend() - position;
606 const auto tailBytesToCopy = tailPartToCopy *
sizeof(T);
607 std::memcpy(newData + headPartToCopy + 1,
cend() - tailPartToCopy, tailBytesToCopy);
608 std::construct_at(newData + headPartToCopy, std::forward<Args>(a_args)...);
609 const auto headBytesToCopy = headPartToCopy *
sizeof(T);
610 std::memcpy(newData,
cbegin(), headBytesToCopy);
614 set_allocator_traits(newData, newCapacity);
617 set_size(
size() + 1);
619 return *(newData + headPartToCopy);
625 std::destroy_at(std::addressof(
back()));
626 set_size(
size() - 1);
631 if (a_count !=
size()) {
632 change_size(a_count);
638 if (a_count !=
size()) {
639 change_size(a_count, a_value);
645 static constexpr float GROWTH_FACTOR = 2.0;
649 return static_cast<pointer>(allocator_type::allocate(a_num *
sizeof(
value_type)));
652 inline void deallocate(
void* a_ptr) { allocator_type::deallocate(a_ptr); }
654 constexpr void set_allocator_traits(
void* a_data,
size_type a_capacity)
noexcept
656 allocator_type::set_allocator_traits(a_data, a_capacity,
sizeof(
value_type));
661 inline void change_capacity(
size_type a_newCapacity)
663 const auto newData = a_newCapacity > 0 ? allocate(a_newCapacity) : nullptr;
664 const auto oldData =
data();
666 const auto oldCapacity =
capacity();
668 const auto bytesToCopy = std::min(oldCapacity, a_newCapacity) *
sizeof(
value_type);
669 std::memcpy(newData, oldData, bytesToCopy);
673 set_allocator_traits(newData, a_newCapacity);
676 template <
class... Args>
677 inline void change_size(
size_type a_newSize, Args&&... a_args)
680 grow_capacity(a_newSize);
683 const auto oldSize =
size();
684 if (a_newSize > oldSize) {
685 for (
size_type i = oldSize; i < a_newSize; ++i) {
686 std::construct_at(
data() + i, std::forward<Args>(a_args)...);
689 for (
size_type i = a_newSize; i < oldSize; ++i) {
690 std::destroy_at(
data() + i);
699 [[nodiscard]]
inline size_type next_capacity()
const {
return next_capacity(
capacity()); }
706 cap = cap > 0 ?
static_cast<size_type>(std::ceil(
static_cast<float>(cap) * GROWTH_FACTOR)) : DF_CAP;
710 inline void grow_capacity() { grow_capacity(
capacity()); }
712 inline void grow_capacity(
size_type a_hint)
714 change_capacity(next_capacity(a_hint));
717 inline void release()
724 template <
class T, std::u
int32_t N = 1>
745 assert(a_pos < _size);
751 assert(a_pos < _size);
772 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() == 0; }
779 std::uint32_t _size{ 0 };
797 assert(a_pos < _size);
798 return data()[a_pos];
803 assert(a_pos < _size);
804 return data()[a_pos];
809 return size() > 1 ? _data.heap : std::addressof(_data.local);
814 return size() > 1 ? _data.heap : std::addressof(_data.local);
825 [[nodiscard]]
constexpr bool empty() const noexcept {
return size() != 0; }
839 std::uint32_t _size{ 0 };
Definition BSTArray.h:287
BSScrapArrayAllocator & operator=(const BSScrapArrayAllocator &a_rhs)
Definition BSTArray.h:314
constexpr BSScrapArrayAllocator() noexcept=default
constexpr const void * data() const noexcept
Definition BSTArray.h:352
constexpr void * data() noexcept
Definition BSTArray.h:351
constexpr size_type capacity() const noexcept
Definition BSTArray.h:354
constexpr BSScrapArrayAllocator(BSScrapArrayAllocator &&a_rhs) noexcept
Definition BSTArray.h:302
std::uint32_t size_type
Definition BSTArray.h:289
BSScrapArrayAllocator & operator=(BSScrapArrayAllocator &&a_rhs)
Definition BSTArray.h:331
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
void * allocate(std::size_t a_size)
Definition BSTArray.h:732
std::uint32_t size_type
Definition BSTArray.h:735
T value_type
Definition BSTArray.h:734
constexpr const_iterator begin() const noexcept
Definition BSTArray.h:765
const value_type * const_pointer
Definition BSTArray.h:737
constexpr const_iterator cbegin() const noexcept
Definition BSTArray.h:766
constexpr reference operator[](size_type a_pos) noexcept
Definition BSTArray.h:743
const value_type & const_reference
Definition BSTArray.h:739
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition BSTArray.h:749
constexpr const_pointer data() const noexcept
Definition BSTArray.h:762
const_pointer const_iterator
Definition BSTArray.h:741
constexpr const_reference front() const noexcept
Definition BSTArray.h:756
constexpr const_reference back() const noexcept
Definition BSTArray.h:759
constexpr reference back() noexcept
Definition BSTArray.h:758
constexpr iterator begin() noexcept
Definition BSTArray.h:764
constexpr bool empty() const noexcept
Definition BSTArray.h:772
pointer iterator
Definition BSTArray.h:740
value_type & reference
Definition BSTArray.h:738
constexpr iterator end() noexcept
Definition BSTArray.h:768
constexpr const_iterator cend() const noexcept
Definition BSTArray.h:770
constexpr size_type size() const noexcept
Definition BSTArray.h:774
constexpr reference front() noexcept
Definition BSTArray.h:755
value_type * pointer
Definition BSTArray.h:736
constexpr pointer data() noexcept
Definition BSTArray.h:761
constexpr const_iterator end() const noexcept
Definition BSTArray.h:769
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
BSTArrayBase & operator=(BSTArrayBase &&) noexcept=default
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
constexpr BSTArrayBase() noexcept=default
BSTArrayBase & operator=(const BSTArrayBase &) noexcept=default
std::uint32_t size_type
Definition BSTArray.h:12
void deallocate(void *a_ptr)
Definition BSTArray.h:131
std::uint32_t size_type
Definition BSTArray.h:55
constexpr void * data() noexcept
Definition BSTArray.h:114
BSTArrayHeapAllocator & operator=(BSTArrayHeapAllocator &&a_rhs)
Definition BSTArray.h:99
BSTArrayHeapAllocator & operator=(const BSTArrayHeapAllocator &a_rhs)
Definition BSTArray.h:83
constexpr const void * data() const noexcept
Definition BSTArray.h:115
void * allocate(std::size_t a_size)
Definition BSTArray.h:120
~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
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:636
void push_back(value_type &&a_value)
Definition BSTArray.h:560
void resize(size_type a_count)
Definition BSTArray.h:629
void pop_back()
Definition BSTArray.h:622
constexpr pointer data() noexcept
Definition BSTArray.h:504
iterator erase(const_iterator a_pos)
Definition BSTArray.h:543
constexpr size_type size() const noexcept
Definition BSTArray.h:517
constexpr reference back() noexcept
Definition BSTArray.h:501
constexpr const_iterator cbegin() const noexcept
Definition BSTArray.h:509
void clear()
Definition BSTArray.h:536
reference emplace(const_iterator position, Args &&... a_args)
Definition BSTArray.h:582
constexpr reference operator[](size_type a_pos) noexcept
Definition BSTArray.h:486
Allocator allocator_type
Definition BSTArray.h:380
constexpr const_reference operator[](size_type a_pos) const noexcept
Definition BSTArray.h:492
~BSTArray()
Definition BSTArray.h:445
reference emplace_back(Args &&... a_args)
Definition BSTArray.h:563
constexpr size_type capacity() const noexcept
Definition BSTArray.h:526
T value_type
Definition BSTArray.h:382
constexpr const_reference back() const noexcept
Definition BSTArray.h:502
void reserve(size_type a_newCap)
Definition BSTArray.h:519
void insert(const_iterator position, value_type &&a_value)
Definition BSTArray.h:576
typename BSTArrayBase::size_type size_type
Definition BSTArray.h:381
void shrink_to_fit()
Definition BSTArray.h:528
const value_type & const_reference
Definition BSTArray.h:386
constexpr const_pointer data() const noexcept
Definition BSTArray.h:505
BSTArray(const BSTArray &a_rhs)
Definition BSTArray.h:392
constexpr iterator end() noexcept
Definition BSTArray.h:511
BSTArray(const std::initializer_list< T > a_list)
Definition BSTArray.h:409
BSTArray & operator=(const BSTArray &a_rhs)
Definition BSTArray.h:447
constexpr reference front() noexcept
Definition BSTArray.h:498
BSTArray & operator=(BSTArray &&a_rhs)
Definition BSTArray.h:466
BSTArray(BSTArray &&)=default
const value_type * const_pointer
Definition BSTArray.h:384
void push_back(const value_type &a_value)
Definition BSTArray.h:559
BSTArray(size_type a_count)
Definition BSTArray.h:428
constexpr bool empty() const noexcept
Definition BSTArray.h:515
value_type * pointer
Definition BSTArray.h:383
void insert(const_iterator position, const value_type &a_value)
Definition BSTArray.h:575
void push_front(value_type &&a_value)
Definition BSTArray.h:579
constexpr const_iterator end() const noexcept
Definition BSTArray.h:512
constexpr const_iterator begin() const noexcept
Definition BSTArray.h:508
void push_front(const value_type &a_value)
Definition BSTArray.h:578
constexpr const_reference front() const noexcept
Definition BSTArray.h:499
constexpr const_iterator cend() const noexcept
Definition BSTArray.h:513
pointer iterator
Definition BSTArray.h:387
constexpr iterator begin() noexcept
Definition BSTArray.h:507
Definition BSTArray.h:148
constexpr BSTSmallArrayHeapAllocator() noexcept
Definition BSTArray.h:152
constexpr void set_allocator_traits(void *a_data, std::uint32_t a_capacity, std::size_t a_typeSize) noexcept
Definition BSTArray.h:219
constexpr void * data() noexcept
Definition BSTArray.h:191
BSTSmallArrayHeapAllocator(BSTSmallArrayHeapAllocator &&a_rhs)
Definition BSTArray.h:164
std::uint32_t size_type
Definition BSTArray.h:150
BSTSmallArrayHeapAllocator & operator=(BSTSmallArrayHeapAllocator &&a_rhs)
Definition BSTArray.h:181
BSTSmallArrayHeapAllocator & operator=(const BSTSmallArrayHeapAllocator &a_rhs)
Definition BSTArray.h:173
void * allocate(std::size_t a_size)
Definition BSTArray.h:197
~BSTSmallArrayHeapAllocator()
Definition BSTArray.h:171
void deallocate(void *a_ptr)
Definition BSTArray.h:212
BSTSmallArrayHeapAllocator(const BSTSmallArrayHeapAllocator &a_rhs)
Definition BSTArray.h:157
constexpr const void * data() const noexcept
Definition BSTArray.h:192
constexpr size_type capacity() const noexcept
Definition BSTArray.h:194
Definition BSTArray.h:784
const value_type & const_reference
Definition BSTArray.h:791
std::uint32_t size_type
Definition BSTArray.h:787
const value_type * const_pointer
Definition BSTArray.h:789
constexpr size_type size() const noexcept
Definition BSTArray.h:827
iterator begin() noexcept
Definition BSTArray.h:817
iterator end() noexcept
Definition BSTArray.h:821
T value_type
Definition BSTArray.h:786
const_iterator cbegin() const noexcept
Definition BSTArray.h:819
const_pointer const_iterator
Definition BSTArray.h:793
const_iterator begin() const noexcept
Definition BSTArray.h:818
constexpr bool empty() const noexcept
Definition BSTArray.h:825
reference operator[](size_type a_pos) noexcept
Definition BSTArray.h:795
pointer data() noexcept
Definition BSTArray.h:807
value_type & reference
Definition BSTArray.h:790
pointer iterator
Definition BSTArray.h:792
const_iterator end() const noexcept
Definition BSTArray.h:822
const_iterator cend() const noexcept
Definition BSTArray.h:823
value_type * pointer
Definition BSTArray.h:788
const_reference operator[](size_type a_pos) const noexcept
Definition BSTArray.h:801
const_pointer data() const noexcept
Definition BSTArray.h:812
Definition ScrapHeap.h:10
Definition AbsorbEffect.h:6
T * malloc()
Definition MemoryManager.h:113
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:397