3#include <AMReX_Config.H>
24template <
class T,
class Allocator=std::allocator<T> >
27 public std::vector<T, Allocator>
31 using std::vector<T, Allocator>::vector;
32 using typename std::vector<T, Allocator>::size_type;
37 "Out of bound error, index: " + std::to_string(i) +
" size: " + std::to_string(
size()));
38 return this->std::vector<T, Allocator>::operator[](i);
41 [[nodiscard]]
const T&
operator[] (size_type i)
const noexcept
44 "Out of bound error, index: " + std::to_string(i) +
" size: " + std::to_string(
size()));
45 return this->std::vector<T, Allocator>::operator[](i);
49 [[nodiscard]] T*
dataPtr () noexcept {
return this->data(); }
51 [[nodiscard]]
const T*
dataPtr () const noexcept {
return this->data(); }
53 [[nodiscard]]
Long size () const noexcept {
return static_cast<Long>(std::vector<T, Allocator>::size());}
63 template <
class T,
typename =
typename T::FABType>
68 for (
auto&
x : a) { r.push_back(&
x); }
72 template <
class T, std::
size_t N,
typename =
typename T::FABType>
77 for (
auto&
x : a) { r.push_back(&
x); }
86 for (
const auto&
x : a) { r.push_back(
x.get()); }
92 template <
class T,
typename =
typename T::FABType>
97 for (
const auto&
x : a) { r.push_back(&
x); }
101 template <
class T, std::
size_t N,
typename =
typename T::FABType>
106 for (
auto&
x : a) { r.push_back(&
x); }
115 for (
const auto&
x : a) { r.push_back(
x.get()); }
119 template <
class T,
typename =
typename T::FABType>
122 return {a.begin(), a.end()};
140 [[nodiscard]] Vector<std::array<T*,AMREX_SPACEDIM> >
150 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
160 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
169 template <class T, std::enable_if_t<IsFabArray<T>::value ||
172 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
181 template <class T, std::enable_if_t<IsFabArray<T>::value ||
184 [[nodiscard]] Vector<std::array<T*, AMREX_SPACEDIM> >
199 std::for_each(a.begin(), a.end(), [](T*& p) { p = nullptr; });
205 std::for_each(a.begin(), a.end(), [](std::unique_ptr<T>& p) { p.reset(); });
212 std::sort(vec.begin(), vec.end());
213 auto it = std::unique(vec.begin(), vec.end());
214 vec.erase(it, vec.end());
219 template <
class T,
class H>
220 std::size_t removeDupDoit (Vector<T>& vec, std::size_t start, std::size_t stop)
222 std::size_t N = stop-start;
223 if (N < 2) {
return stop; }
225 T*
const data = vec.data() + start;
226 T
const sentinel = data[0];
228 for (std::size_t i = 1; i < N; ) {
229 if (data[i] == sentinel) {
234 std::size_t
const hash = hasher(data[i]) % N;
240 if (data[i] == data[hash]) {
246 if (data[hash] == sentinel) {
247 std::swap(data[hash], data[i]);
254 std::size_t
const hashhash = hasher(data[hash]) % N;
255 if (hashhash != hash) {
256 std::swap(data[i], data[hash]);
276 std::size_t swapPos = 0;
277 for (std::size_t i = 0; i < N; ++i) {
279 if (data[i] != sentinel && i == hasher(data[i]) % N) {
280 std::swap(data[i], data[swapPos++]);
286 std::size_t sentinelPos = N;
287 for (std::size_t i = swapPos; i < sentinelPos; ) {
289 if(data[i] == sentinel) {
290 std::swap(data[i], data[--sentinelPos]);
297 return detail::removeDupDoit<T,H>(vec, start+swapPos, start+sentinelPos+1);
302 template <
class T,
class H>
305 std::size_t pos = detail::removeDupDoit<T,H>(vec, 0, vec.
size());
306 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:28
T & operator[](size_type i) noexcept
Definition AMReX_Vector.H:34
T * dataPtr() noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:49
Long size() const noexcept
Definition AMReX_Vector.H:53
const T * dataPtr() const noexcept
get access to the underlying data pointer
Definition AMReX_Vector.H:51
amrex_long Long
Definition AMReX_INT.H:30
std::array< T, N > Array
Definition AMReX_Array.H:26
Definition AMReX_Amr.cpp:49
std::array< T const *, 3 > GetArrOfConstPtrs(const std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1017
Vector< std::array< T const *, 3 > > GetVecOfArrOfPtrsConst(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:151
Vector< const T * > GetVecOfConstPtrs(const Vector< T > &a)
Definition AMReX_Vector.H:93
std::array< T *, 3 > GetArrOfPtrs(std::array< T, 3 > &a) noexcept
Definition AMReX_Array.H:1005
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition AMReX_Vector.H:64
void FillNull(Vector< T * > &a)
Definition AMReX_Vector.H:197
Vector< Vector< T * > > GetVecOfVecOfPtrs(const Vector< Vector< std::unique_ptr< T > > > &a)
Definition AMReX_Vector.H:128
Vector< std::array< T const *, 3 > > GetVecOfArrOfConstPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:161
Vector< std::array< T *, 3 > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, 3 > > &a)
Definition AMReX_Vector.H:141
void RemoveDuplicates(Vector< T > &vec)
Definition AMReX_Vector.H:211