00001 #ifndef NMWR_GB_BIJECTIVE_MAPPING_C
00002 #define NMWR_GB_BIJECTIVE_MAPPING_C
00003
00004
00005
00006
00007 #include "Container/bijective-mapping.h"
00008
00009 template<class T1, class T2>
00010 void write_bm(bijective_mapping<T1,T2> const& m, ostream& out)
00011 {
00012 typedef typename bijective_mapping<T1,T2>::domain_type dt;
00013 typedef typename dt::const_iterator d_iter;
00014 for(d_iter x = m.domain().begin(); ! (x == m.domain().end()); ++x)
00015 out << *x << ' ' << m(*x) << '\n';
00016 }
00017
00018 template<class T1, class T2>
00019 void read_bm(bijective_mapping<T1,T2> & m, istream& in)
00020 {
00021 T1 x;
00022 T2 mx;
00023 while(in >> x >> mx) {
00024 m[x] = mx;
00025 }
00026 }
00027
00028 template<class T1, class T2>
00029 void bijective_mapping<T1,T2>::calculate_inverse() const
00030 {
00031 for(map_iterator it = the_map.begin(); !(it == the_map.end()); ++it)
00032 ((inv_table_type &)the_inverse_map)[(*it).second] = (*it).first;
00033 }
00034
00035 template<class T1, class T2>
00036 bijective_mapping<T1,T2>::bijective_mapping(inverse_mapping<T2,T1> const& inv)
00037 : the_map(inv.domain().size()),
00038 inverse_ok(false)
00039
00040 {
00041 typedef typename inverse_mapping<T2,T1>::domain_type inv_domain_type;
00042 typedef typename inv_domain_type::const_iterator ran_iter;
00043
00044 for(ran_iter x = inv.domain().begin(); !(x == inv.domain().end()); ++x)
00045 the_map[*x] = inv(*x);
00046 }
00047
00048 #endif
00049