src/lemon/maps.h
changeset 1071 7c70fc1b2d8b
parent 1044 f97380557656
child 1076 67a115cdade4
equal deleted inserted replaced
5:ba16ff845c08 6:f814174df912
   210   inline AddMap<M1,M2> addMap(const M1 &m1,const M2 &m2) 
   210   inline AddMap<M1,M2> addMap(const M1 &m1,const M2 &m2) 
   211   {
   211   {
   212     return AddMap<M1,M2>(m1,m2);
   212     return AddMap<M1,M2>(m1,m2);
   213   }
   213   }
   214 
   214 
       
   215   ///Shift a maps with a constant.
       
   216 
       
   217   ///This \ref concept::ReadMap "read only map" returns the sum of the
       
   218   ///given map and a constant value.
       
   219   ///Its \c Key and \c Value is inherited from \c M.
       
   220   ///
       
   221   ///Actually,
       
   222   ///\code
       
   223   ///  ShiftMap<X> sh(x,v);
       
   224   ///\endcode
       
   225   ///it is equivalent with
       
   226   ///\code
       
   227   ///  ConstMap<X::Key, X::Value> c_tmp(v);
       
   228   ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
       
   229   ///\endcode
       
   230   template<class M> 
       
   231   class ShiftMap
       
   232   {
       
   233     const M &m;
       
   234     typename M::Value v;
       
   235   public:
       
   236     typedef typename M::Key Key;
       
   237     typedef typename M::Value Value;
       
   238 
       
   239     ///Constructor
       
   240 
       
   241     ///Constructor
       
   242     ///\param _m is the undelying map
       
   243     ///\param _v is the shift value
       
   244     ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
       
   245     Value operator[](Key k) const {return m[k]+v;}
       
   246   };
       
   247   
       
   248   ///Returns an \ref ShiftMap class
       
   249 
       
   250   ///This function just returns an \ref ShiftMap class.
       
   251   ///\relates ShiftMap
       
   252   ///\todo A better name is required.
       
   253   template<class M> 
       
   254   inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v) 
       
   255   {
       
   256     return ShiftMap<M>(m,v);
       
   257   }
       
   258 
   215   ///Difference of two maps
   259   ///Difference of two maps
   216 
   260 
   217   ///This \ref concept::ReadMap "read only map" returns the difference
   261   ///This \ref concept::ReadMap "read only map" returns the difference
   218   ///of the values returned by the two
   262   ///of the values returned by the two
   219   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   263   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   280   inline MulMap<M1,M2> mulMap(const M1 &m1,const M2 &m2) 
   324   inline MulMap<M1,M2> mulMap(const M1 &m1,const M2 &m2) 
   281   {
   325   {
   282     return MulMap<M1,M2>(m1,m2);
   326     return MulMap<M1,M2>(m1,m2);
   283   }
   327   }
   284  
   328  
       
   329   ///Scale a maps with a constant.
       
   330 
       
   331   ///This \ref concept::ReadMap "read only map" returns the value of the
       
   332   ///given map multipied with a constant value.
       
   333   ///Its \c Key and \c Value is inherited from \c M.
       
   334   ///
       
   335   ///Actually,
       
   336   ///\code
       
   337   ///  ScaleMap<X> sc(x,v);
       
   338   ///\endcode
       
   339   ///it is equivalent with
       
   340   ///\code
       
   341   ///  ConstMap<X::Key, X::Value> c_tmp(v);
       
   342   ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
       
   343   ///\endcode
       
   344   template<class M> 
       
   345   class ScaleMap
       
   346   {
       
   347     const M &m;
       
   348     typename M::Value v;
       
   349   public:
       
   350     typedef typename M::Key Key;
       
   351     typedef typename M::Value Value;
       
   352 
       
   353     ///Constructor
       
   354 
       
   355     ///Constructor
       
   356     ///\param _m is the undelying map
       
   357     ///\param _v is the scaling value
       
   358     ScaleMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
       
   359     Value operator[](Key k) const {return m[k]*v;}
       
   360   };
       
   361   
       
   362   ///Returns an \ref ScaleMap class
       
   363 
       
   364   ///This function just returns an \ref ScaleMap class.
       
   365   ///\relates ScaleMap
       
   366   ///\todo A better name is required.
       
   367   template<class M> 
       
   368   inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v) 
       
   369   {
       
   370     return ScaleMap<M>(m,v);
       
   371   }
       
   372 
   285   ///Quotient of two maps
   373   ///Quotient of two maps
   286 
   374 
   287   ///This \ref concept::ReadMap "read only map" returns the quotient of the
   375   ///This \ref concept::ReadMap "read only map" returns the quotient of the
   288   ///values returned by the two
   376   ///values returned by the two
   289   ///given maps. Its \c Key and \c Value will be inherited from \c M1.
   377   ///given maps. Its \c Key and \c Value will be inherited from \c M1.