


Category:containers 
Component type:concept 


Description

Not to be confused with the std::vector class. The MTL Vector
concept is a Container in which every element has a corresponding
index. The elements do not have to be sorted by their index, and
the indices do not necessarily have to start at 0. Also the indices
do not have to form a contiguous range. The iterator type must be a
model of IndexedIterator. Vector is not a refinement of
RandomAccessContainer (even though Vector defines
operator[]) because Vector does not guarantee amortized
constant time for that operation (to allow fo sparse vectors).
Note also that the invariant a[n] == advance(A.begin(), n)
that applies to RandomAccessContainer does not apply to Vector,
since the a[i] is defined for Vector to return the element
with the ith index. So a[n] == *i if and only if
i.index() == n.
The indices of the elements in the subrange remain the same.
For example, here is a vector written in terms of indexvalue pairs:
x = [ (0,2), (1,5), (2,3), (3,1), (4,9) ]
The subrange [1,3) of x can be obtained with
y = x(1,3)
which results in
y = [ (1,5), (2,3) ]
The subrange vector is a reference to a particular portion of the
original vector.
If you wish to have the subrange vector's starting index to be
zero just do the following:
y = x(1,3).adjust_index(1);
The adjust_index(delta) function does not affect the indexing of
the original vector.


Refinement of



Associated types

Concept 
Type name 
Description 
IndexedIterator

X::iterator


const IndexedIterator

X::const_iterator


Tag

X::dimension

Marks this as 1D

Tag

X::sparsity

dense_tag or sparse_tag

const Vector

X::scaled_type

The vector scaled be a constant

size_type

X::N

the static size, 0 if dynamic

const Container

X::IndexArray

An array containing the indices of the elements in the vector.

Vector

X::subrange_type

The subvector type

const Vector

X::const_subrange_type

The const subvector type



Notations

X  The type of a model of Vector 
a  An object of type X 
splits  A container of integral objects 


Definitions



Expression semantics

Description 
Expression 
Semantics 
Element access

a[n]


Const element access

a[n]


Subrange access

a(s,f)


Subrange access

a[r]


Number of nonzero elements (actually the number of stored elements)

a.nnz()


Adjust the indices of the elements by delta

x.adjust_index(delta);




Function specification

Name 
Function 
Complexity 
Element access

reference operator[](size_type n)

linear time

Const element access

const_reference operator[](size_type n)

linear time

Subrange access

subrange operator()(size_type start, size_type finish)

linear time

Subrange access

subrange operator()(range_type r)

linear time

Number of nonzero elements (actually the number of stored elements)

size_type nnz()

constant time

Adjust the indices of the elements by delta

self adjust_index(size_type delta)

constant time



Invariants

a.nnz() <= a.size()


Models



Notes



See also

