alglib::bimap::bimap< type1, type2 > Class Template Reference

#include <bimap.h>

Public Types

typedef type1 domain_type
 
typedef type2 codomain_type
 
typedef boost::transform_iterator< select1st< std::pair< domain_type, int > >, typename std::map< domain_type, int >::const_iterator > domain_iterator
 
typedef boost::transform_iterator< select1st< std::pair< codomain_type, int > >, typename std::map< codomain_type, int >::const_iterator > codomain_iterator
 

Public Member Functions

 bimap ()
 
 bimap (const bimap &)=default
 
 bimap (bimap &&)
 
void insert (const type1 &elt1, const type2 &elt2)
 
const codomain_typeget_image (const domain_type &elt) const
 
const domain_typeget_preimage (const codomain_type &elt) const
 
void remove_domain_elt (const domain_type &elt)
 
void remove_codomain_elt (const codomain_type &elt)
 
domain_iterator domain_begin () const
 
domain_iterator domain_end () const
 
codomain_iterator codomain_begin () const
 
codomain_iterator codomain_end () const
 

Member Typedef Documentation

template<typename type1, typename type2>
typedef boost::transform_iterator<select1st<std::pair<codomain_type, int> >, typename std::map<codomain_type, int>::const_iterator> alglib::bimap::bimap< type1, type2 >::codomain_iterator
template<typename type1, typename type2>
typedef type2 alglib::bimap::bimap< type1, type2 >::codomain_type
template<typename type1, typename type2>
typedef boost::transform_iterator<select1st<std::pair<domain_type, int> >, typename std::map<domain_type, int>::const_iterator> alglib::bimap::bimap< type1, type2 >::domain_iterator
template<typename type1, typename type2>
typedef type1 alglib::bimap::bimap< type1, type2 >::domain_type

Constructor & Destructor Documentation

template<typename type1 , typename type2 >
alglib::bimap::bimap< type1, type2 >::bimap ( )
92  {
93  dir_entries = 0;
94 }
template<typename type1, typename type2>
alglib::bimap::bimap< type1, type2 >::bimap ( const bimap< type1, type2 > &  )
default
template<typename type1 , typename type2 >
alglib::bimap::bimap< type1, type2 >::bimap ( bimap< type1, type2 > &&  b)
98  : domain(std::move(b.domain)),
99  codomain(std::move(b.codomain)),
100  directory(std::move(b.directory)),
101  dir_entries(b.dir_entries) {}

Member Function Documentation

template<typename type1 , typename type2 >
bimap< type1, type2 >::codomain_iterator alglib::bimap::bimap< type1, type2 >::codomain_begin ( ) const
194  {
195  return boost::make_transform_iterator(codomain.begin(), get_codomain_elt);
196 }
template<typename type1 , typename type2 >
bimap< type1, type2 >::codomain_iterator alglib::bimap::bimap< type1, type2 >::codomain_end ( ) const
200  {
201  return boost::make_transform_iterator(codomain.end(), get_codomain_elt);
202 }
template<typename type1 , typename type2 >
bimap< type1, type2 >::domain_iterator alglib::bimap::bimap< type1, type2 >::domain_begin ( ) const
182  {
183  return boost::make_transform_iterator(domain.begin(), get_domain_elt);
184 }
template<typename type1 , typename type2 >
bimap< type1, type2 >::domain_iterator alglib::bimap::bimap< type1, type2 >::domain_end ( ) const
188  {
189  return boost::make_transform_iterator(domain.end(), get_domain_elt);
190 }
template<typename type1 , typename type2 >
const type2 & alglib::bimap::bimap< type1, type2 >::get_image ( const domain_type elt) const
120  {
121 
122  auto it = domain.find(elt);
123  if(it == domain.end())
124  throw std::out_of_range("The key doesn't exist");
125 
126  return (directory.at(it->second).second)->first;
127 }
template<typename type1 , typename type2 >
const type1 & alglib::bimap::bimap< type1, type2 >::get_preimage ( const codomain_type elt) const
130  {
131 
132  auto it = codomain.find(elt);
133  if(it == codomain.end())
134  throw std::out_of_range("The key doesn't exist");
135 
136  return (directory.at(it->second).first)->first;
137 }
template<typename type1, typename type2>
void alglib::bimap::bimap< type1, type2 >::insert ( const type1 &  elt1,
const type2 &  elt2 
)
104  {
105 
106  auto ret1 = domain.insert(std::make_pair(elt1, dir_entries));
107  auto ret2 = codomain.insert(std::make_pair(elt2, dir_entries));
108 
109  // check if elt1 or elt2 already existed
110  if(!ret1.second or !ret2.second)
111  throw std::domain_error("Either or both of the element already exists");
112 
113  // record it in the directory
114  directory[dir_entries] = std::make_pair(ret1.first, ret2.first);
115 
116  ++dir_entries;
117 }
template<typename type1 , typename type2 >
void alglib::bimap::bimap< type1, type2 >::remove_codomain_elt ( const codomain_type elt)
160  {
161 
162  auto codomain_it = codomain.find(elt);
163  if(codomain_it == codomain.end())
164  throw std::out_of_range("element doesn't exist");
165 
166  auto dir_entry = *directory[codomain_it->second];
167  auto it_pair = dir_entry->second;
168 
169  // Now erase the domain and codomain entry
170  domain.erase(it_pair->first);
171  codomain.erase(it_pair->second);
172 
173  // finally, delete the directory entry)
174  directory.erase(dir_entry);
175 }
template<typename type1 , typename type2 >
void alglib::bimap::bimap< type1, type2 >::remove_domain_elt ( const domain_type elt)
141  {
142 
143  auto domain_it = domain.find(elt);
144  if(domain_it == domain.end())
145  throw std::out_of_range("element doesn't exist");
146 
147  auto dir_entry = *directory[domain_it->second];
148  auto it_pair = dir_entry->second;
149 
150  // Now erase the domain and codomain entry
151  domain.erase(it_pair->first);
152  codomain.erase(it_pair->second);
153 
154  // finally, delete the directory entry)
155  directory.erase(dir_entry);
156 }

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