Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
util::internal::SVector< IndexT, T > Class Template Reference

#include <graph.h>

Public Types

using value_type = T

Public Member Functions

 SVector ()
 ~SVector ()
 SVector (const SVector &other)
 Copy constructor and assignment operator.
SVectoroperator= (const SVector &other)
 SVector (SVector &&other) noexcept
 Move constructor and move assignment operator.
SVectoroperator= (SVector &&other) noexcept
T & operator[] (IndexT n)
const T & operator[] (IndexT n) const
void resize (IndexT n)
void clear ()
T * data () const
const T * begin () const
const T * end () const
void swap (SVector< IndexT, T > &x) noexcept
void reserve (IndexT n)
void grow (const T &left=T(), const T &right=T())
IndexT size () const
IndexT capacity () const
IndexT max_size () const
void clear_and_dealloc ()

Detailed Description

template<typename IndexT, typename T>
class util::internal::SVector< IndexT, T >

A vector-like class where valid indices are in [- size_, size_) and reserved indices for future growth are in [- capacity_, capacity_). It is used to hold arc related information for graphs with reverse arcs. It supports only up to 2^31-1 elements, for compactness. If you ever need more, consider using templates for the size/capacity integer types.

Sample usage:

SVector<int> v; v.grow(left_value, right_value); v.resize(10); v.clear(); v.swap(new_v); std:swap(v[i], v[~i]);

Definition at line 421 of file graph.h.

Member Typedef Documentation

◆ value_type

template<typename IndexT, typename T>
using util::internal::SVector< IndexT, T >::value_type = T

Definition at line 423 of file graph.h.

Constructor & Destructor Documentation

◆ SVector() [1/3]

template<typename IndexT, typename T>
util::internal::SVector< IndexT, T >::SVector ( )
inline

Definition at line 425 of file graph.h.

◆ ~SVector()

template<typename IndexT, typename T>
util::internal::SVector< IndexT, T >::~SVector ( )
inline

Definition at line 427 of file graph.h.

◆ SVector() [2/3]

template<typename IndexT, typename T>
util::internal::SVector< IndexT, T >::SVector ( const SVector< IndexT, T > & other)
inline

Copy constructor and assignment operator.

Definition at line 430 of file graph.h.

◆ SVector() [3/3]

template<typename IndexT, typename T>
util::internal::SVector< IndexT, T >::SVector ( SVector< IndexT, T > && other)
inlinenoexcept

Move constructor and move assignment operator.

Definition at line 450 of file graph.h.

Member Function Documentation

◆ begin()

template<typename IndexT, typename T>
const T * util::internal::SVector< IndexT, T >::begin ( ) const
inline

Definition at line 493 of file graph.h.

◆ capacity()

template<typename IndexT, typename T>
IndexT util::internal::SVector< IndexT, T >::capacity ( ) const
inline

Definition at line 545 of file graph.h.

◆ clear()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::clear ( )
inline

Definition at line 489 of file graph.h.

◆ clear_and_dealloc()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::clear_and_dealloc ( )
inline

Definition at line 549 of file graph.h.

◆ data()

template<typename IndexT, typename T>
T * util::internal::SVector< IndexT, T >::data ( ) const
inline

Definition at line 491 of file graph.h.

◆ end()

template<typename IndexT, typename T>
const T * util::internal::SVector< IndexT, T >::end ( ) const
inline

Definition at line 494 of file graph.h.

◆ grow()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::grow ( const T & left = T(),
const T & right = T() )
inline

NOTE(user): This doesn't currently support movable-only objects, but we could fix that.

We have to copy the elements because they are allowed to be element of *this.

Definition at line 526 of file graph.h.

◆ max_size()

template<typename IndexT, typename T>
IndexT util::internal::SVector< IndexT, T >::max_size ( ) const
inline

Definition at line 547 of file graph.h.

◆ operator=() [1/2]

template<typename IndexT, typename T>
SVector & util::internal::SVector< IndexT, T >::operator= ( const SVector< IndexT, T > & other)
inline

NOTE(user): Alternatively, our capacity could inherit from the other vector's capacity, which can be (much) greater than its size.

Perform the actual copy of the payload.

Definition at line 431 of file graph.h.

◆ operator=() [2/2]

template<typename IndexT, typename T>
SVector & util::internal::SVector< IndexT, T >::operator= ( SVector< IndexT, T > && other)
inlinenoexcept

NOTE(user): We could just swap() and let the other's destruction take care of the clean-up, but it is probably less bug-prone to perform the destruction immediately.

Definition at line 451 of file graph.h.

◆ operator[]() [1/2]

template<typename IndexT, typename T>
T & util::internal::SVector< IndexT, T >::operator[] ( IndexT n)
inline

Definition at line 460 of file graph.h.

◆ operator[]() [2/2]

template<typename IndexT, typename T>
const T & util::internal::SVector< IndexT, T >::operator[] ( IndexT n) const
inline

Definition at line 466 of file graph.h.

◆ reserve()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::reserve ( IndexT n)
inline
Todo
(user): in C++17 we could use std::uninitialized_move instead of this loop.

Definition at line 502 of file graph.h.

◆ resize()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::resize ( IndexT n)
inline

Definition at line 472 of file graph.h.

◆ size()

template<typename IndexT, typename T>
IndexT util::internal::SVector< IndexT, T >::size ( ) const
inline

Definition at line 543 of file graph.h.

◆ swap()

template<typename IndexT, typename T>
void util::internal::SVector< IndexT, T >::swap ( SVector< IndexT, T > & x)
inlinenoexcept

Definition at line 496 of file graph.h.


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