# HG changeset patch # User marci # Date 1095702813 0 # Node ID 3a48bc350e0f0c7d71111c417f6fa25c40563cbd # Parent 47bb9b8f57056e11eadbe9c6b926e34fe8113a11 Specialized ConstMap for defining constant maps at compile time, by klao. Time comparision of the generic and specialized maps. diff -r 47bb9b8f5705 -r 3a48bc350e0f src/hugo/maps.h --- a/src/hugo/maps.h Mon Sep 20 16:20:11 2004 +0000 +++ b/src/hugo/maps.h Mon Sep 20 17:53:33 2004 +0000 @@ -76,7 +76,21 @@ ConstMap(const ConstMap &, const T &_v) : v(_v) {} }; - + //to document later + template + struct Const { }; + //to document later + template + class ConstMap > : public MapBase + { + public: + ConstMap() { } + V operator[](const K&) const { return v; } + void set(const K&, const V&) { } + }; + //to document later + typedef Const True; + typedef Const False; /// \c std::map wrapper diff -r 47bb9b8f5705 -r 3a48bc350e0f src/work/marci/const_map_time.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/work/marci/const_map_time.cc Mon Sep 20 17:53:33 2004 +0000 @@ -0,0 +1,46 @@ +// Use a DIMACS max flow file as stdin. +// const_map_time < dimacs_max_flow_file + +#include + +#include +#include +#include +#include +#include + +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 cap; + readDimacs(std::cin, g, cap, s, t); + //typedef ConstMap > CN1; CN1 cn1; + typedef ConstMap CN1; CN1 cn1; + typedef ConstMap CN2; CN2 cn2(true); + // typedef ConstMap > CE1; CE1 ce1; + typedef ConstMap CE1; CE1 ce1; + typedef ConstMap CE2; CE2 ce2(true); + typedef SubGraphWrapper SB1; SB1 sb1(g, cn1, ce1); + typedef SubGraphWrapper 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; +}