[Lemon-commits] [lemon_svn] beckerjc: r471 - hugo/trunk/src/work/johanna
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:39:37 CET 2006
Author: beckerjc
Date: Sat Apr 17 23:50:48 2004
New Revision: 471
Modified:
hugo/trunk/src/work/johanna/kruskal.h
hugo/trunk/src/work/johanna/kruskal_test.cc
Log:
A successful work-around for using const map reference as an output
parameter to Kruskal().
Modified: hugo/trunk/src/work/johanna/kruskal.h
==============================================================================
--- hugo/trunk/src/work/johanna/kruskal.h (original)
+++ hugo/trunk/src/work/johanna/kruskal.h Sat Apr 17 23:50:48 2004
@@ -37,6 +37,29 @@
return tot_cost;
}
+ /* A work-around for running Kruskal with const-reference bool maps... */
+
+ template<typename Map>
+ class NonConstMapWr {
+ const Map &m;
+ public:
+ typedef typename Map::ValueType ValueType;
+
+ NonConstMapWr(const Map &_m) : m(_m) {}
+
+ template<typename KeyType>
+ void set(KeyType const& k, ValueType const &v) const { m.set(k,v); }
+ };
+
+ template <typename Graph, typename InputEdgeOrder, typename OutBoolMap>
+ inline
+ typename InputEdgeOrder::ValueType
+ Kruskal(Graph const& G, InputEdgeOrder const& edges,
+ OutBoolMap const& out_map)
+ {
+ NonConstMapWr<OutBoolMap> map_wr(out_map);
+ return Kruskal(G, edges, map_wr);
+ }
/* ** ** Output-objektumok: egyszeruen extra bool mapek ** ** */
@@ -49,7 +72,7 @@
template<typename Iterator>
class SequenceOutput {
- Iterator it;
+ mutable Iterator it;
public:
typedef bool ValueType;
@@ -57,7 +80,7 @@
SequenceOutput(Iterator const &_it) : it(_it) {}
template<typename KeyType>
- 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<typename Iterator>
@@ -177,6 +200,7 @@
/// \brief Wrapper to Kruskal().
/// Input is from an EdgeMap, output is a plain boolmap.
template <typename Graph, typename EdgeCostMap, typename RetEdgeBoolMap>
+ 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 <typename Graph, typename EdgeCostMap, typename RetIterator>
+ inline
typename EdgeCostMap::ValueType
Kruskal_EdgeCostMapIn_IteratorOut(Graph const& G,
EdgeCostMap const& edge_costs,
Modified: hugo/trunk/src/work/johanna/kruskal_test.cc
==============================================================================
--- hugo/trunk/src/work/johanna/kruskal_test.cc (original)
+++ hugo/trunk/src/work/johanna/kruskal_test.cc Sat Apr 17 23:50:48 2004
@@ -100,12 +100,18 @@
}
tree_edge_vec.clear();
- SequenceOutput< back_insert_iterator< vector<Edge> > >
- vec_filler(back_inserter(tree_edge_vec));
+// SequenceOutput< back_insert_iterator< vector<Edge> > >
+// vec_filler(back_inserter(tree_edge_vec));
+// cout << "Nemkonst koltseggel tarhatekonyabban: "
+// << Kruskal(G,
+// KruskalMapVec<ECostMap>(G, edge_cost_map),
+// vec_filler)
+// << endl;
cout << "Nemkonst koltseggel tarhatekonyabban: "
<< Kruskal(G,
KruskalMapVec<ECostMap>(G, edge_cost_map),
- vec_filler)
+ makeSequenceOutput(back_inserter(tree_edge_vec))
+ )
<< endl;
i = 1;
More information about the Lemon-commits
mailing list