1 #ifndef AMREX_VECTOR_H_
2 #define AMREX_VECTOR_H_
3 #include <AMReX_Config.H>
23 template <
class T,
class Allocator=std::allocator<T> >
26 public std::vector<T, Allocator>
30 using std::vector<T, Allocator>::vector;
31 using typename std::vector<T, Allocator>::size_type;
36 return this->std::vector<T, Allocator>::operator[](i);
39 [[nodiscard]]
const T&
operator[] (size_type i)
const noexcept
42 return this->std::vector<T, Allocator>::operator[](i);
46 [[nodiscard]] T*
dataPtr () noexcept {
return this->data(); }
48 [[nodiscard]]
const T*
dataPtr () const noexcept {
return this->data(); }
60 template <
class T,
typename =
typename T::FABType>
65 for (
auto&
x : a) {
r.push_back(&
x); }
74 for (
const auto&
x : a) {
r.push_back(
x.get()); }
80 template <
class T,
typename =
typename T::FABType>
85 for (
const auto&
x : a) {
r.push_back(&
x); }
94 for (
const auto&
x : a) {
r.push_back(
x.get()); }
98 template <
class T,
typename =
typename T::FABType>
101 return {a.begin(), a.end()};
117 #ifdef AMREX_SPACEDIM
119 [[nodiscard]] Vector<std::array<T*,AMREX_SPACEDIM> >
129 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
139 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
148 template <class T, std::enable_if_t<IsFabArray<T>::value ||
151 [[nodiscard]] Vector<std::array<T const*,AMREX_SPACEDIM> >
160 template <class T, std::enable_if_t<IsFabArray<T>::value ||
163 [[nodiscard]] Vector<std::array<T*, AMREX_SPACEDIM> >
178 std::for_each(a.begin(), a.end(), [](T*& p) { p = nullptr; });
184 std::for_each(a.begin(), a.end(), [](std::unique_ptr<T>& p) { p.reset(); });
191 std::sort(vec.begin(), vec.end());
192 auto it = std::unique(vec.begin(), vec.end());
193 vec.erase(it, vec.end());
197 template <
class T,
class H>
200 std::size_t N = stop-start;
201 if (N < 2) {
return stop; }
203 T*
const data = vec.data() + start;
204 T
const sentinel = data[0];
206 for (std::size_t i = 1; i < N; ) {
207 if (data[i] == sentinel) {
212 std::size_t
const hash = hasher(data[i]) % N;
218 if (data[i] == data[hash]) {
224 if (data[hash] == sentinel) {
232 std::size_t
const hashhash = hasher(data[hash]) % N;
233 if (hashhash != hash) {
254 std::size_t swapPos = 0;
255 for (std::size_t i = 0; i < N; ++i) {
257 if (data[i] != sentinel && i == hasher(data[i]) % N) {
264 std::size_t sentinelPos = N;
265 for (std::size_t i = swapPos; i < sentinelPos; ) {
267 if(data[i] == sentinel) {
275 return detail::removeDupDoit<T,H>(vec, start+swapPos, start+sentinelPos+1);
279 template <
class T,
class H>
282 std::size_t pos = detail::removeDupDoit<T,H>(vec, 0, vec.
size());
283 vec.erase(vec.begin()+pos, vec.end());
#define BL_ASSERT(EX)
Definition: AMReX_BLassert.H:39
This class is a thin wrapper around std::vector. Unlike vector, Vector::operator[] provides bound che...
Definition: AMReX_Vector.H:27
T & operator[](size_type i) noexcept
Definition: AMReX_Vector.H:33
const T * dataPtr() const noexcept
get access to the underlying data pointer
Definition: AMReX_Vector.H:48
Long size() const noexcept
Definition: AMReX_Vector.H:50
T * dataPtr() noexcept
get access to the underlying data pointer
Definition: AMReX_Vector.H:46
AMREX_GPU_HOST_DEVICE Long size(T const &b) noexcept
integer version
Definition: AMReX_GpuRange.H:26
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void swap(T &a, T &b) noexcept
Definition: AMReX_algoim_K.H:113
std::size_t removeDupDoit(Vector< T > &vec, std::size_t start, std::size_t stop)
Definition: AMReX_Vector.H:198
Definition: AMReX_Amr.cpp:49
std::array< T const *, AMREX_SPACEDIM > GetArrOfConstPtrs(const std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition: AMReX_Array.H:864
Vector< const T * > GetVecOfConstPtrs(const Vector< T > &a)
Definition: AMReX_Vector.H:81
std::array< T *, AMREX_SPACEDIM > GetArrOfPtrs(std::array< T, AMREX_SPACEDIM > &a) noexcept
Definition: AMReX_Array.H:852
Vector< T * > GetVecOfPtrs(Vector< T > &a)
Definition: AMReX_Vector.H:61
Vector< Vector< T * > > GetVecOfVecOfPtrs(const Vector< Vector< std::unique_ptr< T > > > &a)
Definition: AMReX_Vector.H:107
void FillNull(Vector< T * > &a)
Definition: AMReX_Vector.H:176
Vector< std::array< T *, AMREX_SPACEDIM > > GetVecOfArrOfPtrs(const Vector< std::array< std::unique_ptr< T >, AMREX_SPACEDIM > > &a)
Definition: AMReX_Vector.H:120
Vector< std::array< T const *, AMREX_SPACEDIM > > GetVecOfArrOfConstPtrs(const Vector< std::array< std::unique_ptr< T >, AMREX_SPACEDIM > > &a)
Definition: AMReX_Vector.H:140
void RemoveDuplicates(Vector< T > &vec)
Definition: AMReX_Vector.H:190
Vector< std::array< T const *, AMREX_SPACEDIM > > GetVecOfArrOfPtrsConst(const Vector< std::array< std::unique_ptr< T >, AMREX_SPACEDIM > > &a)
Definition: AMReX_Vector.H:130
Definition: AMReX_FabArrayCommI.H:896