Flow123d
release_3.0.0-973-g92f55e826
|
Go to the documentation of this file.
18 #ifndef BIDIRECTIONAL_MAP_HH_
19 #define BIDIRECTIONAL_MAP_HH_
40 unsigned int size()
const;
48 void set_item(T val,
unsigned int pos);
57 void reinit(
unsigned int init_size = 0);
61 void resize(
unsigned int new_size);
78 return vals_map_.size();
83 ASSERT_LT_DBG( pos, vals_vec_.size() )(pos)(vals_vec_.size()).error(
"Value id is out of vector size.");
96 ASSERT( vals_map_.find(val) == vals_map_.end() )(val).error(
"Can not add item since it already exists.");
97 vals_map_[val] = vals_vec_.size();
98 vals_vec_.push_back(val);
99 return vals_map_[val];
105 if (iter == vals_map_.end())
return -1;
106 else return iter->second;
113 vals_vec_.resize(init_size, -1);
121 for(
uint pos = new_size; pos < vals_vec_.size(); pos++){
122 vals_map_.erase(vals_vec_[pos]);
124 vals_vec_.resize(new_size);
125 ASSERT_DBG(vals_vec_.size() == vals_map_.size())(vals_vec_.size())(vals_map_.size());
130 ASSERT( pos < vals_vec_.size() )(pos)(vals_vec_.size());
131 return vals_vec_[pos];
135 #endif // BIDIRECTIONAL_MAP_HH_
Bidirectional map templated by <T, unsigned int>.
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library.
int get_position(T val) const
Return position of item of given value.
void reinit(unsigned int init_size=0)
Reset data of map, allow reserve size.
std::map< T, unsigned int > vals_map_
Maps values to indexes into vals_vec_.
std::vector< T > vals_vec_
Space to save values.
void resize(unsigned int new_size)
Reset data of map, reserve space for given size.
T operator[](unsigned int pos) const
Return value on given position.
#define ASSERT_LT_DBG(a, b)
Definition of comparative assert macro (Less Than) only for debug mode.
void set_item(T val, unsigned int pos)
unsigned int add_item(T val)
Add new item at the end position of map.
BidirectionalMap()
Constructor.
unsigned int size() const
Return size of map.