File indexing completed on 2025-01-18 09:43:31
0001
0002
0003
0004
0005
0006 #ifndef BOOST_DETAIL_DISJOINT_SETS_HPP
0007 #define BOOST_DETAIL_DISJOINT_SETS_HPP
0008
0009 namespace boost
0010 {
0011
0012 namespace detail
0013 {
0014
0015 template < class ParentPA, class Vertex >
0016 Vertex find_representative_with_path_halving(ParentPA p, Vertex v)
0017 {
0018 Vertex parent = get(p, v);
0019 Vertex grandparent = get(p, parent);
0020 while (parent != grandparent)
0021 {
0022 put(p, v, grandparent);
0023 v = grandparent;
0024 parent = get(p, v);
0025 grandparent = get(p, parent);
0026 }
0027 return parent;
0028 }
0029
0030 template < class ParentPA, class Vertex >
0031 Vertex find_representative_with_full_compression(ParentPA parent, Vertex v)
0032 {
0033 Vertex old = v;
0034 Vertex ancestor = get(parent, v);
0035 while (ancestor != v)
0036 {
0037 v = ancestor;
0038 ancestor = get(parent, v);
0039 }
0040 v = get(parent, old);
0041 while (ancestor != v)
0042 {
0043 put(parent, old, ancestor);
0044 old = v;
0045 v = get(parent, old);
0046 }
0047 return ancestor;
0048 }
0049
0050
0051
0052
0053 template < class ParentPA, class RankPA, class Vertex,
0054 class ComponentRepresentative >
0055 inline void link_sets(ParentPA p, RankPA rank, Vertex i, Vertex j,
0056 ComponentRepresentative comp_rep)
0057 {
0058 i = comp_rep(p, i);
0059 j = comp_rep(p, j);
0060 if (i == j)
0061 return;
0062 if (get(rank, i) > get(rank, j))
0063 put(p, j, i);
0064 else
0065 {
0066 put(p, i, j);
0067 if (get(rank, i) == get(rank, j))
0068 put(rank, j, get(rank, j) + 1);
0069 }
0070 }
0071
0072
0073
0074
0075
0076
0077
0078 template < class ParentPA, class Vertex >
0079 inline void normalize_node(ParentPA p, Vertex i)
0080 {
0081 if (i > get(p, i) || get(p, get(p, i)) != get(p, i))
0082 put(p, i, get(p, get(p, i)));
0083 else
0084 {
0085 put(p, get(p, i), i);
0086 put(p, i, i);
0087 }
0088 }
0089
0090 }
0091 }
0092
0093 #endif