OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR > Class Template Reference

Implementation of 1-D std::vector like structure. More...

Detailed Description

template<typename T>
class openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >

Implementation of 1-D std::vector like structure.

this implementation is just a wrapper for the std::vector in the case of data where the members cannot be parsed see openFPM_data wiki for more information

Create add and access the elements

Parameters
Tbase type

Definition at line 25 of file map_vector.hpp.

#include <map_vector.hpp>

Data Structures

struct  pack_cond
 
struct  pack_cond< true, T1, Memory1, prp...>
 
struct  packMem_cond
 
struct  packMem_cond< true, T1, prp...>
 
struct  packRequest_cond
 
struct  packRequest_cond< true, T1, prp...>
 
struct  unpack_cond
 
struct  unpack_cond< true, T1, Memory1, prp...>
 

Public Types

typedef int yes_i_am_vector
 it define that it is a vector
 
typedef vector_key_iterator iterator_key
 iterator for the vector
 
typedef T value_type
 Type of the value the vector is storing.
 

Public Member Functions

template<int... prp>
void pack (ExtPreAlloc< HeapMemory > &mem, Pack_stat &sts)
 
template<int... prp>
void packRequest (std::vector< size_t > &v)
 Insert an allocation request into the vector. More...
 
template<unsigned int... prp>
void unpack (ExtPreAlloc< HeapMemory > &mem, Unpack_stat &ps)
 unpack a vector More...
 
bool save (std::string file)
 Save this object into file. More...
 
bool load (std::string file)
 Load this object from file. More...
 
size_t size () const
 return the size of the vector
 
void resize (size_t slot)
 
void clear ()
 Remove all the element from the vector. More...
 
void add (const T &v)
 It insert a new object on the vector, eventually it reallocate the grid. More...
 
void add (T &&v)
 It insert a new object on the vector, eventually it reallocate the grid. More...
 
void add ()
 Add an empty object (it call the default constructor () ) at the end of the vector. More...
 
void erase (typename std::vector< T >::iterator start, typename std::vector< T >::iterator end)
 Erase the elements from start to end. More...
 
void remove (size_t key)
 Remove one entry from the vector. More...
 
auto begin () -> decltype(base.begin())
 Return an std compatible iterator to the first element. More...
 
auto end () -> decltype(base.begin())
 Return an std compatible iterator to the last element. More...
 
T & last ()
 Get the last element. More...
 
const T & last () const
 Get the last element. More...
 
std::vector< T > duplicate ()
 Duplicate the vector. More...
 
void swap (std::vector< T > &&v)
 swap the memory between the two vector More...
 
void unique ()
 It eliminate double entries. More...
 
void sort ()
 It sort the vector. More...
 
template<unsigned int p>
T & get (size_t id)
 Get an element of the vector. More...
 
template<unsigned int p>
const T & get (size_t id) const
 Get an element of the vector. More...
 
T & get (size_t id)
 Get an element of the vector. More...
 
const T & get (size_t id) const
 Get an element of the vector. More...
 
void fill (unsigned char fl)
 it fill all the memory of fl patterns More...
 
void reserve (size_t ns)
 reserve a memory space in advance to avoid reallocation More...
 
 vector () noexcept
 Constructor, vector of size 0.
 
 vector (size_t sz) noexcept
 Constructor, vector of size sz.
 
 vector (const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) noexcept
 Constructor from another vector.
 
 vector (const std::initializer_list< T > &v)
 Initializer from constructor. More...
 
 vector (vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &&v) noexcept
 Constructor from another vector.
 
 ~vector () noexcept
 destructor
 
void swap (openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v)
 
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. More...
 
vector< T, HeapMemory,
grow_policy_double, STD_VECTOR > & 
operator= (vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &&v)
 Operator= copy the vector into another. More...
 
bool operator!= (const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) const
 Check that two vectors are equal. More...
 
bool operator== (const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &v) const
 Check that two vectors are not equal. More...
 
vector_key_iterator getIterator () const
 Get iterator. More...
 
template<int... prp>
size_t packMem (size_t n, size_t e)
 Calculate the memory size required to allocate n elements. More...
 
void * getPointer ()
 Return the pointer to the chunk of memory. More...
 
const void * getPointer () const
 Return the pointer to the chunk of memory. More...
 
size_t getLastError ()
 Return the last error. More...
 
void vector_overflow (size_t v1) const
 check that the id does not overflow the buffer More...
 
long int who ()
 

Static Public Member Functions

static bool pack ()
 pack a vector selecting the properties to pack More...
 
static bool packRequest ()
 
static bool packMem ()
 
static size_t calculateMemDummy (size_t n, size_t e)
 Calculate the memory size required to allocate n elements. More...
 
static size_t calculateNMem (size_t n)
 How many allocation are required to create n-elements. More...
 
static bool noPointers ()
 This class has pointer inside. More...
 

Private Attributes

size_t v_size
 
std::vector< T > base
 1-D static grid
 
size_t err_code
 Error code.
 

Constructor & Destructor Documentation

template<typename T >
openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::vector ( const std::initializer_list< T > &  v)
inline

Initializer from constructor.

Parameters
vInitializer list

Definition at line 420 of file map_vector.hpp.

Member Function Documentation

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::add ( const T &  v)
inline

It insert a new object on the vector, eventually it reallocate the grid.

Parameters
velement to add
Warning
It is not thread safe should not be used in multi-thread environment reallocation, work only on cpu

vector_isel<T>::value

Definition at line 96 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::add ( T &&  v)
inline

It insert a new object on the vector, eventually it reallocate the grid.

Parameters
velement to add
Warning
It is not thread safe should not be used in multi-thread environment reallocation, work only on cpu

vector_isel<T>::value

Definition at line 113 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::add ( )
inline

Add an empty object (it call the default constructor () ) at the end of the vector.

Definition at line 125 of file map_vector.hpp.

template<typename T >
auto openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::begin ( ) -> decltype(base.begin())
inline

Return an std compatible iterator to the first element.

Returns
an iterator to the first element

Definition at line 168 of file map_vector.hpp.

template<typename T >
static size_t openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::calculateMemDummy ( size_t  n,
size_t  e 
)
inlinestatic

Calculate the memory size required to allocate n elements.

Calculate the total size required to store n-elements in a vector

Parameters
nnumber of elements
eunused
Returns
the size of the allocation number e

Definition at line 552 of file map_vector.hpp.

template<typename T >
static size_t openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::calculateNMem ( size_t  n)
inlinestatic

How many allocation are required to create n-elements.

Parameters
nnumber of elements
Returns
the number of allocations

Definition at line 564 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::clear ( )
inline

Remove all the element from the vector.

Definition at line 79 of file map_vector.hpp.

template<typename T >
std::vector<T> openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::duplicate ( )
inline

Duplicate the vector.

Returns
the duplicated vector

Definition at line 222 of file map_vector.hpp.

template<typename T >
auto openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::end ( ) -> decltype(base.begin())
inline

Return an std compatible iterator to the last element.

Returns
an iterator to the last element

Definition at line 178 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::erase ( typename std::vector< T >::iterator  start,
typename std::vector< T >::iterator  end 
)
inline

Erase the elements from start to end.

Parameters
startelement
endelement

Definition at line 139 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::fill ( unsigned char  fl)
inline

it fill all the memory of fl patterns

WARNING does not assign a value to each element but it fill the memory Useful to fast set the memory to zero

Parameters
flbyte to fill

Definition at line 364 of file map_vector.hpp.

template<typename T >
template<unsigned int p>
T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::get ( size_t  id)
inline

Get an element of the vector.

Template Parameters
pmust be 0
Parameters
idelement to get
Returns
the reference to the element

Definition at line 279 of file map_vector.hpp.

template<typename T >
template<unsigned int p>
const T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::get ( size_t  id) const
inline

Get an element of the vector.

Template Parameters
pmust be 0
Parameters
idelement to get
Returns
the reference to the element

Definition at line 303 of file map_vector.hpp.

template<typename T >
T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::get ( size_t  id)
inline

Get an element of the vector.

Parameters
idelement to get
Returns
the element reference

Definition at line 325 of file map_vector.hpp.

template<typename T >
const T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::get ( size_t  id) const
inline

Get an element of the vector.

Parameters
idelement to get
Returns
the element value

Definition at line 344 of file map_vector.hpp.

template<typename T >
vector_key_iterator openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::getIterator ( ) const
inline

Get iterator.

Returns
an iterator

Definition at line 511 of file map_vector.hpp.

template<typename T >
size_t openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::getLastError ( )
inline

Return the last error.

Definition at line 606 of file map_vector.hpp.

template<typename T >
void* openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::getPointer ( )
inline

Return the pointer to the chunk of memory.

Returns
the pointer to the chunk of memory

Definition at line 575 of file map_vector.hpp.

template<typename T >
const void* openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::getPointer ( ) const
inline

Return the pointer to the chunk of memory.

Returns
the pointer to the chunk of memory

Definition at line 588 of file map_vector.hpp.

template<typename T >
T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::last ( )
inline

Get the last element.

Returns
the last element as reference

Definition at line 188 of file map_vector.hpp.

template<typename T >
const T& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::last ( ) const
inline

Get the last element.

Returns
the last element as reference

Definition at line 205 of file map_vector.hpp.

template<typename T >
bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::load ( std::string  file)
inline

Load this object from file.

Parameters
filefilename
Returns
true if succed

Definition at line 271 of file map_vector.hpp.

template<typename T >
static bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::noPointers ( )
inlinestatic

This class has pointer inside.

Returns
false

Definition at line 598 of file map_vector.hpp.

template<typename T >
bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::operator!= ( const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &  v) const
inline

Check that two vectors are equal.

Parameters
vectorto compare

Definition at line 491 of file map_vector.hpp.

template<typename T >
vector<T,HeapMemory,grow_policy_double,STD_VECTOR>& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::operator= ( const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &  v)
inline

Operator= copy the vector into another.

Returns
itself

Definition at line 461 of file map_vector.hpp.

template<typename T >
vector<T,HeapMemory,grow_policy_double,STD_VECTOR>& openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::operator= ( vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &&  v)
inline

Operator= copy the vector into another.

Returns
itself

Definition at line 476 of file map_vector.hpp.

template<typename T >
bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::operator== ( const vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &  v) const
inline

Check that two vectors are not equal.

Parameters
vectorto compare

Definition at line 501 of file map_vector.hpp.

template<typename T >
static bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::pack ( )
inlinestatic

pack a vector selecting the properties to pack

Parameters
mempreallocated memory where to pack the vector
objobject to pack
stspack-stat info

Definition at line 171 of file map_vector.hpp.

template<typename T >
template<int... prp>
size_t openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::packMem ( size_t  n,
size_t  e 
)
inline

Calculate the memory size required to allocate n elements.

Calculate the total size required to store n-elements in a vector

Parameters
nnumber of elements
eunused
Returns
the size of the allocation number e

Definition at line 529 of file map_vector.hpp.

template<typename T >
template<int... prp>
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::packRequest ( std::vector< size_t > &  v)
inline

Insert an allocation request into the vector.

Parameters
objvector object to pack
requestsvector

Definition at line 203 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::remove ( size_t  key)
inline

Remove one entry from the vector.

Parameters
keyelement to remove

Definition at line 152 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::reserve ( size_t  ns)
inline

reserve a memory space in advance to avoid reallocation

Parameters
nsnumber of element the memory has to store

Definition at line 378 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::resize ( size_t  slot)
inline

\ brief Resize the vector to contain n elements

Parameters
slotnumber of elements

Definition at line 66 of file map_vector.hpp.

template<typename T >
bool openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::save ( std::string  file)
inline

Save this object into file.

Parameters
filefilename
Returns
true if succed

Definition at line 236 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::sort ( )
inline

It sort the vector.

Note
The base object must have an operator< defined

Definition at line 262 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::swap ( std::vector< T > &&  v)
inline

swap the memory between the two vector

Parameters
vvector to swap

Definition at line 235 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::swap ( openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR > &  v)
inline

swap the content of the vector

Parameters
vvector to be swapped with

Definition at line 448 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::unique ( )
inline

It eliminate double entries.

Note
The base object must have an operator== defined

Definition at line 248 of file map_vector.hpp.

template<typename T >
template<unsigned int... prp>
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::unpack ( ExtPreAlloc< HeapMemory > &  mem,
Unpack_stat ps 
)
inline

unpack a vector

Warning
the properties should match the packed properties, and the obj must have the same size of the packed vector, consider to pack this information if you cannot infer-it
Parameters
extpreallocated memory from where to unpack the vector
objobject where to unpack

Definition at line 219 of file map_vector.hpp.

template<typename T >
void openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::vector_overflow ( size_t  v1) const
inline

check that the id does not overflow the buffer

Parameters
idto check

Definition at line 619 of file map_vector.hpp.

Field Documentation

template<typename T >
size_t openfpm::vector< T, HeapMemory, grow_policy_double, STD_VECTOR >::v_size
private

Actual size of the vector, warning: it is not the space allocated in grid grid size increase by a fixed amount every time we need a vector bigger than the actually allocated space

Definition at line 30 of file map_vector.hpp.


The documentation for this class was generated from the following file: