13 #include "util/common.hpp"
14 #include "memory/PtrMemory.hpp"
15 #include "util/object_util.hpp"
16 #include "Grid/util.hpp"
17 #include "Vector/util.hpp"
18 #include "Vector/map_vector_grow_p.hpp"
19 #include "memory/ExtPreAlloc.hpp"
20 #include "util/util_debug.hpp"
21 #include "util/Pack_stat.hpp"
22 #include "Grid/map_grid.hpp"
23 #include "memory/HeapMemory.hpp"
24 #include "vect_isel.hpp"
25 #include "util/object_s_di.hpp"
30 #include "util/Pack_stat.hpp"
31 #include "memory/ExtPreAlloc.hpp"
33 #include "Packer_Unpacker/Unpacker.hpp"
34 #include "Packer_Unpacker/Packer.hpp"
36 #include "Packer_Unpacker/Packer_util.hpp"
37 #include "Packer_Unpacker/has_pack_agg.hpp"
39 #include "map_vector_std_util.hpp"
40 #include "data_type/aggregate.hpp"
41 #include "vector_map_iterator.hpp"
60 template<
typename T,
typename Memory,
typename layout,
template<
typename>
class layout_base,
typename grow_p,
unsigned int impl>
72 std::cerr << __FILE__ <<
":" << __LINE__ <<
" Error stub vector created" << std::endl;
77 #include "map_vector_std.hpp"
78 #include "map_vector_std_ptr.hpp"
95 template<
typename T,
typename Memory,
typename layout,
template <
typename>
class layout_base,
typename grow_p>
96 class vector<T,Memory,layout,layout_base,grow_p,OPENFPM_NATIVE>
128 void check_overflow(
size_t id)
const
132 std::cerr <<
"Error " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " <<
id <<
"\n";
133 ACTION_ON_ERROR(VECTOR_ERROR_OBJECT);
158 #include "vector_pack_unpack.ipp"
186 if (sp > base.size())
221 if (slot > base.size())
223 size_t gr = grow_p::grow(base.size(),slot);
235 typedef size_t access_key;
250 if (v_size >= base.size())
254 non_zero_one(sz,2*base.size());
277 if (v_size >= base.size())
281 non_zero_one(sz,2*base.size());
308 if (v_size >= base.size())
312 non_zero_one(sz,2*base.size());
333 for (
size_t i = 0 ; i < v.
size() ; i++)
373 template <
template<
typename,
typename>
class op,
typename S,
typename M,
typename gp,
unsigned int ...args>
374 void merge_prp(
const vector<S,M,
typename layout_base<S>::type,layout_base,gp,OPENFPM_NATIVE> & v,
383 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error merge_prp: v.size()=" << v.
size() <<
" must be the same as o_part.size()" << opart.
size() << std::endl;
386 for (
size_t i = 0 ; i < v.
size() ; i++)
392 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" try to access element " << opart.get(i) <<
" but the vector has size " <<
size() << std::endl;
396 object_s_di_op<op,decltype(v.get(i)),decltype(
get(
size()-1)),OBJ_ENCAP,args...>(v.get(i),
get(opart.get(i)));
436 template <
template<
typename,
typename>
class op,
440 template <
typename>
class layout_base2,
441 unsigned int ...args>
442 void merge_prp_v(
const vector<S,M,
typename layout_base2<S>::type,layout_base2,gp,OPENFPM_NATIVE> & v,
451 std::cerr << __FILE__ <<
":" << __LINE__ <<
" error merge_prp: v.size()=" << v.
size() <<
" must be the same as o_part.size()" << opart.
size() << std::endl;
454 for (
size_t i = 0 ; i < v.
size() ; i++)
459 if (i >= opart.
size())
460 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" try to access element " << opart.template get<0>(i) <<
" but the vector has size " <<
size() << std::endl;
464 object_s_di_op<op,decltype(v.get(i)),decltype(
get(
size()-1)),OBJ_ENCAP,args...>(v.get(i),
get(opart.template get<0>(i)));
503 template <
template<
typename,
typename>
class op,
507 template <
typename>
class layout_base2,
508 unsigned int ...args>
509 void merge_prp_v(
const vector<S,M,
typename layout_base2<S>::type,layout_base2,gp,OPENFPM_NATIVE> & v,
515 for (
size_t i = 0 ; i < v.
size() ; i++)
520 if (start + i >= v_size)
521 std::cerr <<
"Error: " << __FILE__ <<
":" << __LINE__ <<
" try to access element " << start+i <<
" but the vector has size " <<
size() << std::endl;
525 object_s_di_op<op,decltype(v.get(0)),decltype(
get(0)),OBJ_ENCAP,args...>(v.get(i),
get(start+i));
543 template <
typename S,
547 template <
typename>
class layout_base2,
548 unsigned int ...args>
549 void add_prp(
const vector<S,M,
typename layout_base2<S>::type,layout_base2,gp,impl> & v)
554 for (
size_t i = 0 ; i < v.
size() ; i++)
561 object_s_di<decltype(v.get(i)),decltype(
get(
size()-1)),OBJ_ENCAP,args...>(v.get(i),
get(
size()-1));
577 long int d_k = (
long int)
size()-1;
578 long int s_k = (
long int)
size()-2;
581 while (s_k >= (
long int)key)
601 size_t s_k =
key + 1;
630 if (keys.size() <= start )
633 size_t a_key = start;
634 size_t d_k = keys.get(a_key);
635 size_t s_k = keys.get(a_key) + 1;
641 while (a_key+1 < keys.size() && s_k == keys.get(a_key+1))
644 s_k = keys.get(a_key) + 1;
658 v_size -= keys.size() - start;
672 template <
unsigned int p>
673 inline auto get(
size_t id)
const -> decltype(base.template get<p>(
grid_key_dx<1>(0)))
683 return base.template get<p>(
key);
705 return base.get_o(key);
717 inline auto get(
size_t id)
const ->
const decltype(base.get_o(
grid_key_dx<1>(
id)))
727 return base.get_o(key);
752 return base.get_o(key);
768 return base.get_o(key);
782 template <
unsigned int p>
793 return base.template get<p>(key);
809 return base.get_o(key);
834 dup.
base.swap(base.duplicate());
849 check_new(
this,8,VECTOR_EVENT,1);
863 check_new(
this,8,VECTOR_EVENT,1);
873 check_new(
this,8,VECTOR_EVENT,1);
883 check_new(
this,8,VECTOR_EVENT,1);
921 template <
typename encap_S,
unsigned int ...args>
void set_o(
size_t i,
const encap_S & obj)
928 object_s_di<encap_S,decltype(
get(i)),OBJ_ENCAP,args...>(obj,
get(i));
937 void set(
size_t id,
const T & obj)
964 base.set(
id,v.
base,src);
976 vector<T, Memory,layout,layout_base,grow_p,OPENFPM_NATIVE> &
operator=(
vector<T, Memory, layout, layout_base,grow_p,OPENFPM_NATIVE> && mv)
996 vector<T, Memory,layout,layout_base,grow_p,OPENFPM_NATIVE> &
operator=(
const vector<T, Memory, layout, layout_base ,grow_p,OPENFPM_NATIVE> & mv)
1002 size_t rsz[1] = {v_size};
1003 if (base.size() < v_size)
1007 for (
size_t i = 0 ; i < v_size ; i++ )
1010 base.set(key,mv.base,key);
1025 template<
typename Mem,
typename gp>
vector<T, Memory,layout,layout_base,grow_p,OPENFPM_NATIVE> &
operator=(
vector<T, Mem, layout, layout_base,gp,OPENFPM_NATIVE> && mv)
1028 check_valid(
this,8);
1045 template<
typename Mem,
typename gp>
vector<T, Memory,layout,layout_base,grow_p,OPENFPM_NATIVE> &
operator=(
const vector<T, Mem, layout, layout_base ,gp,OPENFPM_NATIVE> & mv)
1048 check_valid(
this,8);
1050 v_size = mv.getInternal_v_size();
1051 size_t rsz[1] = {v_size};
1055 for (
size_t i = 0 ; i < v_size ; i++ )
1058 base.set(key,mv.getInternal_base(),key);
1071 return !this->operator==(v);
1085 for (
size_t i = 0 ; i < v_size ; i++ )
1089 if (base.get_o(key) != v.
base.get_o(key))
1104 check_valid(
this,8);
1106 size_t sz_sp = v_size;
1123 check_valid(
this,8);
1125 size_t sz_sp = v_size;
1144 check_valid(
this,8);
1161 check_valid(
this,8);
1176 check_valid(
this,8);
1190 check_valid(
this,8);
1192 return base.packObjectSize();
1205 check_valid(
this,8);
1207 return base.packObject(mem);
1220 template<
int ... prp>
static inline size_t calculateMem(
size_t n,
size_t e)
1228 if (
sizeof...(prp) == 0)
1229 return grow_p::grow(0,n) *
sizeof(
typename T::type);
1231 typedef object<
typename object_creator<
typename T::type,prp...>::type> prp_object;
1233 return grow_p::grow(0,n) *
sizeof(prp_object);
1247 template<
int ... prp>
static inline size_t packMem(
size_t n,
size_t e)
1249 if (
sizeof...(prp) == 0)
1250 return n *
sizeof(
typename T::type);
1252 typedef object<
typename object_creator<
typename T::type,prp...>::type> prp_object;
1254 return n *
sizeof(prp_object);
1277 check_valid(
this,8);
1279 base.setMemory(mem);
1290 check_valid(
this,8);
1292 return base.getPointer();
1303 check_valid(
this,8);
1305 return base.getPointer();
1326 return check_whoami(
this,8);
It copy the properties from one object to another.
Implementation of 1-D std::vector like structure.
void clear()
Clear the vector.
void set(size_t id, const T &obj)
Set the object id to obj.
void merge_prp_v(const vector< S, M, typename layout_base2< S >::type, layout_base2, gp, OPENFPM_NATIVE > &v, size_t start)
It merge the elements of a source vector to this vector.
Transform the boost::fusion::vector into memory specification (memory_traits)
const grid_cpu< 1, T, Memory, layout > & getInternal_base() const
Internal function.
layout layout_type
Type of the encapsulation memory parameter.
Grow policy define how the vector should grow every time we exceed the size.
grid_key_dx is the key to access any element in the grid
size_t packObject(void *mem)
Pack the object into the given pointer.
int yes_i_am_vector
it define that it is a vector
size_t size() const
Return the size of the vector.
void swap(openfpm::vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &&v)
Swap the memory with another vector.
T value_type
Type of the value the vector is storing.
void * getPointer()
Return the pointer that store the data.
vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > duplicate() const
It duplicate the vector.
vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > & operator=(const vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &mv)
Assignment operator.
void resize(size_t slot)
Resize the vector.
void insert(size_t key)
Insert an entry in the vector.
void reserve(size_t sp)
Reserve slots in the vector to avoid reallocation.
vector(size_t sz) THROW
Constructor, vector of size sz.
grid_cpu< 1, T, Memory, typename layout_base< T >::type > base
1-D static grid
size_t packObjectSize()
Return the size of the message needed to pack this object.
void add(const typename grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container &v)
It insert a new object on the vector, eventually it reallocate the vector.
void set(size_t id, const typename grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container &obj)
Set the object id to obj.
void setMemory(Memory &mem)
Set the memory of the base structure using an object.
~vector() THROW
Destructor.
vector_key_iterator getIterator() const
Get the vector elements iterator.
const size_t & getInternal_v_size() const
Internal function.
void non_zero_one(size_t sz[1], size_t arg)
If the argument is zero return 1 otherwise return the argument.
static size_t packMem(size_t n, size_t e)
Calculate the memory size required to pack n elements.
const grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container last() const
Get the last element of the vector.
const void * getPointer() const
Return the pointer that store the data.
void add(const T &v)
It insert a new object on the vector, eventually it reallocate the grid.
static bool noPointers()
This class has pointer inside.
vector(const vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &v) THROW
Constructor from another constant vector.
It copy the properties from one object to another applying an operation.
void set(size_t id, vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &v, size_t src)
Set the element of the vector v from another element of another vector.
vector(vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &&v)
Constructor from another temporal vector.
vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > & operator=(const vector< T, Mem, layout, layout_base, gp, OPENFPM_NATIVE > &mv)
Assignment operator.
vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > & operator=(vector< T, Mem, layout, layout_base, gp, OPENFPM_NATIVE > &&mv)
Assignment operator.
void merge_prp_v(const vector< S, M, typename layout_base2< S >::type, layout_base2, gp, OPENFPM_NATIVE > &v, const openfpm::vector< aggregate< size_t, size_t >> &opart)
It merge the elements of a source vector to this vector.
bool operator==(const vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &v) const
Check that two vectors are not equal.
void add()
It insert a new emtpy object on the vector, eventually it reallocate the grid.
void swap(openfpm::vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &v)
Swap the memory with another vector.
void set_o(size_t i, const encap_S &obj)
It set an element of the vector from a object that is a subset of the vector properties.
This class is a trick to indicate the compiler a specific specialization pattern. ...
vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > & operator=(vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &&mv)
Assignment operator.
const grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container get_o(size_t id) const
Get an element of the vector.
void merge_prp(const vector< S, M, typename layout_base< S >::type, layout_base, gp, OPENFPM_NATIVE > &v, const openfpm::vector< size_t > &opart)
It merge the elements of a source vector to this vector.
vector_key_iterator getIteratorTo(size_t stop) const
Get iterator over the particles from 0 until a particular index.
It create a boost::fusion vector with the selected properties.
vector() THROW
Constructor, vector of size 0.
void add(const vector< T, M, layout, layout_base, gp, OPENFPM_NATIVE > &v)
It add the element of another vector to this vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
static size_t calculateMem(size_t n, size_t e)
Calculate the memory size required to allocate n elements.
grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container last()
Get the last element of the vector.
bool operator!=(const vector< T, Memory, layout, layout_base, grow_p, OPENFPM_NATIVE > &v) const
Check that two vectors are equal.
Implementation of 1-D std::vector like structure.
static size_t calculateNMem(size_t n)
How many allocation are required to create n-elements.
vector_key_iterator getIteratorFrom(size_t start) const
Get iterator over the particles from a particular index.
grid_cpu< 1, T, Memory, typename layout_base< T >::type >::container container
Object container for T, it is the return type of get_o it return a object type trough.