[Lemon-commits] [lemon_svn] alpar: r1466 - in hugo/trunk/src: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:45:40 CET 2006
Author: alpar
Date: Tue Jan 11 10:05:24 2005
New Revision: 1466
Modified:
hugo/trunk/src/lemon/maps.h
hugo/trunk/src/test/maps_test.cc
Log:
ShiftMap and ScaleMap added
Modified: hugo/trunk/src/lemon/maps.h
==============================================================================
--- hugo/trunk/src/lemon/maps.h (original)
+++ hugo/trunk/src/lemon/maps.h Tue Jan 11 10:05:24 2005
@@ -212,6 +212,50 @@
return AddMap<M1,M2>(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<X> sh(x,v);
+ ///\endcode
+ ///it is equivalent with
+ ///\code
+ /// ConstMap<X::Key, X::Value> c_tmp(v);
+ /// AddMap<X, ConstMap<X::Key, X::Value> > sh(x,v);
+ ///\endcode
+ template<class M>
+ 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<class M>
+ inline ShiftMap<M> shiftMap(const M &m,const typename M::Value &v)
+ {
+ return ShiftMap<M>(m,v);
+ }
+
///Difference of two maps
///This \ref concept::ReadMap "read only map" returns the difference
@@ -282,6 +326,50 @@
return MulMap<M1,M2>(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<X> sc(x,v);
+ ///\endcode
+ ///it is equivalent with
+ ///\code
+ /// ConstMap<X::Key, X::Value> c_tmp(v);
+ /// MulMap<X, ConstMap<X::Key, X::Value> > sc(x,v);
+ ///\endcode
+ template<class M>
+ 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<class M>
+ inline ScaleMap<M> scaleMap(const M &m,const typename M::Value &v)
+ {
+ return ScaleMap<M>(m,v);
+ }
+
///Quotient of two maps
///This \ref concept::ReadMap "read only map" returns the quotient of the
Modified: hugo/trunk/src/test/maps_test.cc
==============================================================================
--- hugo/trunk/src/test/maps_test.cc (original)
+++ hugo/trunk/src/test/maps_test.cc Tue Jan 11 10:05:24 2005
@@ -26,6 +26,8 @@
checkConcept<ReadMap<A,double>, DivMap<DoubleMap,DoubleMap> >();
checkConcept<ReadMap<A,double>, NegMap<DoubleMap> >();
checkConcept<ReadMap<A,double>, AbsMap<DoubleMap> >();
+ checkConcept<ReadMap<A,double>, ShiftMap<DoubleMap> >();
+ checkConcept<ReadMap<A,double>, ScaleMap<DoubleMap> >();
checkConcept<ReadMap<B,double>, ComposeMap<DoubleMap,ReadMap<B,A> > >();
More information about the Lemon-commits
mailing list