ShiftMap and ScaleMap added
authoralpar
Tue, 11 Jan 2005 09:05:24 +0000
changeset 10706aa1520a0f2f
parent 1069 7b81a36809c6
child 1071 7c70fc1b2d8b
ShiftMap and ScaleMap added
src/lemon/maps.h
src/test/maps_test.cc
     1.1 --- a/src/lemon/maps.h	Tue Jan 11 09:04:08 2005 +0000
     1.2 +++ b/src/lemon/maps.h	Tue Jan 11 09:05:24 2005 +0000
     1.3 @@ -212,6 +212,50 @@
     1.4      return AddMap<M1,M2>(m1,m2);
     1.5    }
     1.6  
     1.7 +  ///Shift a maps with a constant.
     1.8 +
     1.9 +  ///This \ref concept::ReadMap "read only map" returns the sum of the
    1.10 +  ///given map and a constant value.
    1.11 +  ///Its \c Key and \c Value is inherited from \c M.
    1.12 +  ///
    1.13 +  ///Actually,
    1.14 +  ///\code
    1.15 +  ///  ShiftMap<X> sh(x,v);
    1.16 +  ///\endcode
    1.17 +  ///it is equivalent with
    1.18 +  ///\code
    1.19 +  ///  ConstMap<X::Key, X::Value> c_tmp(v);
    1.20 +  ///  AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
    1.21 +  ///\endcode
    1.22 +  template<class M> 
    1.23 +  class ShiftMap
    1.24 +  {
    1.25 +    const M &m;
    1.26 +    typename M::Value v;
    1.27 +  public:
    1.28 +    typedef typename M::Key Key;
    1.29 +    typedef typename M::Value Value;
    1.30 +
    1.31 +    ///Constructor
    1.32 +
    1.33 +    ///Constructor
    1.34 +    ///\param _m is the undelying map
    1.35 +    ///\param _v is the shift value
    1.36 +    ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
    1.37 +    Value operator[](Key k) const {return m[k]+v;}
    1.38 +  };
    1.39 +  
    1.40 +  ///Returns an \ref ShiftMap class
    1.41 +
    1.42 +  ///This function just returns an \ref ShiftMap class.
    1.43 +  ///\relates ShiftMap
    1.44 +  ///\todo A better name is required.
    1.45 +  template<class M> 
    1.46 +  inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v) 
    1.47 +  {
    1.48 +    return ShiftMap<M>(m,v);
    1.49 +  }
    1.50 +
    1.51    ///Difference of two maps
    1.52  
    1.53    ///This \ref concept::ReadMap "read only map" returns the difference
    1.54 @@ -282,6 +326,50 @@
    1.55      return MulMap<M1,M2>(m1,m2);
    1.56    }
    1.57   
    1.58 +  ///Scale a maps with a constant.
    1.59 +
    1.60 +  ///This \ref concept::ReadMap "read only map" returns the value of the
    1.61 +  ///given map multipied with a constant value.
    1.62 +  ///Its \c Key and \c Value is inherited from \c M.
    1.63 +  ///
    1.64 +  ///Actually,
    1.65 +  ///\code
    1.66 +  ///  ScaleMap<X> sc(x,v);
    1.67 +  ///\endcode
    1.68 +  ///it is equivalent with
    1.69 +  ///\code
    1.70 +  ///  ConstMap<X::Key, X::Value> c_tmp(v);
    1.71 +  ///  MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
    1.72 +  ///\endcode
    1.73 +  template<class M> 
    1.74 +  class ScaleMap
    1.75 +  {
    1.76 +    const M &m;
    1.77 +    typename M::Value v;
    1.78 +  public:
    1.79 +    typedef typename M::Key Key;
    1.80 +    typedef typename M::Value Value;
    1.81 +
    1.82 +    ///Constructor
    1.83 +
    1.84 +    ///Constructor
    1.85 +    ///\param _m is the undelying map
    1.86 +    ///\param _v is the scaling value
    1.87 +    ScaleMap(const M &_m,const Value &_v ) : m(_m), v(_v) {};
    1.88 +    Value operator[](Key k) const {return m[k]*v;}
    1.89 +  };
    1.90 +  
    1.91 +  ///Returns an \ref ScaleMap class
    1.92 +
    1.93 +  ///This function just returns an \ref ScaleMap class.
    1.94 +  ///\relates ScaleMap
    1.95 +  ///\todo A better name is required.
    1.96 +  template<class M> 
    1.97 +  inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v) 
    1.98 +  {
    1.99 +    return ScaleMap<M>(m,v);
   1.100 +  }
   1.101 +
   1.102    ///Quotient of two maps
   1.103  
   1.104    ///This \ref concept::ReadMap "read only map" returns the quotient of the
     2.1 --- a/src/test/maps_test.cc	Tue Jan 11 09:04:08 2005 +0000
     2.2 +++ b/src/test/maps_test.cc	Tue Jan 11 09:05:24 2005 +0000
     2.3 @@ -26,6 +26,8 @@
     2.4    checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
     2.5    checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
     2.6    checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
     2.7 +  checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
     2.8 +  checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
     2.9    
    2.10    checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
    2.11