8 #ifndef MAP_VECTOR_STD_HPP_
9 #define MAP_VECTOR_STD_HPP_
11 #include "se_vector.hpp"
25 class vector<T,HeapMemory,grow_policy_double,STD_VECTOR>
49 #include "vector_std_pack_unpack.ipp"
96 inline void add(
const T & v)
118 base.emplace_back(v);
130 base.emplace_back(T());
139 void erase(
typename std::vector<T>::iterator start,
typename std::vector<T>::iterator end)
144 base.erase(start,end);
158 vector_overflow(
key);
160 base.erase(base.begin() +
key);
168 inline auto begin() -> decltype(base.begin())
178 inline auto end() -> decltype(base.begin())
194 if (base.size() == 0)
195 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
197 return base[base.size()-1];
211 if (base.size() == 0)
212 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" vector of size 0\n";
214 return base[base.size()-1];
253 auto it = std::unique(base.begin(),base.end());
254 base.resize( std::distance(base.begin(),it) );
267 std::sort(base.begin(), base.end());
279 template <
unsigned int p>
inline T&
get(
size_t id)
286 {std::cerr <<
"Error the property does not exist" <<
"\n";}
303 template <
unsigned int p>
inline const T&
get(
size_t id)
const
310 {std::cerr <<
"Error the property does not exist" <<
"\n";}
325 inline T &
get(
size_t id)
331 if (
id >= base.size())
332 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " <<
id <<
"\n";
344 inline const T &
get(
size_t id)
const
364 inline void fill(
unsigned char fl)
369 memset(&base[0],fl,base.size() *
sizeof(T));
388 :v_size(0),err_code(0)
391 check_new(
this,8,VECTOR_STD_EVENT,1);
397 :v_size(0),base(sz),err_code(0)
400 check_new(
this,8,VECTOR_STD_EVENT,1);
406 :v_size(0),err_code(0)
409 check_new(
this,8,VECTOR_STD_EVENT,1);
420 vector(
const std::initializer_list<T> & v)
426 :v_size(0),err_code(0)
429 check_new(
this,8,VECTOR_STD_EVENT,1);
493 return base != v.
base;
503 return base == v.
base;
516 return vector_key_iterator(base.size());
529 template<
int ... prp>
inline size_t packMem(
size_t n,
size_t e)
535 std::cout <<
"Inside map_vector_std.hpp packMem()" << std::endl;
538 return cm.packMemory(*
this,n,0);
621 if (v1 >= base.size())
623 std::cerr <<
"Error vector: " << __FILE__ <<
":" << __LINE__ <<
" overflow id: " << v1 <<
"\n";\
624 size_t * err_code_pointer = (
size_t *)&this->err_code;\
625 *err_code_pointer = 2001;\
626 ACTION_ON_ERROR(VECTOR_ERROR);\
638 return check_whoami(
this,8);
std::vector< T > duplicate()
Duplicate the vector.
size_t size() const
return the size of the vector
size_t getLastError()
Return the last error.
void swap(openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v)
Implementation of 1-D std::vector like structure.
vector_key_iterator iterator_key
iterator for the vector
void add()
Add an empty object (it call the default constructor () ) at the end of the vector.
std::vector< T > base
1-D static grid
vector< T, HeapMemory, grow_policy_double, STD_VECTOR > & operator=(vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &&v)
Operator= copy the vector into another.
void sort()
It sort the vector.
std::vector< T > base
1-D static grid
static bool noPointers()
This class has pointer inside.
vector_key_iterator getIterator() const
Get iterator.
void add(const T &v)
It insert a new object on the vector, eventually it reallocate the grid.
vector(const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) noexcept
Constructor from another vector.
const T & last() const
Get the last element.
T & last()
Get the last element.
static size_t calculateMemDummy(size_t n, size_t e)
Calculate the memory size required to allocate n elements.
int yes_i_am_vector
it define that it is a vector
~vector() noexcept
destructor
void unique()
It eliminate double entries.
void erase(typename std::vector< T >::iterator start, typename std::vector< T >::iterator end)
Erase the elements from start to end.
auto end() -> decltype(base.begin())
Return an std compatible iterator to the last element.
vector(vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &&v) noexcept
Constructor from another vector.
void add(T &&v)
It insert a new object on the vector, eventually it reallocate the grid.
This class is a trick to indicate the compiler a specific specialization pattern. ...
size_t packMem(size_t n, size_t e)
Calculate the memory size required to allocate n elements.
size_t err_code
Error code.
void clear()
Remove all the element from the vector.
bool operator==(const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are not equal.
vector(size_t sz) noexcept
Constructor, vector of size sz.
void fill(unsigned char fl)
it fill all the memory of fl patterns
bool operator!=(const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) const
Check that two vectors are equal.
vector< T, HeapMemory, grow_policy_double, STD_VECTOR > & operator=(const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v)
Operator= copy the vector into another.
static size_t calculateNMem(size_t n)
How many allocation are required to create n-elements.
Implementation of 1-D std::vector like structure.
void swap(std::vector< T > &&v)
swap the memory between the two vector
auto begin() -> decltype(base.begin())
Return an std compatible iterator to the first element.
void * getPointer()
Return the pointer to the chunk of memory.
void reserve(size_t ns)
reserve a memory space in advance to avoid reallocation
vector(const std::initializer_list< T > &v)
Initializer from constructor.
vector() noexcept
Constructor, vector of size 0.
Implementation of 1-D std::vector like structure.
void vector_overflow(size_t v1) const
check that the id does not overflow the buffer
const void * getPointer() const
Return the pointer to the chunk of memory.
T value_type
Type of the value the vector is storing.