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, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > Class Template Reference

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

Detailed Description

template<typename T, typename Memory, typename grow_p>
class openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >

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

The layout is memory_traits_lin

Add and access elements

openfpm::vector<Point_test<float>> v_ofp_test;
p.setx(1.0);
p.sety(2.0);
p.setz(3.0);
p.sets(4.0);
// push objects
for (size_t i = 0 ; i < n_ele / 2 ; i++)
{
// Modify the point
p.get<P::v>()[0] = 1.0 + i;
p.get<P::v>()[1] = 2.0 + i;
p.get<P::v>()[2] = 7.0 + i;
p.get<P::t>()[0][0] = 10.0 + i;
p.get<P::t>()[0][1] = 13.0 + i;
p.get<P::t>()[0][2] = 8.0 + i;
p.get<P::t>()[1][0] = 19.0 + i;
p.get<P::t>()[1][1] = 23.0 + i;
p.get<P::t>()[1][2] = 5.0 + i;
p.get<P::t>()[2][0] = 4.0 + i;
p.get<P::t>()[2][1] = 3.0 + i;
p.get<P::t>()[2][2] = 11.0 + i;
// add p
v_ofp_test.add(p);
}
for (size_t i = n_ele / 2 ; i < n_ele ; i++)
{
v_ofp_test.add();
size_t last = v_ofp_test.size()-1;
// Modify the point
v_ofp_test.get<P::v>(last)[0] = 1.0 + i;
v_ofp_test.get<P::v>(last)[1] = 2.0 + i;
v_ofp_test.get<P::v>(last)[2] = 7.0 + i;
v_ofp_test.get<P::t>(last)[0][0] = 10.0 + i;
v_ofp_test.get<P::t>(last)[0][1] = 13.0 + i;
v_ofp_test.get<P::t>(last)[0][2] = 8.0 + i;
v_ofp_test.get<P::t>(last)[1][0] = 19.0 + i;
v_ofp_test.get<P::t>(last)[1][1] = 23.0 + i;
v_ofp_test.get<P::t>(last)[1][2] = 5.0 + i;
v_ofp_test.get<P::t>(last)[2][0] = 4.0 + i;
v_ofp_test.get<P::t>(last)[2][1] = 3.0 + i;
v_ofp_test.get<P::t>(last)[2][2] = 11.0 + i;
}
Template Parameters
Ttype of object the vector store
basememory layout to use
Memoryallocator to use
grow_pgrow policy for vector in case of reallocation

OPENFPM_NATIVE implementation

Definition at line 280 of file map_vector.hpp.

#include <map_vector.hpp>

Public Types

typedef int yes_i_am_vector
 it define that it is a vector
 
typedef grid_cpu< 1, T >
::memory_conf 
memory_conf
 Type of the encapsulation memory parameter.
 
typedef vector_key_iterator iterator_key
 iterator for the vector
 
typedef grid_cpu< 1, T >::container container
 Object container for T, it is the return type of get_o it return a object type trough.
 
typedef T value_type
 Type of the value the vector is storing.
 
typedef size_t access_key
 Access key for the vector.
 

Public Member Functions

size_t size () const
 Return the size of the vector. More...
 
void reserve (size_t sp)
 Reserve slots in the vector to avoid reallocation. More...
 
void resize (size_t slot)
 Resize the vector. More...
 
void add ()
 It insert a new emtpy object on the vector, eventually it reallocate the grid. More...
 
void add (const T &v)
 It insert a new object on the vector, eventually it reallocate the grid. More...
 
void add (const typename grid_cpu< 1, T >::container &v)
 It insert a new object on the vector, eventually it reallocate the vector. More...
 
template<typename M , typename gp >
void add (const vector< T, device_cpu< T >, M, gp, OPENFPM_NATIVE > &v)
 It add the element of another vector to this vector. More...
 
template<typename S , typename M , typename gp , unsigned int... args>
void add_prp (const vector< S, device_cpu< S >, M, gp, OPENFPM_NATIVE > &v)
 It add the element of a source vector to this vector. More...
 
void remove (size_t key)
 Remove one entry from the vector. More...
 
void remove (openfpm::vector< size_t > keys, size_t start=0)
 Remove several entries from the vector. More...
 
template<unsigned int p>
const type_cpu_prop< p,
memory_lin >::type & 
get (size_t id) const
 Get an element of the vector. More...
 
const grid_cpu< 1, T >::container get (size_t id) const
 Get an element of the vector. More...
 
template<unsigned int p>
type_cpu_prop< p, memory_lin >
::type & 
get (size_t id)
 Get an element of the vector. More...
 
grid_cpu< 1, T >::container get (size_t id)
 Get an element of the vector. More...
 
 vector (vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&mv)
 Constructor from vector. More...
 
vector< T, device_cpu< T >
, Memory, grow_p,
OPENFPM_NATIVE > 
duplicate () const
 It duplicate the vector. More...
 
 vector (const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&v)
 Constructor from another temporal vector. More...
 
 vector (const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &v)
 Constructor from another constant vector. More...
 
 vector ()
 Constructor, vector of size 0.
 
 vector (size_t sz)
 Constructor, vector of size sz.
 
void set (size_t id, const typename grid_cpu< 1, T >::container &obj)
 Set the object id to obj. More...
 
void set (size_t id, T &obj)
 Set the object id to obj. More...
 
void set (size_t id, vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &v, size_t src)
 Set the element of the vector v from another element of another vector. More...
 
vector< T, device_cpu< T >
, Memory, grow_p,
OPENFPM_NATIVE > 
operator= (vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&mv)
 Assignment operator. More...
 
vector< T, device_cpu< T >
, Memory, grow_p,
OPENFPM_NATIVE > 
operator= (const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &mv)
 Assignment operator. More...
 
void swap (openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &v)
 Swap the memory with another vector. More...
 
void swap (openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&v)
 Swap the memory with another vector. More...
 
vector_key_iterator getIteratorFrom (size_t mark) const
 Get iterator over the particles from a particular index. More...
 
vector_key_iterator getIterator () const
 Get the vector elements iterator. More...
 
size_t packObjectSize ()
 Return the size of the message needed to pack this object. More...
 
size_t packObject (void *mem)
 Pack the object into the given pointer. More...
 
void setMemory (Memory &mem)
 Set the memory of the base structure using an object. More...
 
void * getPointer ()
 Return the pointer that store the data. More...
 

Static Public Member Functions

static size_t calculateMem (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 Types

typedef grid_cpu< 1, T >
::memory_lin 
memory_lin
 This structure use this layout.
 

Private Member Functions

std::vector< size_t > getV (size_t sz)
 Create a 1D vector that contain the vector size. More...
 
void non_zero_one (size_t sz[1], size_t arg)
 If the argument is zero return 1 otherwise return the argument. More...
 

Private Attributes

size_t v_size
 
grid_cpu< 1, T > base
 1-D static grid
 

Constructor & Destructor Documentation

template<typename T , typename Memory , typename grow_p >
openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::vector ( vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&  mv)
inline

Constructor from vector.

Parameters
mvvector

Definition at line 668 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::vector ( const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&  v)
inline

Constructor from another temporal vector.

Parameters
vthe vector

Definition at line 693 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::vector ( const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &  v)
inline

Constructor from another constant vector.

Parameters
vthe vector

Definition at line 704 of file map_vector.hpp.

Member Function Documentation

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::add ( )
inline

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

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

Check if we have enough space

Resize the memory, double up the actual memory allocated for the vector

increase the vector size

Definition at line 404 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::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

Check if we have enough space

Resize the memory, double up the actual memory allocated for the vector

copy the element

increase the vector size

Definition at line 428 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::add ( const typename grid_cpu< 1, T >::container v)
inline

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

Parameters
vobject (encapsulated)
Warning
It is not thread safe should not be used in multi-thread environment reallocation, work only on cpu

Check if we have enough space

Resize the memory, double up the actual memory allocated for the vector

copy the added element

increase the vector size

Definition at line 456 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
template<typename M , typename gp >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::add ( const vector< T, device_cpu< T >, M, gp, OPENFPM_NATIVE > &  v)
inline

It add the element of another vector to this vector.

Parameters
vfrom where to take the vector

Add the element of v

Definition at line 480 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
template<typename S , typename M , typename gp , unsigned int... args>
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::add_prp ( const vector< S, device_cpu< S >, M, gp, OPENFPM_NATIVE > &  v)
inline

It add the element of a source vector to this vector.

The number of properties in the source vector must be smaller than the destination all the properties of S must be mapped so if S has 3 properties 3 numbers for args are required

Template Parameters
SBase object of the source vector
Mmemory type of the source vector
gpGrow policy of the source vector
argsone or more number that define which property to set-up
Parameters
vsource vector

Add the element of v

Definition at line 501 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
static size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::calculateMem ( 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 899 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
static size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::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 914 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
vector<T,device_cpu<T>, Memory,grow_p,OPENFPM_NATIVE> openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::duplicate ( ) const
inline

It duplicate the vector.

Returns
a duplicated vector

Definition at line 678 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
template<unsigned int p>
const type_cpu_prop<p,memory_lin>::type& openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::get ( size_t  id) const
inline

Get an element of the vector.

Get an element of the vector

Template Parameters
pProperty to get
Parameters
idElement to get
Returns
the element value requested

Definition at line 588 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
const grid_cpu<1,T>::container openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::get ( size_t  id) const
inline

Get an element of the vector.

Get an element of the vector

Parameters
idElement to get
Returns
the element (encapsulated)

Definition at line 609 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
template<unsigned int p>
type_cpu_prop<p,memory_lin>::type& openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::get ( size_t  id)
inline

Get an element of the vector.

Get an element of the vector

Template Parameters
pProperty to get
Parameters
idElement to get
Returns
the element value requested

Definition at line 631 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
grid_cpu<1,T>::container openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::get ( size_t  id)
inline

Get an element of the vector.

Get an element of the vector

Parameters
idElement to get
Returns
the element (encapsulated)

Definition at line 652 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
vector_key_iterator openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::getIterator ( ) const
inline

Get the vector elements iterator.

Returns
an iterator to iterate through all the elements of the vector

Definition at line 861 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
vector_key_iterator openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::getIteratorFrom ( size_t  mark) const
inline

Get iterator over the particles from a particular index.

Returns
an iterator to iterate from a particular index

Definition at line 849 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void* openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::getPointer ( )
inline

Return the pointer that store the data.

Returns
the pointer that store the data

Definition at line 934 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
std::vector<size_t> openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::getV ( size_t  sz)
inlineprivate

Create a 1D vector that contain the vector size.

Used to construct the underline 1D-grid

Parameters
szsize of the vector
Returns
a vector with one element

Definition at line 302 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::non_zero_one ( size_t  sz[1],
size_t  arg 
)
inlineprivate

If the argument is zero return 1 otherwise return the argument.

Parameters
szoutput
argargument

Definition at line 317 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
static bool openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::noPointers ( )
inlinestatic

This class has pointer inside.

Returns
false

Definition at line 944 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
vector<T,device_cpu<T>, Memory,grow_p,OPENFPM_NATIVE> openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::operator= ( vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&  mv)
inline

Assignment operator.

move semantic movement operator=

Parameters
mvvector
Returns
itself

Definition at line 779 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
vector<T,device_cpu<T>, Memory,grow_p,OPENFPM_NATIVE> openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::operator= ( const vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &  mv)
inline

Assignment operator.

it copy

Parameters
mvvector
Returns
itself

Definition at line 796 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::packObject ( void *  mem)
inline

Pack the object into the given pointer.

Parameters
mempointer
Returns
the size of the packed message

Definition at line 884 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::packObjectSize ( )
inline

Return the size of the message needed to pack this object.

Returns
The size

Definition at line 872 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::remove ( size_t  key)
inline

Remove one entry from the vector.

Parameters
keyelement to remove

Definition at line 519 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::remove ( openfpm::vector< size_t >  keys,
size_t  start = 0 
)
inline

Remove several entries from the vector.

Parameters
keysobjects id to remove
startkey starting point

Definition at line 543 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::reserve ( size_t  sp)
inline

Reserve slots in the vector to avoid reallocation.

Reserve slots in the vector to avoid reallocation

Parameters
spnumber of slot to reserve

Resize the memory

Definition at line 361 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::resize ( size_t  slot)
inline

Resize the vector.

Resize the vector and allocate n elements

Parameters
slotnumber of elements

Resize the memory

Definition at line 378 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::set ( size_t  id,
const typename grid_cpu< 1, T >::container obj 
)
inline

Set the object id to obj.

Parameters
idelement
objobject (encapsulated)

copy the element

Definition at line 728 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::set ( size_t  id,
T &  obj 
)
inline

Set the object id to obj.

Parameters
id
obj

copy the element

Definition at line 744 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::set ( size_t  id,
vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &  v,
size_t  src 
)
inline

Set the element of the vector v from another element of another vector.

Parameters
idelement id
vvector source
srcsource element

Definition at line 761 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::setMemory ( Memory &  mem)
inline

Set the memory of the base structure using an object.

Parameters
memMemory object to use for allocation

Definition at line 924 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::size ( ) const
inline

Return the size of the vector.

Returns
the size

Definition at line 348 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::swap ( openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &  v)
inline

Swap the memory with another vector.

Parameters
vvector

Definition at line 817 of file map_vector.hpp.

template<typename T , typename Memory , typename grow_p >
void openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::swap ( openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE > &&  v)
inline

Swap the memory with another vector.

Parameters
vvector

Definition at line 833 of file map_vector.hpp.

Field Documentation

template<typename T , typename Memory , typename grow_p >
size_t openfpm::vector< T, device_cpu< T >, Memory, grow_p, OPENFPM_NATIVE >::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 288 of file map_vector.hpp.


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