SparseVector or an alias object referring to a mutable sparse vector.
The real result type is a temporary object of type pm::SameElementVector.
It contains only a single copy of an element, or just a reference to an element,
but makes it to appear as a sequence of identical elements.
The real result type is a temporary alias object of type pm::VectorSlice.
It inherits the const-ness from the original vector.
This assertion is checked only in the DIMENSION_CHECKS compilation mode.
Random-access vector object: Vector, concatenation of random-access vectors,
or a slice of a random-access vector with a random-access index set
sequence or series.
if no preceding random access operations were performed on the sparse vector
The concrete vector type hidden behind the GenericVector.
if there already were random access operations on the sparse vector
Either a functor class satisfying the extended requirements
for binary operations, or
an untyped template of such a class wrapped into BuildBinary or BuildBinaryIt
(preferably expressed via the convenience typedef from namespace polymake::operations.
Vector or FixedVector.
In the latter case the dimension argument is ignored, as the vector dimension is hard encoded into the object type.
The real result type is a temporary alias object of type pm::VectorChain.
It is mutable only if both operands are mutable too.
The real return type is a temporary object (expression template) implementing the lazy evaluation
of the operation result. You should have it in mind when passing the result of a vector expression
as a GenericVector argument to a template function where it has a chance to be evaluated multiple
times. See also prevent_lazy class.
The vector and matrix operators defined in the Polymake Template Library do take care of this,
so this remark applies more likely to your own functions.
Any persistent vector: Vector or SparseVector,
or an alias object referring to a mutable (non-const) vector.
The real result type is a masquerade reference pm::SingleElementVector&.
This assertion is checked only in the INDEX_CHECKS compilation mode.
Any persistent class: Vector, SparseVector, or FixedVector.
In the latter case the dimension argument is ignored, as the vector dimension is hard encoded into the object type.
Either a functor class satisfying the extended requirements
for unary operations, or
an untyped template of such a class wrapped into BuildUnary or BuildUnaryIt
(preferably expressed via the convenience typedef from namespace polymake::operations.
The real result type is a temporary object of type pm::SameElementSparseVector.
It contains only a single copy of an element, or just a reference to it,
but makes it to appear as a sequence of elements.
The real return type is a temporary proxy object, forwarding the read/write access operations
to the sparse vector. Prior to the destruction, which happens after the completion of the expression
envolving the random access, it checks whether the element became zero and, if this holds, removes it from
the vector.
Prerequisits
#include <Vector.h>
#include <SparseVector.h>
using namespace polymake;
Introduction
The Vector class family implement vectors in the usual algebraic notion.
It contains three persistent vector types with different data storage organization:
template <typename ElementType> class SparseVector;
is an associative container with element indices (coordinates) as keys; elements equal to the default value
(ElementType(), which is 0 for most numerical types) are not stored, but implicitly encoded by the gaps in the
key set. It is based on a balanced binary search (AVL) tree.
template <typename ElementType, int size> class FixedVector;
is a built-in array of a fixed dimension decorated with the common vector interface.
The following brief analysis might help you when choosing the most efficient representation for a concrete case.
n is the number of (non-zero in sparse case) elements in the vector.
_Vector, the concrete vector object behind the generic reference
generic_type
GenericVector<_Vector> itself
persistent_type
Vector<ElementType> for dense vectors, SparseVector<ElementType> for sparse vectors.
Methods and friend functions applicable to GenericVector directly are scattered over the entire page.
They are discernible on the prefix GenericVector:: or parameters of type GenericVector&.
To use other methods via a generic reference (or pointer), you must first move to the concrete object using the
top() method.
Create a vector of dimension n, initialize all elements with value.
Use of corresponding constructor for SparseVector would defeat all the advantages of the
sparse structure, therefore it is not defined.
template <typename Iterator>
Vector (int n, Iterator src);
Create a vector of dimension n, initialize the elements from a data sequence.
For SparseVector, Iterator can be either indexed,
or supply index-value pairs, e.g. std::pair<int,ElementType>
or a plain sequence of data items. In the latter case zero elements are filtered out.
Persistent vector objects have after the assignment the same dimension as the right hand side operand.
Alias objects, such as vector slice or concatenated vector, cannot be resized, thus
they must have the same dimension as the right hand side operand.
Tell the current vector dimension. For dense vectors it is always the same as size().
For sparse vectors, however, the latter tells the number of non-zero elements.
Sequential access
All vector classes implement the STL Forward Container interface
or one of its refinements. This means, every vector object can be traversed using an
iterator or const_iterator created by begin() method or entire() function,
its size can be retrieved with size() method and so on.
For a vector object accessed via GenericVector reference or
pointer, you need first get to the concrete class with top() method
before you can use the standard container interface.
SparseVector inherits the data access methods from the binary tree.
Note that dereferencing the SparseVector::iterator
yields a reference to the element value, not a key-value pair as in the
std::map class or other associative containers.
The SparseVector::iterator::index() method tells the current element index (coordinate.)
Do exactly what the mnemonics suggest. Every type combination is allowed, including
mixing of sparse and dense vectors. ElementType of vector operands and Scalar type
can be different, provided the arithmetic operator with corresponding arguments exists.
Select a vector slice consisting of elements with given indices. The last variant
selects a contiguous range of indices beginning with start. size==0 means
up to the end of the vector. The const variants of these methods create immutable slice objects.
Concatenate two vectors, yielding a longer vector. A scalar argument is treated
as a vector of dimension 1. ElementType of vector operands must be identical, otherwise you will
get a rather cryptic message from the compiler.
Create a dense vector of dimension n, with all elements equal to x, 1, or 0, respectively.
Note the obligatory explicit specification of the template parameter ElementType, where
it cannot be deduced from the function arguments.