lemon/maps.h
changeset 1536 308150155bb5
parent 1531 a3b20dd847b5
child 1537 0d9f1a71be27
equal deleted inserted replaced
3:eef567aeae13 4:5c386d44c23a
   225 
   225 
   226   ///This \ref concept::ReadMap "read only map"
   226   ///This \ref concept::ReadMap "read only map"
   227   ///converts the \c Value of a maps to type \c T.
   227   ///converts the \c Value of a maps to type \c T.
   228   ///Its \c Value is inherited from \c M.
   228   ///Its \c Value is inherited from \c M.
   229   ///
   229   ///
   230   ///Actually,
       
   231   ///\code
       
   232   ///  ConvertMap<X> sh(x,v);
       
   233   ///\endcode
       
   234   ///it is equivalent with
       
   235   ///\code
       
   236   ///  ConstMap<X::Key, X::Value> c_tmp(v);
       
   237   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
       
   238   ///\endcode
       
   239   ///\bug wrong documentation
   230   ///\bug wrong documentation
   240   template<class M, class T> 
   231   template<class M, class T> 
   241   class ConvertMap {
   232   class ConvertMap {
   242     typename SmartConstReference<M>::Type m;
   233     typename SmartConstReference<M>::Type m;
   243   public:
   234   public:
   250     typedef T Value;
   241     typedef T Value;
   251 
   242 
   252     ///Constructor
   243     ///Constructor
   253 
   244 
   254     ///Constructor
   245     ///Constructor
   255     ///\param _m is the undelying map
   246     ///\param _m is the underlying map
   256     ///\param _v is the convert value
       
   257     ConvertMap(const M &_m) : m(_m) {};
   247     ConvertMap(const M &_m) : m(_m) {};
   258 
   248 
   259     /// \brief The subscript operator.
   249     /// \brief The subscript operator.
   260     ///
   250     ///
   261     /// The subscript operator.
   251     /// The subscript operator.
   262     /// \param edge The edge 
   252     /// \param k The key
   263     /// \return The target of the edge 
   253     /// \return The target of the edge 
   264     Value operator[](Key k) const {return m[k];}
   254     Value operator[](Key k) const {return m[k];}
   265   };
   255   };
   266   
   256   
   267   ///Returns an \ref ConvertMap class
   257   ///Returns an \ref ConvertMap class
   295     typedef typename M1::Key Key;
   285     typedef typename M1::Key Key;
   296     ///\e
   286     ///\e
   297     typedef typename M1::Value Value;
   287     typedef typename M1::Value Value;
   298 
   288 
   299     ///Constructor
   289     ///Constructor
   300 
       
   301     ///\e
       
   302     ///
       
   303     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   290     AddMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   304     Value operator[](Key k) const {return m1[k]+m2[k];}
   291     Value operator[](Key k) const {return m1[k]+m2[k];}
   305   };
   292   };
   306   
   293   
   307   ///Returns an \ref AddMap class
   294   ///Returns an \ref AddMap class
   384     typedef typename M1::Key Key;
   371     typedef typename M1::Key Key;
   385     ///\e
   372     ///\e
   386     typedef typename M1::Value Value;
   373     typedef typename M1::Value Value;
   387 
   374 
   388     ///Constructor
   375     ///Constructor
   389 
       
   390     ///\e
       
   391     ///
       
   392     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   376     SubMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   393     Value operator[](Key k) const {return m1[k]-m2[k];}
   377     Value operator[](Key k) const {return m1[k]-m2[k];}
   394   };
   378   };
   395   
   379   
   396   ///Returns a \ref SubMap class
   380   ///Returns a \ref SubMap class
   424     typedef typename M1::Key Key;
   408     typedef typename M1::Key Key;
   425     ///\e
   409     ///\e
   426     typedef typename M1::Value Value;
   410     typedef typename M1::Value Value;
   427 
   411 
   428     ///Constructor
   412     ///Constructor
   429 
       
   430     ///\e
       
   431     ///
       
   432     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   413     MulMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   433     Value operator[](Key k) const {return m1[k]*m2[k];}
   414     Value operator[](Key k) const {return m1[k]*m2[k];}
   434   };
   415   };
   435   
   416   
   436   ///Returns a \ref MulMap class
   417   ///Returns a \ref MulMap class
   510     typedef typename M1::Key Key;
   491     typedef typename M1::Key Key;
   511     ///\e
   492     ///\e
   512     typedef typename M1::Value Value;
   493     typedef typename M1::Value Value;
   513 
   494 
   514     ///Constructor
   495     ///Constructor
   515 
       
   516     ///\e
       
   517     ///
       
   518     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   496     DivMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   519     Value operator[](Key k) const {return m1[k]/m2[k];}
   497     Value operator[](Key k) const {return m1[k]/m2[k];}
   520   };
   498   };
   521   
   499   
   522   ///Returns a \ref DivMap class
   500   ///Returns a \ref DivMap class
   558     typedef typename M2::Key Key;
   536     typedef typename M2::Key Key;
   559     ///\e
   537     ///\e
   560     typedef typename M1::Value Value;
   538     typedef typename M1::Value Value;
   561 
   539 
   562     ///Constructor
   540     ///Constructor
   563 
       
   564     ///\e
       
   565     ///
       
   566     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   541     ComposeMap(const M1 &_m1,const M2 &_m2) : m1(_m1), m2(_m2) {};
   567     Value operator[](Key k) const {return m1[m2[k]];}
   542     Value operator[](Key k) const {return m1[m2[k]];}
   568   };
   543   };
   569   ///Returns a \ref ComposeMap class
   544   ///Returns a \ref ComposeMap class
   570 
   545 
   613     typedef typename M1::Key Key;
   588     typedef typename M1::Key Key;
   614     ///\e
   589     ///\e
   615     typedef V Value;
   590     typedef V Value;
   616 
   591 
   617     ///Constructor
   592     ///Constructor
   618 
       
   619     ///\e
       
   620     ///
       
   621     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   593     CombineMap(const M1 &_m1,const M2 &_m2,const F &_f)
   622       : m1(_m1), m2(_m2), f(_f) {};
   594       : m1(_m1), m2(_m2), f(_f) {};
   623     Value operator[](Key k) const {return f(m1[k],m2[k]);}
   595     Value operator[](Key k) const {return f(m1[k],m2[k]);}
   624   };
   596   };
   625   
   597   
   664     typedef typename M::Key Key;
   636     typedef typename M::Key Key;
   665     ///\e
   637     ///\e
   666     typedef typename M::Value Value;
   638     typedef typename M::Value Value;
   667 
   639 
   668     ///Constructor
   640     ///Constructor
   669 
       
   670     ///\e
       
   671     ///
       
   672     NegMap(const M &_m) : m(_m) {};
   641     NegMap(const M &_m) : m(_m) {};
   673     Value operator[](Key k) const {return -m[k];}
   642     Value operator[](Key k) const {return -m[k];}
   674   };
   643   };
   675   
   644   
   676   ///Returns a \ref NegMap class
   645   ///Returns a \ref NegMap class
   718     typedef typename M::Key Key;
   687     typedef typename M::Key Key;
   719     ///\e
   688     ///\e
   720     typedef typename M::Value Value;
   689     typedef typename M::Value Value;
   721 
   690 
   722     ///Constructor
   691     ///Constructor
   723 
       
   724     ///\e
       
   725     ///
       
   726     AbsMap(const M &_m) : m(_m) {};
   692     AbsMap(const M &_m) : m(_m) {};
   727     Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
   693     Value operator[](Key k) const {Value tmp=m[k]; return tmp>=0?tmp:-tmp;}
   728   };
   694   };
   729   
   695   
   730   ///Returns a \ref AbsMap class
   696   ///Returns a \ref AbsMap class
   761     typedef K Key;
   727     typedef K Key;
   762     ///\e
   728     ///\e
   763     typedef V Value;
   729     typedef V Value;
   764 
   730 
   765     ///Constructor
   731     ///Constructor
   766 
       
   767     ///\e
       
   768     ///
       
   769     FunctorMap(const F &_f) : f(_f) {};
   732     FunctorMap(const F &_f) : f(_f) {};
   770     Value operator[](Key k) const {return f(k);}
   733     Value operator[](Key k) const {return f(k);}
   771   };
   734   };
   772   
   735   
   773   ///Returns a \ref FunctorMap class
   736   ///Returns a \ref FunctorMap class