One more step toward the standars interface.
10 template <typename EdgeCostPair> static
11 bool comparePair(EdgeCostPair const& a, EdgeCostPair const& b) {
12 return a.second < b.second;
16 template <typename Graph, typename EdgeDoubleMap, typename EdgeBoolMap>
18 typename EdgeDoubleMap::ValueType
19 MinCostTreeKruskal(Graph const& G, EdgeDoubleMap const& costmap,
23 typedef typename EdgeDoubleMap::ValueType EDouble;
24 typedef typename Graph::EachEdgeIt EachEdgeIt;
25 typedef std::pair<EachEdgeIt, EDouble> EdgeCostPair;
28 typedef std::vector<EdgeCostPair> EdgeCostVector;
31 for (EachEdgeIt e=G.template first<EachEdgeIt>(); e.valid(); ++e) {
32 rank.push_back(make_pair(e, costmap.get(e)));
36 std::sort(rank.begin(), rank.end(), comparePair<EdgeCostPair>);
38 typedef typename Graph::NodeMap<int> NodeIntMap;
39 typedef typename Graph::NodeIt NodeIt;
40 NodeIntMap comp_map(G, -1);
41 UnionFind<NodeIt,NodeIntMap> uf(comp_map);
44 for (typename EdgeCostVector::iterator p = rank.begin();
45 p!=rank.end(); ++p ) {
46 if ( uf.joinComponents(G.head(p->first), G.tail(p->first)) ) {
47 treemap.set(p->first, true);
48 tot_cost += p->second;
51 treemap.set(p->first, false);
60 #endif //HUGO_KRUSKAL_H