# HG changeset patch # User beckerjc # Date 1082238648 0 # Node ID 4b89077ab715d8e9ce87af7675de25bf1f229462 # Parent 01fb9da7a3633fd75b9bf8bedb94488724e82fb5 A successful work-around for using const map reference as an output parameter to Kruskal(). diff -r 01fb9da7a363 -r 4b89077ab715 src/work/johanna/kruskal.h --- a/src/work/johanna/kruskal.h Sat Apr 17 19:54:04 2004 +0000 +++ b/src/work/johanna/kruskal.h Sat Apr 17 21:50:48 2004 +0000 @@ -37,6 +37,29 @@ return tot_cost; } + /* A work-around for running Kruskal with const-reference bool maps... */ + + template + class NonConstMapWr { + const Map &m; + public: + typedef typename Map::ValueType ValueType; + + NonConstMapWr(const Map &_m) : m(_m) {} + + template + void set(KeyType const& k, ValueType const &v) const { m.set(k,v); } + }; + + template + inline + typename InputEdgeOrder::ValueType + Kruskal(Graph const& G, InputEdgeOrder const& edges, + OutBoolMap const& out_map) + { + NonConstMapWr map_wr(out_map); + return Kruskal(G, edges, map_wr); + } /* ** ** Output-objektumok: egyszeruen extra bool mapek ** ** */ @@ -49,7 +72,7 @@ template class SequenceOutput { - Iterator it; + mutable Iterator it; public: typedef bool ValueType; @@ -57,7 +80,7 @@ SequenceOutput(Iterator const &_it) : it(_it) {} template - void set(KeyType const& k, bool v) { if(v) {*it=k; ++it;} } + void set(KeyType const& k, bool v) const { if(v) {*it=k; ++it;} } }; template @@ -177,6 +200,7 @@ /// \brief Wrapper to Kruskal(). /// Input is from an EdgeMap, output is a plain boolmap. template + inline typename EdgeCostMap::ValueType Kruskal_EdgeCostMapIn_BoolMapOut(Graph const& G, EdgeCostMap const& edge_costs, @@ -193,6 +217,7 @@ /// \brief Wrapper to Kruskal(). /// Input is from an EdgeMap, output is to a sequence. template + inline typename EdgeCostMap::ValueType Kruskal_EdgeCostMapIn_IteratorOut(Graph const& G, EdgeCostMap const& edge_costs, diff -r 01fb9da7a363 -r 4b89077ab715 src/work/johanna/kruskal_test.cc --- a/src/work/johanna/kruskal_test.cc Sat Apr 17 19:54:04 2004 +0000 +++ b/src/work/johanna/kruskal_test.cc Sat Apr 17 21:50:48 2004 +0000 @@ -100,12 +100,18 @@ } tree_edge_vec.clear(); - SequenceOutput< back_insert_iterator< vector > > - vec_filler(back_inserter(tree_edge_vec)); +// SequenceOutput< back_insert_iterator< vector > > +// vec_filler(back_inserter(tree_edge_vec)); +// cout << "Nemkonst koltseggel tarhatekonyabban: " +// << Kruskal(G, +// KruskalMapVec(G, edge_cost_map), +// vec_filler) +// << endl; cout << "Nemkonst koltseggel tarhatekonyabban: " << Kruskal(G, KruskalMapVec(G, edge_cost_map), - vec_filler) + makeSequenceOutput(back_inserter(tree_edge_vec)) + ) << endl; i = 1;