Public Member Functions | List of all members
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. More...
 
SVectoroperator= (const SVector &other)
 
 SVector (SVector &&other)
 Move constructor and move assignment operator. More...
 
SVectoroperator= (SVector &&other)
 
T & operator[] (int n)
 
const T & operator[] (int n) const
 
void resize (int n)
 
void clear ()
 
T * data () const
 
void swap (SVector< T > &x)
 
void reserve (int n)
 
void grow (const T &left=T(), const T &right=T())
 NOTE(user): This doesn't currently support movable-only objects, but we could fix that. More...
 
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 174 of file graph.h.

Constructor & Destructor Documentation

◆ SVector() [1/3]

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

Definition at line 774 of file graph.h.

◆ ~SVector()

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

Definition at line 776 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 779 of file graph.h.

◆ SVector() [3/3]

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

Move constructor and move assignment operator.

Definition at line 801 of file graph.h.

Member Function Documentation

◆ capacity()

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

Definition at line 892 of file graph.h.

◆ clear()

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

Definition at line 840 of file graph.h.

◆ clear_and_dealloc()

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

Definition at line 896 of file graph.h.

◆ data()

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

Definition at line 842 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 873 of file graph.h.

◆ max_size()

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

Definition at line 894 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 780 of file graph.h.

◆ operator=() [2/2]

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

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

◆ operator[]() [1/2]

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

Definition at line 811 of file graph.h.

◆ operator[]() [2/2]

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

Definition at line 817 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 850 of file graph.h.

◆ resize()

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

Definition at line 823 of file graph.h.

◆ size()

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

Definition at line 890 of file graph.h.

◆ swap()

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

Definition at line 844 of file graph.h.


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