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

Forward declaration. More...

#include <graph.h>

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[] (int n)
 
const T & operator[] (int n) const
 
void resize (int n)
 
void clear ()
 
T * data () const
 
void swap (SVector< T > &x) noexcept
 
void reserve (int n)
 
void grow (const T &left=T(), const T &right=T())
 
int size () const
 
int capacity () const
 
int max_size () const
 
void clear_and_dealloc ()
 

Detailed Description

template<typename T>
class util::SVector< T >

Forward declaration.

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 793 of file graph.h.

Constructor & Destructor Documentation

◆ SVector() [1/3]

template<typename T >
util::SVector< T >::SVector ( )
inline

Definition at line 795 of file graph.h.

◆ ~SVector()

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

Definition at line 797 of file graph.h.

◆ SVector() [2/3]

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

Copy constructor and assignment operator.

Definition at line 800 of file graph.h.

◆ SVector() [3/3]

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

Move constructor and move assignment operator.

Definition at line 820 of file graph.h.

Member Function Documentation

◆ capacity()

template<typename T >
int util::SVector< T >::capacity ( ) const
inline

Definition at line 911 of file graph.h.

◆ clear()

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

Definition at line 859 of file graph.h.

◆ clear_and_dealloc()

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

Definition at line 915 of file graph.h.

◆ data()

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

Definition at line 861 of file graph.h.

◆ grow()

template<typename T >
void util::SVector< 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 892 of file graph.h.

◆ max_size()

template<typename T >
int util::SVector< T >::max_size ( ) const
inline

Definition at line 913 of file graph.h.

◆ operator=() [1/2]

template<typename T >
SVector & util::SVector< T >::operator= ( const SVector< 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 801 of file graph.h.

◆ operator=() [2/2]

template<typename T >
SVector & util::SVector< T >::operator= ( SVector< 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 821 of file graph.h.

◆ operator[]() [1/2]

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

Definition at line 830 of file graph.h.

◆ operator[]() [2/2]

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

Definition at line 836 of file graph.h.

◆ reserve()

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

Definition at line 869 of file graph.h.

◆ resize()

template<typename T >
void util::SVector< T >::resize ( int n)
inline

Definition at line 842 of file graph.h.

◆ size()

template<typename T >
int util::SVector< T >::size ( ) const
inline

Definition at line 909 of file graph.h.

◆ swap()

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

Definition at line 863 of file graph.h.


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