1 // (C) Copyright Jeremy Siek 2004
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_DETAIL_DISJOINT_SETS_HPP
7 #define BOOST_DETAIL_DISJOINT_SETS_HPP
13 template <class ParentPA, class Vertex>
15 find_representative_with_path_halving(ParentPA p, Vertex v)
17 Vertex parent = get(p, v);
18 Vertex grandparent = get(p, parent);
19 while (parent != grandparent) {
20 put(p, v, grandparent);
23 grandparent = get(p, parent);
28 template <class ParentPA, class Vertex>
30 find_representative_with_full_compression(ParentPA parent, Vertex v)
33 Vertex ancestor = get(parent, v);
34 while (ancestor != v) {
36 ancestor = get(parent, v);
39 while (ancestor != v) {
40 put(parent, old, ancestor);
47 /* the postcondition of link sets is:
48 component_representative(i) == component_representative(j)
50 template <class ParentPA, class RankPA, class Vertex,
51 class ComponentRepresentative>
53 link_sets(ParentPA p, RankPA rank, Vertex i, Vertex j,
54 ComponentRepresentative comp_rep)
59 if (get(rank, i) > get(rank, j))
63 if (get(rank, i) == get(rank, j))
64 put(rank, j, get(rank, j) + 1);
68 // normalize components has the following postcondidition:
70 // that is, the representative is the node with the smallest index in its class
71 // as its precondition it it assumes that the node container is compressed
73 template <class ParentPA, class Vertex>
75 normalize_node(ParentPA p, Vertex i)
77 if (i > get(p,i) || get(p, get(p,i)) != get(p,i))
78 put(p,i, get(p, get(p,i)));
88 #endif // BOOST_DETAIL_DISJOINT_SETS_HPP