Provides a bidirectional access from values to their indices in an std::vector.
More...
#include <hipipe/core/index_mapper.hpp>
|
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.
|
|
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.
◆ index_mapper()
template<typename T>
template<typename Rng >
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.
◆ at() [1/2]
Returns the value at the given index.
- Exceptions
-
std::out_of_range | If the index does not exist in the mapper. |
Definition at line 89 of file index_mapper.hpp.
◆ at() [2/2]
Returns the values at the given indexes.
- Exceptions
-
std::out_of_range | If any of the indexes does not exist in the mapper. |
Definition at line 101 of file index_mapper.hpp.
◆ CPP_template() [1/2]
Insert elements from a range to the index mapper.
If this function throws an exception, the state of the mapper is undefined.
- Parameters
-
rng | The range of values to be inserted. |
- Exceptions
-
std::invalid_argument | if any of the elements is already present in the mapper. |
Definition at line 131 of file index_mapper.hpp.
◆ CPP_template() [2/2]
Insert elements to index mapper while skipping duplicates.
- Parameters
-
rng | The 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_range | If any of the values does not exist. |
Definition at line 68 of file index_mapper.hpp.
◆ index_for() [2/2]
Returns the index of the given value.
- Exceptions
-
std::out_of_range | If the value does not exist. |
Definition at line 50 of file index_mapper.hpp.
◆ insert()
Inserts a value into the mapper with index size()-1.
- Parameters
-
val | The value to be inserted. |
- Returns
- The index of the inserted value.
- Exceptions
-
std::invalid_argument | if the element is already present in the mapper. |
Definition at line 115 of file index_mapper.hpp.
◆ try_insert()
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
-
val | The 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: