2#include "gaia/config/config.h"
5#include <initializer_list>
11#include "gaia/core/iterator.h"
12#include "gaia/core/utility.h"
13#include "gaia/mem/data_layout_policy.h"
14#include "gaia/mem/mem_utils.h"
15#include "gaia/mem/raw_data_holder.h"
20 namespace sarr_ext_soa_detail {
28 struct sarr_ext_soa_iterator {
35 using size_type = sarr_ext_soa_detail::size_type;
37 using iterator = sarr_ext_soa_iterator;
47 sarr_ext_soa_iterator(uint8_t* ptr, uint32_t cnt, uint32_t idx): m_ptr(ptr), m_cnt(cnt), m_idx(idx) {}
50 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
52 T operator->()
const {
53 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
56 return iterator(m_ptr, m_cnt, m_idx + offset);
87 return iterator(m_ptr, m_cnt, m_idx + offset);
90 return iterator(m_ptr, m_cnt, m_idx + offset);
93 GAIA_ASSERT(m_ptr == other.m_ptr);
98 GAIA_ASSERT(m_ptr == other.m_ptr);
99 return m_idx == other.m_idx;
102 GAIA_ASSERT(m_ptr == other.m_ptr);
103 return m_idx != other.m_idx;
105 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
106 GAIA_ASSERT(m_ptr == other.m_ptr);
107 return m_idx > other.m_idx;
109 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
110 GAIA_ASSERT(m_ptr == other.m_ptr);
111 return m_idx >= other.m_idx;
113 GAIA_NODISCARD
bool operator<(
const iterator& other)
const {
114 GAIA_ASSERT(m_ptr == other.m_ptr);
115 return m_idx < other.m_idx;
117 GAIA_NODISCARD
bool operator<=(
const iterator& other)
const {
118 GAIA_ASSERT(m_ptr == other.m_ptr);
119 return m_idx <= other.m_idx;
123 template <
typename T>
124 struct const_sarr_ext_soa_iterator {
129 using size_type = sarr_ext_soa_detail::size_type;
131 using iterator = const_sarr_ext_soa_iterator;
135 const uint8_t* m_ptr;
140 const_sarr_ext_soa_iterator(
const uint8_t* ptr, uint32_t cnt, uint32_t idx): m_ptr(ptr), m_cnt(cnt), m_idx(idx) {}
142 T operator*()
const {
143 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
145 T operator->()
const {
146 return mem::data_view_policy<T::gaia_Data_Layout, T>::get({m_ptr, m_cnt}, m_idx);
149 return iterator(m_ptr, m_cnt, m_idx + offset);
180 return iterator(m_ptr, m_cnt, m_idx + offset);
183 return iterator(m_ptr, m_cnt, m_idx + offset);
186 GAIA_ASSERT(m_ptr == other.m_ptr);
191 GAIA_ASSERT(m_ptr == other.m_ptr);
192 return m_idx == other.m_idx;
195 GAIA_ASSERT(m_ptr == other.m_ptr);
196 return m_idx != other.m_idx;
198 GAIA_NODISCARD
bool operator>(
const iterator& other)
const {
199 GAIA_ASSERT(m_ptr == other.m_ptr);
200 return m_idx > other.m_idx;
202 GAIA_NODISCARD
bool operator>=(
const iterator& other)
const {
203 GAIA_ASSERT(m_ptr == other.m_ptr);
204 return m_idx >= other.m_idx;
206 GAIA_NODISCARD
bool operator<(
const iterator& other)
const {
207 GAIA_ASSERT(m_ptr == other.m_ptr);
208 return m_idx < other.m_idx;
210 GAIA_NODISCARD
bool operator<=(
const iterator& other)
const {
211 GAIA_ASSERT(m_ptr == other.m_ptr);
212 return m_idx <= other.m_idx;
219 template <
typename T, sarr_ext_soa_detail::
size_type N>
221 static_assert(mem::is_soa_layout_v<T>,
"sarr_ext_soa can be used only with soa types");
224 static_assert(
N > 0);
256 mem::raw_data_holder<T, allocated_bytes> m_data;
283 template <
typename InputIt>
285 const auto count = (
size_type)core::distance(first, last);
288 if constexpr (std::is_pointer_v<InputIt>) {
290 operator[](
i) = first[
i];
291 }
else if constexpr (std::is_same_v<typename InputIt::iterator_category, core::random_access_iterator_tag>) {
293 operator[](
i) = *(first[
i]);
296 for (
auto it = first;
it != last; ++
it)
297 operator[](++
i) = *
it;
312 GAIA_ASSERT(core::addressof(other) !=
this);
314 mem::move_elements<T, true>(m_data, other.m_data, other.size(), 0,
extent, other.extent);
331 GAIA_ASSERT(core::addressof(other) !=
this);
334 mem::copy_elements<T, true>(
345 GAIA_ASSERT(core::addressof(other) !=
this);
348 mem::move_elements<T, true>(
357 GAIA_CLANG_WARNING_PUSH()
359 GAIA_CLANG_WARNING_DISABLE("-
Wcast-align")
364 return GAIA_ACC((
pointer)&m_data[0]);
376 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
noexcept {
384 GAIA_NODISCARD
constexpr decltype(
auto)
operator[](
size_type pos)
const noexcept {
389 GAIA_CLANG_WARNING_POP()
394 GAIA_ASSERT(
size() <
N);
402 GAIA_ASSERT(
size() <
N);
411 template <
typename...
Args>
413 GAIA_ASSERT(
size() <
N);
420 GAIA_ASSERT(!
empty());
430 GAIA_ASSERT(
size() <
N);
451 GAIA_ASSERT(
size() <
N);
492 GAIA_ASSERT(first >=
data())
494 GAIA_ASSERT(last > first);
495 GAIA_ASSERT(last <= (
data() +
size()));
502 const auto cnt = (
size_type)(last - first);
546 if constexpr (std::is_copy_constructible_v<value_type>) {
552 operator[](
i) = value;
560 template <
typename Func>
567 if (func(
operator[](
idxSrc))) {
572 core::call_dtor(
ptr2);
577 core::call_dtor(ptr);
615 GAIA_ASSERT(!
empty());
622 GAIA_ASSERT(!
empty());
629 GAIA_ASSERT(!
empty());
630 return (
operator[])(m_cnt - 1);
636 GAIA_ASSERT(!
empty());
716 if (m_cnt != other.m_cnt)
720 if (!(
operator[](
i) == other[
i]))
735 template <
size_t Item>
744 template <
size_t Item>
747 std::span<const uint8_t>{GAIA_ACC((
const uint8_t*)&m_data[0]),
extent});
753 template <
typename T, uint32_t N, uint32_t... I>
754 constexpr sarr_ext_soa<std::remove_cv_t<T>, N> to_sarray_impl(T (&a)[N], std::index_sequence<I...> ) {
765 template <
typename T, u
int32_t N>
766 constexpr sarr_ext_soa<std::remove_cv_t<T>, N> to_sarray(T (&a)[N]) {
767 return detail::to_sarray_impl(a, std::make_index_sequence<N>{});
776 template <
typename T, u
int32_t N>
777 struct tuple_size<gaia::cnt::sarr_ext_soa<T, N>>: std::integral_constant<uint32_t, N> {};
779 template <
size_t I,
typename T, u
int32_t N>
780 struct tuple_element<I, gaia::cnt::sarr_ext_soa<T, N>> {
Array with variable size of elements of type.
Definition darray_impl.h:27
darr_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition darray_impl.h:44
GAIA_NODISCARD decltype(auto) operator[](size_type pos) noexcept
Accesses an element without bounds checking in optimized builds.
Definition darray_impl.h:206
core::random_access_iterator_tag iterator_category
Iterator category exposed by the container.
Definition darray_impl.h:51
GAIA_NODISCARD auto begin() noexcept
Returns an iterator to the first element.
Definition darray_impl.h:556
GAIA_NODISCARD bool operator==(const darr &other) const noexcept
Compares two containers element by element.
Definition darray_impl.h:629
T value_type
Element type stored by the container.
Definition darray_impl.h:30
pointer iterator
Mutable random-access iterator type.
Definition darray_impl.h:47
darr_detail::difference_type difference_type
Type used for iterator differences.
Definition darray_impl.h:42
GAIA_NODISCARD constexpr bool operator!=(const darr &other) const noexcept
Checks whether two containers differ.
Definition darray_impl.h:642
GAIA_NODISCARD auto end() noexcept
Returns an iterator one past the last element.
Definition darray_impl.h:592
Array of elements of type.
Definition sarray_ext_soa_impl.h:220
sarr_ext_soa_detail::difference_type difference_type
Type used for iterator differences.
Definition sarray_ext_soa_impl.h:239
constexpr void resize(size_type count) noexcept
Changes the number of elements.
Definition sarray_ext_soa_impl.h:533
iterator insert(iterator pos, const T &arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_soa_impl.h:429
auto view() const noexcept
Returns a read-only view of one structure-of-arrays member.
Definition sarray_ext_soa_impl.h:745
sarr_ext_soa_detail::size_type size_type
Unsigned type used for sizes and indices.
Definition sarray_ext_soa_impl.h:241
iterator erase(iterator first, iterator last) noexcept
Removes the elements in the range [first, last)
Definition sarray_ext_soa_impl.h:491
GAIA_NODISCARD constexpr bool empty() const noexcept
Checks whether the container has no elements.
Definition sarray_ext_soa_impl.h:596
iterator erase_at(size_type pos) noexcept
Definition sarray_ext_soa_impl.h:513
sarr_ext_soa_iterator< T > iterator
Mutable random-access iterator type.
Definition sarray_ext_soa_impl.h:244
GAIA_NODISCARD constexpr auto end() noexcept
Returns an iterator one past the last element.
Definition sarray_ext_soa_impl.h:678
GAIA_NODISCARD constexpr auto begin() const noexcept
Returns an iterator to the first element.
Definition sarray_ext_soa_impl.h:648
constexpr sarr_ext_soa(std::initializer_list< T > il)
Constructs a container from an initializer list.
Definition sarray_ext_soa_impl.h:303
GAIA_NODISCARD constexpr auto crend() const noexcept
Returns the read-only reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:708
constexpr sarr_ext_soa(sarr_ext_soa &&other) noexcept
Move-constructs a container.
Definition sarray_ext_soa_impl.h:311
auto view_mut() noexcept
Returns a mutable view of one structure-of-arrays member.
Definition sarray_ext_soa_impl.h:736
GAIA_NODISCARD constexpr auto cbegin() const noexcept
Returns a read-only iterator to the first element.
Definition sarray_ext_soa_impl.h:654
GAIA_NODISCARD constexpr decltype(auto) front() const noexcept
Accesses the first element.
Definition sarray_ext_soa_impl.h:621
static constexpr size_type extent
Fixed capacity of the container.
Definition sarray_ext_soa_impl.h:251
static constexpr uint32_t allocated_bytes
Number of bytes reserved by the inline storage.
Definition sarray_ext_soa_impl.h:253
constexpr void push_back(T &&arg) noexcept
Appends an element.
Definition sarray_ext_soa_impl.h:401
const_sarr_ext_soa_iterator< T > const_iterator
Read-only random-access iterator type.
Definition sarray_ext_soa_impl.h:246
GAIA_NODISCARD constexpr decltype(auto) front() noexcept
Accesses the first element.
Definition sarray_ext_soa_impl.h:614
constexpr iterator erase(iterator pos) noexcept
Removes the element at pos.
Definition sarray_ext_soa_impl.h:470
GAIA_NODISCARD constexpr bool operator!=(const sarr_ext_soa &other) const noexcept
Checks whether two containers differ.
Definition sarray_ext_soa_impl.h:728
GAIA_NODISCARD constexpr auto rbegin() noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:660
auto retain(Func &&func) noexcept
Removes all elements that fail the predicate.
Definition sarray_ext_soa_impl.h:561
constexpr void clear() noexcept
Removes all elements.
Definition sarray_ext_soa_impl.h:527
GAIA_NODISCARD constexpr decltype(auto) back() const noexcept
Accesses the last element.
Definition sarray_ext_soa_impl.h:635
GAIA_NODISCARD constexpr size_type max_size() const noexcept
Returns the maximum number of elements supported by this container.
Definition sarray_ext_soa_impl.h:608
GAIA_NODISCARD constexpr decltype(auto) back() noexcept
Accesses the last element.
Definition sarray_ext_soa_impl.h:628
constexpr decltype(auto) emplace_back(Args &&... args) noexcept
Constructs and appends an element.
Definition sarray_ext_soa_impl.h:412
GAIA_NODISCARD constexpr auto rend() noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:696
GAIA_NODISCARD constexpr auto cend() const noexcept
Returns a read-only iterator one past the last element.
Definition sarray_ext_soa_impl.h:690
constexpr sarr_ext_soa(InputIt first, InputIt last) noexcept
Constructs a container from an iterator range.
Definition sarray_ext_soa_impl.h:284
GAIA_NODISCARD constexpr size_type size() const noexcept
Returns the number of elements.
Definition sarray_ext_soa_impl.h:590
GAIA_NODISCARD constexpr auto crbegin() const noexcept
Returns a read-only reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:672
GAIA_NODISCARD constexpr const_pointer data() const noexcept
Returns a pointer to the element storage.
Definition sarray_ext_soa_impl.h:369
constexpr void pop_back() noexcept
Removes the last element.
Definition sarray_ext_soa_impl.h:419
GAIA_NODISCARD constexpr decltype(auto) operator[](size_type pos) noexcept
Accesses an element without bounds checking in optimized builds.
Definition sarray_ext_soa_impl.h:376
GAIA_NODISCARD constexpr auto begin() noexcept
Returns an iterator to the first element.
Definition sarray_ext_soa_impl.h:642
constexpr sarr_ext_soa(size_type count, const_reference value) noexcept
Constructs a container with copies of a value.
Definition sarray_ext_soa_impl.h:269
GAIA_NODISCARD constexpr auto end() const noexcept
Returns an iterator one past the last element.
Definition sarray_ext_soa_impl.h:684
GAIA_NODISCARD constexpr auto rend() const noexcept
Returns the reverse traversal sentinel preceding the first element.
Definition sarray_ext_soa_impl.h:702
constexpr sarr_ext_soa & operator=(const sarr_ext_soa &other)
Copy-assigns the container.
Definition sarray_ext_soa_impl.h:330
constexpr sarr_ext_soa & operator=(sarr_ext_soa &&other) noexcept
Move-assigns the container.
Definition sarray_ext_soa_impl.h:344
constexpr void resize(size_type count, const_reference value) noexcept
Changes the size and initializes new elements from a value.
Definition sarray_ext_soa_impl.h:542
GAIA_NODISCARD constexpr auto rbegin() const noexcept
Returns a reverse traversal iterator to the last element.
Definition sarray_ext_soa_impl.h:666
GAIA_NODISCARD constexpr pointer data() noexcept
Returns a pointer to the element storage.
Definition sarray_ext_soa_impl.h:363
constexpr sarr_ext_soa(const sarr_ext_soa &other)
Copy-constructs a container.
Definition sarray_ext_soa_impl.h:307
sarr_ext_soa & operator=(std::initializer_list< T > il)
Replaces the elements from an initializer list.
Definition sarray_ext_soa_impl.h:322
iterator insert(iterator pos, T &&arg) noexcept
Insert the element to the position given by iterator pos.
Definition sarray_ext_soa_impl.h:450
GAIA_NODISCARD constexpr size_type capacity() const noexcept
Returns the number of elements that fit without reallocation.
Definition sarray_ext_soa_impl.h:602
constexpr sarr_ext_soa(size_type count) noexcept
Constructs a container with the requested number of value-initialized elements.
Definition sarray_ext_soa_impl.h:275
constexpr void push_back(const T &arg) noexcept
Appends an element.
Definition sarray_ext_soa_impl.h:393
GAIA_NODISCARD constexpr bool operator==(const sarr_ext_soa &other) const noexcept
Compares two containers element by element.
Definition sarray_ext_soa_impl.h:715
View policy for accessing and storing data in the SoA way. Good for SIMD processing.
Definition data_layout_policy.h:402
GAIA_NODISCARD static constexpr ValueType get(std::span< const uint8_t > s, size_t idx) noexcept
Reconstructs a value from its SoA fields.
Definition data_layout_policy.h:530
uint8_t * TargetCastType
Pointer type used to address SoA storage.
Definition data_layout_policy.h:408
GAIA_NODISCARD static constexpr uint32_t get_min_byte_size(uintptr_t addr, size_t cnt) noexcept
Calculates the bytes required for an SoA value range.
Definition data_layout_policy.h:431
GAIA_NODISCARD static constexpr auto set(std::span< uint8_t > s, size_t idx) noexcept
Returns a mutable proxy for one complete value.
Definition data_layout_policy.h:582
Storage policy for a selected layout and item type.
Definition data_layout_policy.h:123