Polymake Template Library (PTL): pm::SparseVector< E > Class Template Reference
pm::SparseVector< E > Class Template Reference
Inheritance diagram for pm::SparseVector< E >:
Collaboration diagram for pm::SparseVector< E >:

Public Types

typedef E element_type
 element type
 
typedef std::conditional< is_sparse, SparseVector< E >, Vector< E > >::type persistent_type
 persistent type
 
typedef Generic< SparseVector< E > >::top_type top_type
 top type
 
typedef GenericVector generic_type
 generic type
 

Public Member Functions

int dim () const
 tell the current vector dimension, i.e., the number of non-zero elements (may differ from size)
 
 SparseVector ()
 create as empty
 
 SparseVector (int dim_arg)
 create vector of length n, (implicitly) initialize all elements with 0
 
template<typename Iterator , bool enabled = construct_sparse_iterator<Iterator, E>::enabled>
 SparseVector (int dim_arg, Iterator &&src)
 
 SparseVector (const GenericVector< SparseVector > &v)
 Copy of a disguised SparseVector object.
 
template<typename Vector2 >
 SparseVector (const GenericVector< Vector2, E > &v)
 Create a vector as a copy of another vector of the same element type.
 
template<typename Vector2 , typename E2 >
 SparseVector (const GenericVector< Vector2, E2 > &v, typename std::enable_if< can_initialize< E2, E >::value, void ** >::type=nullptr)
 Create a vector as a copy of another vector with a different element type.
 
template<typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
 SparseVector (std::initializer_list< E2 > l)
 
 SparseVector (int d, std::initializer_list< std::pair< int, E >> l)
 
void clear ()
 truncate to zero size
 
void resize (int n)
 change the size, initialize appended elements with default constructor
 
reference operator[] (int i)
 random access, may cost O(log(n)) time; Performance Comparison of Vector Classes
 
const E & operator[] (int i) const
 constant random access, may cost O(log(n)) time; Performance Comparison of Vector Classes
 
template<typename Vector2 , typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
SparseVectoroperator|= (const GenericVector< Vector2, E2 > &v)
 append a GenericVector
 
template<typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
SparseVectoroperator|= (E2 &&r)
 append an element
 
template<typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
SparseVectoroperator|= (std::initializer_list< E2 > l)
 
void remove0s ()
 remove all zero elements which might have been overseen in some previous operation
 
top_typeoperator+= (const GenericVector< TVector2 > &v)
 
top_typeoperator-= (const GenericVector< TVector2 > &v)
 
top_typeoperator*= (const Right &r)
 multiply with an element
 
top_typeoperator/= (const Right &r)
 appending an element
 
top_typediv_exact (const Right &r)
 divide by an element
 
top_typedehomogenize ()
 divides by the first element
 
top_typedehomogenize_trop ()
 subtracts first element
 
std::enable_if< isomorphic_to_container_of< IndexSet, int >::value, IndexedSlice< unwary_t< SparseVector< E > > &, const typename Concrete< IndexSet >::type & > >::type slice (const IndexSet &indices)
 

Static Public Attributes

static const bool is_sparse
 determine if the persistent type is sparse
 

Detailed Description

template<typename E>
class pm::SparseVector< E >

Vector type class which 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 an AVL tree.

Constructor & Destructor Documentation

template<typename E>
template<typename Iterator , bool enabled = construct_sparse_iterator<Iterator, E>::enabled>
pm::SparseVector< E >::SparseVector ( int  dim_arg,
Iterator &&  src 
)
inline

Create a vector of dimension n, initialize the elements from a data sequence. 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.

template<typename E>
template<typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
pm::SparseVector< E >::SparseVector ( std::initializer_list< E2 >  l)
inline

Create a vector from a list of values. Zeroes are filtered out automatically.

template<typename E>
pm::SparseVector< E >::SparseVector ( int  d,
std::initializer_list< std::pair< int, E >>  l 
)
inline

Create a vector from a list of (index, value) pairs. Parameter d specifies the dimension. Indices don't have to come in ascending order; zero values are not detected.

Member Function Documentation

top_type& pm::GenericVector< SparseVector< E > , E >::operator+= ( const GenericVector< TVector2 > &  v)
inlineinherited

adding a vector TODO: check whether addition is defined for both element types

top_type& pm::GenericVector< SparseVector< E > , E >::operator-= ( const GenericVector< TVector2 > &  v)
inlineinherited

subtracting a vector TODO: check whether subtraction is defined for both element types

template<typename E>
template<typename E2 , typename = typename std::enable_if<can_initialize<E2, E>::value>::type>
SparseVector& pm::SparseVector< E >::operator|= ( std::initializer_list< E2 >  l)
inline

append a list of elements zeroes are filtered out automatically

std::enable_if<isomorphic_to_container_of<IndexSet, int>::value, IndexedSlice<unwary_t<SparseVector< E > >&, const typename Concrete<IndexSet>::type&> >::type pm::GenericVector< SparseVector< E > , E >::slice ( const IndexSet &  indices)
inlineinherited

Select a vector slice consisting of elements with given indices. The last variant selects a contiguous range of indices beginning with start. size==-1 means up to the end of the vector. The const variants of these methods create immutable slice objects. The indices must lie in the valid range.


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