Advanced Multi-Physics (AMP)
On-Line Documentation
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
AMP::LinearAlgebra::VectorDataIterator< TYPE > Class Template Reference

Iterator for local data in a vector. More...

#include <VectorDataIterator.h>

Public Types

using difference_type = ptrdiff_t
 
using iterator_category = std::random_access_iterator_tag
 
using pointer = const TYPE *
 
using reference = const TYPE &
 
using value_type = TYPE
 

Public Member Functions

VectorDataIterator begin () const
 Return a new iterator to the beginning of this iterator.
 
VectorDataIterator end () const
 Return a new iterator to the end of this iterator.
 
bool operator!= (const VectorDataIterator &rhs) const
 Test for inequality.
 
TYPE & operator* ()
 Dereference the iterator.
 
VectorDataIterator operator+ (int i)
 Add a constant to this iterator.
 
VectorDataIteratoroperator++ ()
 Increment the iterator.
 
VectorDataIterator operator++ (int)
 Increment the iterator.
 
VectorDataIteratoroperator+= (int i)
 Add a constant to this iterator.
 
int operator- (const VectorDataIterator &rhs) const
 Compute distance between two iterators.
 
VectorDataIterator operator- (int i)
 Subtract a constant to this iterator.
 
VectorDataIteratoroperator-- ()
 Decrement the iterator.
 
VectorDataIterator operator-- (int)
 Decrement the iterator.
 
VectorDataIteratoroperator-= (int i)
 Subtract a constant to this iterator.
 
bool operator< (const VectorDataIterator &rhs) const
 Less than operator.
 
bool operator<= (const VectorDataIterator &rhs) const
 Less than or equal operator.
 
VectorDataIteratoroperator= (const VectorDataIterator &rhs)
 
VectorDataIteratoroperator= (VectorDataIterator &&rhs)
 
bool operator== (const VectorDataIterator &rhs) const
 Test for equality.
 
bool operator> (const VectorDataIterator &rhs) const
 Greater than operator.
 
bool operator>= (const VectorDataIterator &rhs) const
 Greater than or equal operator.
 
TYPE & operator[] (int i)
 Return data a distance from the current iterator.
 
size_t position () const
 Return the position of the iterator.
 
size_t size () const
 Return the size of the iterator.
 
 VectorDataIterator ()
 Default constructor.
 
 VectorDataIterator (const VectorDataIterator &rhs)
 Copy constructor.
 
 VectorDataIterator (VectorData *p, size_t position)
 Constructor from a vector.
 
 VectorDataIterator (VectorDataIterator &&rhs)
 
 ~VectorDataIterator ()
 Destructor.
 

Private Types

using TYPE2 = typename AMP::remove_cvref_t< TYPE >
 

Private Member Functions

void advance (size_t)
 
void recede (size_t)
 

Private Attributes

size_t * d_blockSize
 
size_t d_CurBlock
 
size_t d_CurOffset
 
TYPE ** d_data
 
TYPE2 d_dataCast
 
size_t d_hashcode
 
size_t d_N_blocks
 
size_t d_pos
 
size_t d_size
 
uint64_t * d_typeHash
 

Detailed Description

template<class TYPE = double>
class AMP::LinearAlgebra::VectorDataIterator< TYPE >

Iterator for local data in a vector.

Even though a vector may have non-contiguous storage of data, the interface presents a contiguous block of memory to the user: each element in the vector is given an offset from 0 and the vector is packed. This allows for a random access iterator on the data.

Vector::begin() and Vector::end() return this class. This class uses the DataBlock interface in vectors to access data. As a result, for some non-AMP managed vectors, this class may not be the most efficient.

Definition at line 31 of file VectorDataIterator.h.

Member Typedef Documentation

◆ difference_type

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::difference_type = ptrdiff_t

Definition at line 36 of file VectorDataIterator.h.

◆ iterator_category

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::iterator_category = std::random_access_iterator_tag

Definition at line 34 of file VectorDataIterator.h.

◆ pointer

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::pointer = const TYPE *

Definition at line 37 of file VectorDataIterator.h.

◆ reference

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::reference = const TYPE &

Definition at line 38 of file VectorDataIterator.h.

◆ TYPE2

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::TYPE2 = typename AMP::remove_cvref_t<TYPE>
private

Definition at line 41 of file VectorDataIterator.h.

◆ value_type

template<class TYPE = double>
using AMP::LinearAlgebra::VectorDataIterator< TYPE >::value_type = TYPE

Definition at line 35 of file VectorDataIterator.h.

Constructor & Destructor Documentation

◆ VectorDataIterator() [1/4]

template<class TYPE = double>
AMP::LinearAlgebra::VectorDataIterator< TYPE >::VectorDataIterator ( )

Default constructor.

◆ ~VectorDataIterator()

template<class TYPE = double>
AMP::LinearAlgebra::VectorDataIterator< TYPE >::~VectorDataIterator ( )

Destructor.

◆ VectorDataIterator() [2/4]

template<class TYPE = double>
AMP::LinearAlgebra::VectorDataIterator< TYPE >::VectorDataIterator ( const VectorDataIterator< TYPE > &  rhs)

Copy constructor.

Parameters
[in]rhsiterator to copy

Copies an iterator

◆ VectorDataIterator() [3/4]

template<class TYPE = double>
AMP::LinearAlgebra::VectorDataIterator< TYPE >::VectorDataIterator ( VectorDataIterator< TYPE > &&  rhs)

Move constructor

Parameters
rhsIterator to copy

◆ VectorDataIterator() [4/4]

template<class TYPE = double>
AMP::LinearAlgebra::VectorDataIterator< TYPE >::VectorDataIterator ( VectorData p,
size_t  position 
)
explicit

Constructor from a vector.

This will construct an iterator over the local data in the vector. Vector::begin() and Vector::end() call this function to instantiate a new iterator. This method should not be invoked outside of this use.

Parameters
[in]pA (non-reference counted) pointer to the vector being iterated over
[in]positionThe local position in the vector.

Member Function Documentation

◆ advance()

template<class TYPE = double>
void AMP::LinearAlgebra::VectorDataIterator< TYPE >::advance ( size_t  )
private

◆ begin()

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::begin ( ) const

Return a new iterator to the beginning of this iterator.

◆ end()

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::end ( ) const

Return a new iterator to the end of this iterator.

◆ operator!=()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator!= ( const VectorDataIterator< TYPE > &  rhs) const
inline

Test for inequality.

Returns
True iff !(*this == rhs)

Returns !(*this == rhs)

◆ operator*()

template<class TYPE = double>
TYPE & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator* ( )
inline

Dereference the iterator.

Returns
Value pointed to by the iterator
Warning
Setting values in the vector with the iterator requires firing of dataChanged event.
See also
PetscVector
DataChangeListener

This returns a reference to the data pointed to by the iterator

◆ operator+()

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator+ ( int  i)

Add a constant to this iterator.

Parameters
[in]iOffset to move forward
Returns
A new iterator i steps forward

Equivalent to

for ( int k = 0 ; k != i ; k++ )
++t;
Iterator for local data in a vector.

except it is \(O(1)\) in most cases.

◆ operator++() [1/2]

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator++ ( )

Increment the iterator.

Returns
a reference to this iterator

◆ operator++() [2/2]

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator++ ( int  )

Increment the iterator.

Returns
a copy of this iterator

◆ operator+=()

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator+= ( int  i)

Add a constant to this iterator.

Parameters
[in]iOffset to move forward
Returns
A new iterator i steps forward

Equivalent to

for ( int k = 0 ; k != i ; k++ )
operator ++ ();

except it is \(O(1)\) in most cases.

◆ operator-() [1/2]

template<class TYPE = double>
int AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator- ( const VectorDataIterator< TYPE > &  rhs) const

Compute distance between two iterators.

Parameters
rhsThe other iterator to measure distance to
Returns
Number of entities between iterators. If rhs == this, the answer is 0. Else, if rhs is after this, then the answer is positive, otherwise it is negative.

If rhs is after this, this is equivalent to

int answer = 0;
while ( t != rhs )
{
t++;
answer++;
}
return answer;

except it is \(O(1)\) in most cases. If rhs is before this, the equivalent code is the same except t and answer are decremented.

◆ operator-() [2/2]

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator- ( int  i)

Subtract a constant to this iterator.

Parameters
[in]iOffset to move backward
Returns
A new iterator i steps backward

Equivalent to

for ( int k = 0 ; k != i ; k++ )
--t;

except it is \(O(1)\) in most cases.

◆ operator--() [1/2]

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator-- ( )

Decrement the iterator.

Returns
a reference to this iterator

◆ operator--() [2/2]

template<class TYPE = double>
VectorDataIterator AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator-- ( int  )

Decrement the iterator.

Returns
a copy of this iterator

◆ operator-=()

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator-= ( int  i)

Subtract a constant to this iterator.

Parameters
[in]iOffset to move backward
Returns
A new iterator i steps backward

Equivalent to

for ( int k = 0 ; k != i ; k++ )
operator -- ();

except it is \(O(1)\) in most cases.

◆ operator<()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator< ( const VectorDataIterator< TYPE > &  rhs) const
inline

Less than operator.

◆ operator<=()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator<= ( const VectorDataIterator< TYPE > &  rhs) const
inline

Less than or equal operator.

◆ operator=() [1/2]

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator= ( const VectorDataIterator< TYPE > &  rhs)

Assignment operator

Parameters
rhsIterator to copy

◆ operator=() [2/2]

template<class TYPE = double>
VectorDataIterator & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator= ( VectorDataIterator< TYPE > &&  rhs)

Move assignment operator

Parameters
rhsIterator to copy

◆ operator==()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator== ( const VectorDataIterator< TYPE > &  rhs) const
inline

Test for equality.

Returns
True iff iterators point to the same place on the same vector

Returns true iff rhs points to the exact same offset of the same vector. It is possible for two iterators to point to the same spot in memory and return false. This is due to the abstraction of a contiguous block presented by Vector.

◆ operator>()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator> ( const VectorDataIterator< TYPE > &  rhs) const
inline

Greater than operator.

◆ operator>=()

template<class TYPE = double>
bool AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator>= ( const VectorDataIterator< TYPE > &  rhs) const
inline

Greater than or equal operator.

◆ operator[]()

template<class TYPE = double>
TYPE & AMP::LinearAlgebra::VectorDataIterator< TYPE >::operator[] ( int  i)

Return data a distance from the current iterator.

Parameters
iOffset from this iterator
Returns
The data pointed to at this + i

Equivalent to

VectorDataIterator t = *this + i;
return *t;

◆ position()

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::position ( ) const
inline

Return the position of the iterator.

Definition at line 107 of file VectorDataIterator.h.

References AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_pos.

◆ recede()

template<class TYPE = double>
void AMP::LinearAlgebra::VectorDataIterator< TYPE >::recede ( size_t  )
private

◆ size()

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::size ( ) const
inline

Return the size of the iterator.

Definition at line 103 of file VectorDataIterator.h.

References AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_size.

Member Data Documentation

◆ d_blockSize

template<class TYPE = double>
size_t* AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_blockSize
private

Definition at line 44 of file VectorDataIterator.h.

◆ d_CurBlock

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_CurBlock
private

Definition at line 42 of file VectorDataIterator.h.

◆ d_CurOffset

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_CurOffset
private

Definition at line 42 of file VectorDataIterator.h.

◆ d_data

template<class TYPE = double>
TYPE** AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_data
private

Definition at line 45 of file VectorDataIterator.h.

◆ d_dataCast

template<class TYPE = double>
TYPE2 AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_dataCast
mutableprivate

Definition at line 47 of file VectorDataIterator.h.

◆ d_hashcode

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_hashcode
private

Definition at line 43 of file VectorDataIterator.h.

◆ d_N_blocks

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_N_blocks
private

Definition at line 42 of file VectorDataIterator.h.

◆ d_pos

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_pos
private

◆ d_size

template<class TYPE = double>
size_t AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_size
private

◆ d_typeHash

template<class TYPE = double>
uint64_t* AMP::LinearAlgebra::VectorDataIterator< TYPE >::d_typeHash
private

Definition at line 46 of file VectorDataIterator.h.


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



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:43.
Comments on this page