# HG changeset patch # User alpar # Date 1105434324 0 # Node ID 6aa1520a0f2f921c124d6395f13514839d0e53d3 # Parent 7b81a36809c681c3df87d49e1f37e02eff2685ef ShiftMap and ScaleMap added diff -r 7b81a36809c6 -r 6aa1520a0f2f src/lemon/maps.h --- a/src/lemon/maps.h Tue Jan 11 09:04:08 2005 +0000 +++ b/src/lemon/maps.h Tue Jan 11 09:05:24 2005 +0000 @@ -212,6 +212,50 @@ return AddMap(m1,m2); } + ///Shift a maps with a constant. + + ///This \ref concept::ReadMap "read only map" returns the sum of the + ///given map and a constant value. + ///Its \c Key and \c Value is inherited from \c M. + /// + ///Actually, + ///\code + /// ShiftMap sh(x,v); + ///\endcode + ///it is equivalent with + ///\code + /// ConstMap c_tmp(v); + /// AddMap > sh(x,v); + ///\endcode + template + class ShiftMap + { + const M &m; + typename M::Value v; + public: + typedef typename M::Key Key; + typedef typename M::Value Value; + + ///Constructor + + ///Constructor + ///\param _m is the undelying map + ///\param _v is the shift value + ShiftMap(const M &_m,const Value &_v ) : m(_m), v(_v) {}; + Value operator[](Key k) const {return m[k]+v;} + }; + + ///Returns an \ref ShiftMap class + + ///This function just returns an \ref ShiftMap class. + ///\relates ShiftMap + ///\todo A better name is required. + template + inline ShiftMap shiftMap(const M &m,const typename M::Value &v) + { + return ShiftMap(m,v); + } + ///Difference of two maps ///This \ref concept::ReadMap "read only map" returns the difference @@ -282,6 +326,50 @@ return MulMap(m1,m2); } + ///Scale a maps with a constant. + + ///This \ref concept::ReadMap "read only map" returns the value of the + ///given map multipied with a constant value. + ///Its \c Key and \c Value is inherited from \c M. + /// + ///Actually, + ///\code + /// ScaleMap sc(x,v); + ///\endcode + ///it is equivalent with + ///\code + /// ConstMap c_tmp(v); + /// MulMap > sc(x,v); + ///\endcode + template + class ScaleMap + { + const M &m; + typename M::Value v; + public: + typedef typename M::Key Key; + typedef typename M::Value Value; + + ///Constructor + + ///Constructor + ///\param _m is the undelying map + ///\param _v is the scaling value + ScaleMap(const M &_m,const Value &_v ) : m(_m), v(_v) {}; + Value operator[](Key k) const {return m[k]*v;} + }; + + ///Returns an \ref ScaleMap class + + ///This function just returns an \ref ScaleMap class. + ///\relates ScaleMap + ///\todo A better name is required. + template + inline ScaleMap scaleMap(const M &m,const typename M::Value &v) + { + return ScaleMap(m,v); + } + ///Quotient of two maps ///This \ref concept::ReadMap "read only map" returns the quotient of the diff -r 7b81a36809c6 -r 6aa1520a0f2f src/test/maps_test.cc --- a/src/test/maps_test.cc Tue Jan 11 09:04:08 2005 +0000 +++ b/src/test/maps_test.cc Tue Jan 11 09:05:24 2005 +0000 @@ -26,6 +26,8 @@ checkConcept, DivMap >(); checkConcept, NegMap >(); checkConcept, AbsMap >(); + checkConcept, ShiftMap >(); + checkConcept, ScaleMap >(); checkConcept, ComposeMap > >();