[Lemon-commits] [lemon_svn] marci: r1198 - in hugo/trunk/src: hugo work/marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:43:49 CET 2006
Author: marci
Date: Mon Sep 20 19:53:33 2004
New Revision: 1198
Added:
hugo/trunk/src/work/marci/const_map_time.cc
Modified:
hugo/trunk/src/hugo/maps.h
Log:
Specialized ConstMap for defining constant maps at compile time, by klao.
Time comparision of the generic and specialized maps.
Modified: hugo/trunk/src/hugo/maps.h
==============================================================================
--- hugo/trunk/src/hugo/maps.h (original)
+++ hugo/trunk/src/hugo/maps.h Mon Sep 20 19:53:33 2004
@@ -76,7 +76,21 @@
ConstMap(const ConstMap<K,T1> &, const T &_v) : v(_v) {}
};
-
+ //to document later
+ template<typename T, T v>
+ struct Const { };
+ //to document later
+ template<typename K, typename V, V v>
+ class ConstMap<K, Const<V, v> > : public MapBase<K, V>
+ {
+ public:
+ ConstMap() { }
+ V operator[](const K&) const { return v; }
+ void set(const K&, const V&) { }
+ };
+ //to document later
+ typedef Const<bool, true> True;
+ typedef Const<bool, false> False;
/// \c std::map wrapper
Added: hugo/trunk/src/work/marci/const_map_time.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/marci/const_map_time.cc Mon Sep 20 19:53:33 2004
@@ -0,0 +1,46 @@
+// Use a DIMACS max flow file as stdin.
+// const_map_time < dimacs_max_flow_file
+
+#include <iostream>
+
+#include <hugo/maps.h>
+#include <hugo/smart_graph.h>
+#include <hugo/time_measure.h>
+#include <hugo/dimacs.h>
+#include <hugo/graph_wrapper.h>
+
+using namespace hugo;
+
+int main() {
+
+ typedef SmartGraph Graph;
+ typedef Graph::Node Node;
+ typedef Graph::Edge Edge;
+ typedef Graph::EdgeIt EdgeIt;
+
+ Graph g;
+
+ Node s, t;
+ NullMap<Edge, int> cap;
+ readDimacs(std::cin, g, cap, s, t);
+ //typedef ConstMap<Node, Bool<true> > CN1; CN1 cn1;
+ typedef ConstMap<Node, True> CN1; CN1 cn1;
+ typedef ConstMap<Node, bool> CN2; CN2 cn2(true);
+ // typedef ConstMap<Edge, Bool<true> > CE1; CE1 ce1;
+ typedef ConstMap<Edge, True> CE1; CE1 ce1;
+ typedef ConstMap<Edge, bool> CE2; CE2 ce2(true);
+ typedef SubGraphWrapper<Graph, CN1, CE1> SB1; SB1 sb1(g, cn1, ce1);
+ typedef SubGraphWrapper<Graph, CN2, CE2> SB2; SB2 sb2(g, cn2, ce2);
+ Timer ts;
+ cout << "specialized (compile-time) const map time:" << endl;
+ ts.reset();
+ for (SB1::NodeIt n(sb1); n!=INVALID; ++n)
+ for (SB1::EdgeIt e(sb1); e!=INVALID; ++e) { }
+ cout << ts << endl;
+ ts.reset();
+ cout << "generic const map time:" << endl;
+ for (SB2::NodeIt n(sb2); n!=INVALID; ++n)
+ for (SB2::EdgeIt e(sb2); e!=INVALID; ++e) { }
+ cout << ts << endl;
+ return 0;
+}
More information about the Lemon-commits
mailing list