Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt::SparseVectorView< T > Class Template Reference

#include <sparse_vector_view.h>

Classes

class  const_iterator
 

Public Types

using value_type = std::pair<int64_t, T>
 

Public Member Functions

 SparseVectorView (absl::Span< const int64_t > ids, absl::Span< const T > values)
 
 SparseVectorView ()=default
 
const_iterator begin () const
 
const_iterator end () const
 
absl::Span< const int64_t > ids () const
 
int64_t ids (int index) const
 
int ids_size () const
 
absl::Span< const T > values () const
 
int values_size () const
 
const T & values (int index) const
 
template<typename KeyType , typename Storage >
absl::flat_hash_map< KeyType, T > as_map (const Storage *storage)
 

Detailed Description

template<typename T>
class operations_research::math_opt::SparseVectorView< T >

Abstracts sparse ids-values structures like SparseDoubleVector and mimics its .ids()/.values() API. It additionally provides const range iterations over the (id, value) pairs and conversion to a map.

The returned iterators are proper STL forward iterators that can be used with STL containers. For example to build a vector of pairs of values, one can simply use the iterators:

const auto view = MakeView(arg); const std::vector v(view.begin(), view.end());

Constructor SparseVectorView<T>(ids, values) will not check if ids and values have the same length. However, iterator functions and .as_map() will CHECK fail if ids and values do not have the same length.

Definition at line 88 of file sparse_vector_view.h.

Member Typedef Documentation

◆ value_type

template<typename T >
using operations_research::math_opt::SparseVectorView< T >::value_type = std::pair<int64_t, T>

Definition at line 90 of file sparse_vector_view.h.

Constructor & Destructor Documentation

◆ SparseVectorView() [1/2]

template<typename T >
operations_research::math_opt::SparseVectorView< T >::SparseVectorView ( absl::Span< const int64_t > ids,
absl::Span< const T > values )
inline

Definition at line 117 of file sparse_vector_view.h.

◆ SparseVectorView() [2/2]

template<typename T >
operations_research::math_opt::SparseVectorView< T >::SparseVectorView ( )
default

Member Function Documentation

◆ as_map()

template<typename T >
template<typename KeyType , typename Storage >
absl::flat_hash_map< KeyType, T > operations_research::math_opt::SparseVectorView< T >::as_map ( const Storage * storage)

Returns the map corresponding to this sparse vector.

It should be possible to construct KeyType::IdType from an int64_t and KeyType from a Storage pointer and the build id. See cpp/key_types.h for details.

Definition at line 243 of file sparse_vector_view.h.

◆ begin()

template<typename T >
SparseVectorView< T >::const_iterator operations_research::math_opt::SparseVectorView< T >::begin ( ) const
inline

Definition at line 229 of file sparse_vector_view.h.

◆ end()

template<typename T >
SparseVectorView< T >::const_iterator operations_research::math_opt::SparseVectorView< T >::end ( ) const
inline

Definition at line 236 of file sparse_vector_view.h.

◆ ids() [1/2]

template<typename T >
absl::Span< const int64_t > operations_research::math_opt::SparseVectorView< T >::ids ( ) const
inline

Definition at line 124 of file sparse_vector_view.h.

◆ ids() [2/2]

template<typename T >
int64_t operations_research::math_opt::SparseVectorView< T >::ids ( int index) const
inline

Definition at line 125 of file sparse_vector_view.h.

◆ ids_size()

template<typename T >
int operations_research::math_opt::SparseVectorView< T >::ids_size ( ) const
inline

Definition at line 126 of file sparse_vector_view.h.

◆ values() [1/2]

template<typename T >
absl::Span< const T > operations_research::math_opt::SparseVectorView< T >::values ( ) const
inline

Definition at line 127 of file sparse_vector_view.h.

◆ values() [2/2]

template<typename T >
const T & operations_research::math_opt::SparseVectorView< T >::values ( int index) const
inline

Definition at line 129 of file sparse_vector_view.h.

◆ values_size()

template<typename T >
int operations_research::math_opt::SparseVectorView< T >::values_size ( ) const
inline

Definition at line 128 of file sparse_vector_view.h.


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