Flow123d  master-f44eb46
Public Member Functions | Private Attributes | List of all members
BidirectionalMap< T > Class Template Reference

Bidirectional map templated by <T, unsigned int>. More...

#include <bidirectional_map.hh>

Public Member Functions

 BidirectionalMap ()
 Constructor. More...
 
unsigned int size () const
 Return size of map. More...
 
void set_item (T val, unsigned int pos)
 
unsigned int add_item (T val)
 Add new item at the end position of map. More...
 
int get_position (T val) const
 Return position of item of given value. More...
 
void clear ()
 Clear the content. Do not release memory. More...
 
void reserve (unsigned int init_size=0)
 Reset data of map, reserve space for given size. More...
 
void resize (unsigned int new_size)
 Reset data of map, reserve space for given size. More...
 
operator[] (unsigned int pos) const
 Return value on given position. More...
 

Private Attributes

std::vector< T > vals_vec_
 Space to save values. More...
 
std::unordered_map< T, unsigned int > vals_map_
 Maps values to indexes into vals_vec_. More...
 

Detailed Description

template<typename T>
class BidirectionalMap< T >

Bidirectional map templated by <T, unsigned int>.

Store pairs of value and its position (index) and allow bidirectional search. Items of both (values, positions) must be unique.

Definition at line 33 of file bidirectional_map.hh.

Constructor & Destructor Documentation

◆ BidirectionalMap()

template<typename T >
BidirectionalMap< T >::BidirectionalMap
inline

Constructor.

Definition at line 76 of file bidirectional_map.hh.

Member Function Documentation

◆ add_item()

template<typename T >
unsigned int BidirectionalMap< T >::add_item ( val)
inline

Add new item at the end position of map.

Definition at line 106 of file bidirectional_map.hh.

Here is the caller graph for this function:

◆ clear()

template<typename T >
void BidirectionalMap< T >::clear
inline

Clear the content. Do not release memory.

Definition at line 121 of file bidirectional_map.hh.

Here is the caller graph for this function:

◆ get_position()

template<typename T >
int BidirectionalMap< T >::get_position ( val) const
inline

Return position of item of given value.

Definition at line 114 of file bidirectional_map.hh.

Here is the caller graph for this function:

◆ operator[]()

template<typename T >
T BidirectionalMap< T >::operator[] ( unsigned int  pos) const
inline

Return value on given position.

Definition at line 145 of file bidirectional_map.hh.

◆ reserve()

template<typename T >
void BidirectionalMap< T >::reserve ( unsigned int  init_size = 0)
inline

Reset data of map, reserve space for given size.

Definition at line 139 of file bidirectional_map.hh.

Here is the caller graph for this function:

◆ resize()

template<typename T >
void BidirectionalMap< T >::resize ( unsigned int  new_size)
inline

Reset data of map, reserve space for given size.

Resizes to given new_size if new size is smaller than the actual. The rest of data are thrown away and removed from the map.

Definition at line 128 of file bidirectional_map.hh.

◆ set_item()

template<typename T >
void BidirectionalMap< T >::set_item ( val,
unsigned int  pos 
)
inline

Set value of given position.

Position must be in interval set in reinit method <0, init_size-1>. Element on every position can be set only once.

Definition at line 86 of file bidirectional_map.hh.

◆ size()

template<typename T >
unsigned int BidirectionalMap< T >::size
inline

Return size of map.

Definition at line 80 of file bidirectional_map.hh.

Member Data Documentation

◆ vals_map_

template<typename T >
std::unordered_map<T, unsigned int> BidirectionalMap< T >::vals_map_
private

Maps values to indexes into vals_vec_.

Definition at line 71 of file bidirectional_map.hh.

◆ vals_vec_

template<typename T >
std::vector<T> BidirectionalMap< T >::vals_vec_
private

Space to save values.

Definition at line 70 of file bidirectional_map.hh.


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