HiPipe  0.7.0
C++17 data pipeline with Python bindings.
Public Member Functions | List of all members
hipipe::index_mapper< T > Class Template Reference

Provides a bidirectional access from values to their indices in an std::vector. More...

#include <hipipe/core/index_mapper.hpp>

Public Member Functions

template<typename Rng >
 index_mapper (Rng &&values)
 
 index_mapper (std::initializer_list< T > values)
 Behaves as if the values were inserted to the mapper using insert().
 
std::size_t index_for (const T &val) const
 
std::size_t index_for (const T &val, std::size_t defval) const
 Returns the index of the given value or a default value if it does not exist.
 
std::vector< std::size_t > index_for (const std::vector< T > &vals) const
 
std::vector< std::size_t > index_for (const std::vector< T > &vals, std::size_t defval) const
 Returns the indexes of the given values or a default value if they do not exist.
 
const T & at (const std::size_t &idx) const
 
std::vector< T > at (const std::vector< std::size_t > &idxs) const
 
std::size_t insert (T val)
 
 CPP_template (class Rng)(requires ranges
 
 CPP_template (class Rng)(requires ranges
 Specialization of range insertion for views.
 
bool try_insert (T val)
 
 CPP_template (class Rng)(requires ranges
 
 CPP_template (class Rng)(requires ranges
 Specialization of try_insert for views.
 
bool contains (const T &val) const
 Checks whether the mapper contains the given value.
 
std::size_t size () const
 Returns the size of the mapper.
 
const std::vector< T > & values () const
 Returns all the contained values.
 

Detailed Description

template<typename T>
class hipipe::index_mapper< T >

Provides a bidirectional access from values to their indices in an std::vector.

Definition at line 27 of file index_mapper.hpp.

Constructor & Destructor Documentation

◆ index_mapper()

template<typename T>
template<typename Rng >
hipipe::index_mapper< T >::index_mapper ( Rng &&  values)
inline

Construct index mapper from a range of values.

Behaves as if the values were inserted to the mapper using insert().

Definition at line 35 of file index_mapper.hpp.

Member Function Documentation

◆ at() [1/2]

template<typename T>
const T& hipipe::index_mapper< T >::at ( const std::size_t &  idx) const
inline

Returns the value at the given index.

Exceptions
std::out_of_rangeIf the index does not exist in the mapper.

Definition at line 89 of file index_mapper.hpp.

◆ at() [2/2]

template<typename T>
std::vector<T> hipipe::index_mapper< T >::at ( const std::vector< std::size_t > &  idxs) const
inline

Returns the values at the given indexes.

Exceptions
std::out_of_rangeIf any of the indexes does not exist in the mapper.

Definition at line 101 of file index_mapper.hpp.

◆ CPP_template() [1/2]

template<typename T>
hipipe::index_mapper< T >::CPP_template ( class Rng  )
inline

Insert elements from a range to the index mapper.

If this function throws an exception, the state of the mapper is undefined.

Parameters
rngThe range of values to be inserted.
Exceptions
std::invalid_argumentif any of the elements is already present in the mapper.

Definition at line 131 of file index_mapper.hpp.

◆ CPP_template() [2/2]

template<typename T>
hipipe::index_mapper< T >::CPP_template ( class Rng  )
inline

Insert elements to index mapper while skipping duplicates.

Parameters
rngThe range of values to be inserted.

Definition at line 161 of file index_mapper.hpp.

◆ index_for() [1/2]

template<typename T>
std::vector<std::size_t> hipipe::index_mapper< T >::index_for ( const std::vector< T > &  vals) const
inline

Returns the indexes of the given values.

Exceptions
std::out_of_rangeIf any of the values does not exist.

Definition at line 68 of file index_mapper.hpp.

◆ index_for() [2/2]

template<typename T>
std::size_t hipipe::index_mapper< T >::index_for ( const T &  val) const
inline

Returns the index of the given value.

Exceptions
std::out_of_rangeIf the value does not exist.

Definition at line 50 of file index_mapper.hpp.

◆ insert()

template<typename T>
std::size_t hipipe::index_mapper< T >::insert ( val)
inline

Inserts a value into the mapper with index size()-1.

Parameters
valThe value to be inserted.
Returns
The index of the inserted value.
Exceptions
std::invalid_argumentif the element is already present in the mapper.

Definition at line 115 of file index_mapper.hpp.

◆ try_insert()

template<typename T>
bool hipipe::index_mapper< T >::try_insert ( val)
inline

Tries to insert a value into the mapper with index size()-1. If the value is already present in the mapper, the operation does nothing.

Parameters
valThe value to be inserted.
Returns
True if the value insertion was successful.

Definition at line 151 of file index_mapper.hpp.


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