8#ifndef MAP_VECTOR_STD_HPP_
9#define MAP_VECTOR_STD_HPP_
11#include "se_vector.hpp"
12#include "map_vector_std_ptr.hpp"
14#define OBJECT_ADD false
15#define VECTOR_ADD true
18template<
bool objv,
typename vect_dst>
36 template <
typename S,
typename M,
typename gp,
unsigned int impl,
unsigned int ...args>
37 inline static void add(
const vector<S,M,memory_traits_lin,gp,impl> & v_src, vect_dst & v_dst)
40 for (
size_t i = 0 ; i < v_src.size() ; i++)
46 v_dst.get(v_dst.size()-1) = v_src.get(i);
52template<
typename vect_dst>
70 template <
typename S,
typename M,
typename gp,
unsigned int impl,
unsigned int ...args>
inline static void add(
const vector<S,M,memory_traits_lin,gp,impl> & v_src, vect_dst & v_dst)
76 v_dst.get(v_dst.size()-1) = v_src;
92template<
typename T,
typename grow_p>
118 typedef void base_to_copy;
123 template<
typename Tobj>
130#include "vector_std_pack_unpack.ipp"
162 base.shrink_to_fit();
174 inline void add(
const T & v)
176 if (std::is_same<grow_p,openfpm::grow_policy_identity>::value ==
true)
179 base.reserve(base.size()+1);
196 if (std::is_same<grow_p,openfpm::grow_policy_identity>::value ==
true)
199 base.reserve(base.size()+1);
202 base.emplace_back(v);
210 base.emplace_back(T());
220 if (std::is_same<grow_p,openfpm::grow_policy_identity>::value ==
true)
223 base.reserve(base.size() + eles.
size());
226 size_t start = base.size();
227 base.resize(base.size() + eles.
size());
230 std::copy(eles.begin(),eles.end(),base.begin()+start);
242 template<
typename S>
inline void add(
const S & v)
256 template<
typename S>
inline void add(
const S && v)
258 if (std::is_same<grow_p,openfpm::grow_policy_identity>::value ==
true)
261 base.reserve(base.size() + 1);
281 template <
typename S,
285 template <
typename>
class layout_base,
286 unsigned int ...args>
287 void add_prp(
const vector<S,M,layout_base,gp,impl> & v)
306 template <
typename S,
310 template <
typename>
class layout_base,
311 unsigned int ...args>
330 template <
typename S,
334 template <
typename>
class layout_base,
335 unsigned int ...args>
347 void erase(
typename std::vector<T>::iterator start,
typename std::vector<T>::iterator end)
349 base.erase(start,end);
360 vector_overflow(key);
362 base.erase(base.begin() + key);
376 if (keys.size() <= start )
379 size_t a_key = start;
380 size_t d_k = keys.get(a_key);
381 size_t s_k = keys.get(a_key) + 1;
387 while (a_key+1 < keys.size() && s_k == keys.get(a_key+1))
390 s_k = keys.get(a_key) + 1;
397 base[d_k] = base[s_k];
404 base.resize(base.size() - (keys.size() - start));
412 inline auto begin() ->
decltype(base.begin())
422 inline auto end() ->
decltype(base.begin())
432 inline auto begin() const -> const decltype(base.begin())
442 inline auto end() const -> const decltype(base.begin())
455 if (base.size() == 0)
456 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
458 return base[base.size()-1];
469 if (base.size() == 0)
470 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
472 return base[base.size()-1];
502 auto it = std::unique(base.begin(),base.end());
503 base.resize( std::distance(base.begin(),it) );
513 std::sort(base.begin(), base.end());
525 template <
unsigned int p>
inline T&
get(
size_t id)
529 {std::cerr <<
"Error the property does not exist" <<
"\n";}
546 template <
unsigned int p>
inline const T&
get(
size_t id)
const
550 {std::cerr <<
"Error the property does not exist" <<
"\n";}
580 inline const T &
get(
size_t id)
const
596 inline void fill(
unsigned char fl)
598 memset(&base[0],fl,base.size() *
sizeof(T));
619 :base(sz),err_code(0)
624 vector(
const vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> & v) noexcept
635 vector(
const std::initializer_list<T> & v)
641 vector(vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> && v) noexcept
648 template<
class InputIt >
651 while(first != last) {
689 vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(
const vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
701 template<
typename Mem,
typename gp> vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(
const vector<T,Mem,memory_traits_lin,gp,STD_VECTOR> & v)
705 vector<T,Mem,memory_traits_lin,gp,STD_VECTOR> >::copy(*
this,v);
717 vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> && v)
731 template<
typename Mem,
typename gp> vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> &
operator=(vector<T,Mem,memory_traits_lin,gp,STD_VECTOR> && v)
745 bool operator!=(
const vector<T, HeapMemory, memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
const
747 return base != v.base;
757 bool operator==(
const vector<T, HeapMemory, memory_traits_lin,grow_policy_double,STD_VECTOR> & v)
const
759 return base == v.base;
769 return vector_key_iterator(base.size());
781 return vector_key_iterator(k);
794 template<
int ... prp>
inline size_t packMem(
size_t n,
size_t e)
const
801 return cm.packMemory(*
this,n,0);
859 template<
unsigned int ... prp>
void deviceToHost(
size_t start,
size_t stop)
866 template<
unsigned int ... prp>
void hostToDevice(
size_t start,
size_t stop)
906 if (v1 >= base.size())
908 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " << v1 <<
"\n";\
909 size_t * err_code_pointer = (
size_t *)&this->err_code;\
910 *err_code_pointer = 2001;\
912 ACTION_ON_ERROR(VECTOR_ERROR_OBJECT);\
931:
private vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR>
933 typedef vector<T,HeapMemory,memory_traits_lin,grow_policy_double,STD_VECTOR> base_type;
957 return base_type::size();
967 if (sz <= base_type::size())
973 base_type::resize(sz);
1003 base_type::resize(sz);
1016 return base_type::get(
id);
1028 return base_type::get(
id);
1040 return base_type::get(
size()-1);
1048 void swap(openfpm::vector_fr<T> & v)
1050 size_t v_size_tmp = v.v_size;
This class allocate, and destroy CPU memory.
Implementation of 1-D std::vector like structure.
vector(vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v) noexcept
Constructor from another vector.
T & last()
Get the last element.
const T & get(size_t id) const
Get an element of the vector.
T & get(size_t id)
Get an element of the vector.
vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(vector< T, Mem, memory_traits_lin, gp, STD_VECTOR > &&v)
Operator= copy the vector into another.
void add(const S &v)
It insert a new object on the vector, eventually it reallocate the object.
void vector_overflow(size_t v1) const
check that the id does not overflow the buffer
auto end() -> decltype(base.begin())
Return an std compatible iterator to the last element.
const T & last() const
Get the last element.
void fill(unsigned char fl)
it fill all the memory of fl patterns
vector(const vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) noexcept
Constructor from another vector.
void sort()
It sort the vector.
auto begin() -> decltype(base.begin())
Return an std compatible iterator to the first element.
void hostToDevice()
Do nothing.
const void * getPointer() const
Return the pointer to the chunk of memory.
bool operator!=(const vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are equal.
void clear()
Remove all the element from the vector.
void * getPointer()
Return the pointer to the chunk of memory.
void add_prp_device(const vector< S, M, layout_base, gp, impl > &v)
It add the element of a source vector to this vector.
vector_key_iterator getIteratorTo(size_t k) const
Get iterator until a specified element.
void hostToDevice(size_t start, size_t stop)
Do nothing.
void add()
Add an empty object (it call the default constructor () ) at the end of the vector.
size_t packMem(size_t n, size_t e) const
Calculate the memory size required to allocate n elements.
vector_key_iterator getIterator() const
Get an iterator over all the elements of the vector.
vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v)
Operator= copy the vector into another.
void swap(openfpm::vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &&v)
void remove(size_t key)
Remove one entry from the vector.
size_t size() const
return the size of the vector
std::vector< T > base
1-D static grid
grow_policy_double grow_policy
growing policy of this vector
size_t getLastError()
Return the last error.
T value_type
Type of the value the vector is storing.
void reserve(size_t ns)
reserve a memory space in advance to avoid reallocation
void deviceToHost(size_t start, size_t stop)
Do nothing.
void remove(openfpm::vector< size_t > &keys, size_t start=0)
Remove several entries from the vector.
vector() noexcept
Constructor, vector of size 0.
T & get(size_t id)
Get an element of the vector.
int yes_i_am_vector
it define that it is a vector
void add(T &&v)
It insert a new object on the vector, eventually it reallocate the grid.
bool operator==(const vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are not equal.
vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(const vector< T, Mem, memory_traits_lin, gp, STD_VECTOR > &v)
Operator= copy the vector into another.
void add(const openfpm::vector< T, Mem, lb, gp > &eles)
add elements to the vector
vector(InputIt first, InputIt last)
Constructor from iterators.
vector(const std::initializer_list< T > &v)
Initializer from constructor.
void add_prp(const vector< S, M, layout_base, gp, impl > &v)
It add the element of a source vector to this vector.
void swap(std::vector< T > &&v)
swap the memory between the two vector
static size_t calculateMemDummy(size_t n, size_t e)
Calculate the memory size required to allocate n elements.
vector(size_t sz) noexcept
Constructor, vector of size sz.
openfpm::vector< T > duplicate() const
Duplicate the vector.
const T & get(size_t id) const
Get an element of the vector.
void shrink_to_fit()
Fit the memory to the size of the vector.
void unique()
It eliminate double entries.
void add(const S &&v)
It insert a new object on the vector, eventually it reallocate the grid.
void deviceToHost()
Do nothing.
void swap(openfpm::vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &v)
~vector() noexcept
destructor
static bool noPointers()
This class has pointer inside.
auto begin() const -> const decltype(base.begin())
Return an std compatible iterator to the first element.
static size_t calculateNMem(size_t n)
How many allocation are required to create n-elements.
vector_key_iterator iterator_key
iterator for the vector
void add_prp(const T &v)
It add the element it is equivalent to add.
void erase(typename std::vector< T >::iterator start, typename std::vector< T >::iterator end)
Erase the elements from start to end.
void add(const T &v)
It insert a new object on the vector, eventually it reallocate the grid.
auto end() const -> const decltype(base.begin())
Return an std compatible iterator to the last element.
vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > & operator=(const vector< T, HeapMemory, memory_traits_lin, grow_policy_double, STD_VECTOR > &v)
Operator= copy the vector into another.
Implementation of 1-D std::vector like structure.
void add()
Add another element.
T & get(size_t id)
Get an element of the vector.
size_t size_base()
return the base size of the vector
T & operator[](size_t id)
Get an element of the vector.
void clear()
Eliminate all elements.
void swap(openfpm::vector_fr< T > &v)
size_t size()
return the size of the vector
T & last()
Get an element of the vector.
void resize_base(size_t sz)
resize the base vector (this kill the objects)
void resize(size_t sz)
resize the vector retaining the objects
size_t v_size
size of the vector
static void add(const vector< S, M, memory_traits_lin, gp, impl > &v_src, vect_dst &v_dst)
It add the element of a source vector to a destination vector.
struct to merge two vectors
static void add(const vector< S, M, memory_traits_lin, gp, impl > &v_src, vect_dst &v_dst)
It add the element of a source vector to this vector.
Transform the boost::fusion::vector into memory specification (memory_traits)