3#include <AMReX_Config.H>
25template <
class T,
class Allocator=std::allocator<T> >
28 public std::vector<T, Allocator>
32 using std::vector<T, Allocator>::vector;
33 using typename std::vector<T, Allocator>::size_type;
38 "Out of bound error, index: " + std::to_string(i) +
" size: " + std::to_string(
size()));
39 return this->std::vector<T, Allocator>::operator[](i);
45 "Out of bound error, index: " + std::to_string(i) +
" size: " + std::to_string(
size()));
46 return this->std::vector<T, Allocator>::operator[](i);
50 [[nodiscard]] T*
dataPtr () noexcept {
return this->data(); }
52 [[nodiscard]]
const T*
dataPtr () const noexcept {
return this->data(); }
54 [[nodiscard]]
Long size () const noexcept {
return static_cast<Long>(std::vector<T, Allocator>::size());}
64 template <
class T,
typename =
typename T::FABType>
69 for (
auto&
x : a) { r.push_back(&
x); }
73 template <
class T, std::
size_t N,
typename =
typename T::FABType>
78 for (
auto&
x : a) { r.push_back(&
x); }
87 for (
const auto&
x : a) { r.push_back(
x.get()); }
93 template <
class T,
typename =
typename T::FABType>
98 for (
const auto&
x : a) { r.push_back(&
x); }
102 template <
class T, std::
size_t N,
typename =
typename T::FABType>
107 for (
auto&
x : a) { r.push_back(&
x); }
116 for (
const auto&
x : a) { r.push_back(
x.get()); }
120 template <
class T,
typename =
typename T::FABType>
123 return {a.begin(), a.end()};
141 [[nodiscard]] Vector<std::array<T*,AMREX_SPACEDIM> >
151 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
161 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
171 requires (FabArrayType<T> || BaseFabType<T>)
172 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
182 requires (FabArrayType<T> || BaseFabType<T>)
183 [[nodiscard]] Vector<std::array<T*, AMREX_SPACEDIM> >
198 std::for_each(a.begin(), a.end(), [](T*& p) { p = nullptr; });
204 std::for_each(a.begin(), a.end(), [](std::unique_ptr<T>& p) { p.reset(); });
211 std::sort(vec.begin(), vec.end());
212 auto it = std::unique(vec.begin(), vec.end());
213 vec.erase(it, vec.end());
218 template <
class T,
class H>
219 std::size_t removeDupDoit (Vector<T>& vec, std::size_t start, std::size_t stop)
221 std::size_t N = stop-start;
222 if (N < 2) {
return stop; }
224 T*
const data = vec.data() + start;
225 T
const sentinel = data[0];
227 for (std::size_t i = 1; i < N; ) {
228 if (data[i] == sentinel) {
233 std::size_t
const hash = hasher(data[i]) % N;
239 if (data[i] == data[hash]) {
245 if (data[hash] == sentinel) {
246 std::swap(data[hash], data[i]);
253 std::size_t
const hashhash = hasher(data[hash]) % N;
254 if (hashhash != hash) {
255 std::swap(data[i], data[hash]);
275 std::size_t swapPos = 0;
276 for (std::size_t i = 0; i < N; ++i) {
278 if (data[i] != sentinel && i == hasher(data[i]) % N) {
279 std::swap(data[i], data[swapPos++]);
285 std::size_t sentinelPos = N;
286 for (std::size_t i = swapPos; i < sentinelPos; ) {
288 if(data[i] == sentinel) {
289 std::swap(data[i], data[--sentinelPos]);
296 return detail::removeDupDoit<T,H>(vec, start+swapPos, start+sentinelPos+1);
301 template <
class T,
class H>
304 std::size_t pos = detail::removeDupDoit<T,H>(vec, 0, vec.
size());
305 vec.erase(vec.begin()+pos, vec.end());
#define AMREX_ASSERT_WITH_MESSAGE(EX, MSG)
Definition AMReX_BLassert.H:37
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition AMReX_Vector.H:29
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:50
Long size() const noexcept
Definition AMReX_Vector.H:54
const T * dataPtr() const noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:52
T & operator[](size_type i)
Definition AMReX_Vector.H:35
amrex_long Long
Definition AMReX_INT.H:30
std::array< T, N > Array
Definition AMReX_Array.H:26
Definition AMReX_Amr.cpp:50
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Create an array of const-qualified pointers from an array of objects.
Definition AMReX_Array.H:1047
Vector< std::array< T const *, 3 > > GetVecOfArrOfPtrsConst(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:152
Vector< const T * > GetVecOfConstPtrs(const Vector< T > &a)
Definition AMReX_Vector.H:94
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Create an array of pointers from an array of objects.
Definition AMReX_Array.H:1001
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition AMReX_Vector.H:65
void FillNull(Vector< T * > &a)
Definition AMReX_Vector.H:196
Vector< Vector< T * > > GetVecOfVecOfPtrs(const Vector< Vector< std::unique_ptr< T > > > &a)
Definition AMReX_Vector.H:129
Vector< std::array< T const *, 3 > > GetVecOfArrOfConstPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:162
Vector< std::array< T *, 3 > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:142
void RemoveDuplicates(Vector< T > &vec)
Definition AMReX_Vector.H:210