00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SGI_connected_components_h_INCLUDED
00038 #define SGI_connected_components_h_INCLUDED
00039
00040
00041
00042 template <class Parent, class Edge>
00043 void erase_from_parent(Parent& p, const Edge& e)
00044 {
00045 p[second(e)] = second(e);
00046 }
00047
00048 template <class Container, class Edge>
00049 void erase_from_child(Container& heir,
00050 Container& next_sibling,
00051 const Edge& e)
00052 {
00053 typedef typename Container::value_type index;
00054 index parent = first(e);
00055 index child = second(e);
00056 index oldest_child = heir[parent];
00057 if (child == oldest_child) {
00058 index next_child = next_sibling[oldest_child];
00059 heir[parent] = oldest_child != next_child ? next_child : parent;
00060 next_sibling[oldest_child] = oldest_child;
00061 } else {
00062 index next_child = next_sibling[oldest_child];
00063 while (next_child != child) {
00064 oldest_child = next_child;
00065 next_child = next_sibling[next_child];
00066 }
00067 index next_next_child = next_sibling[next_child];
00068 next_sibling[oldest_child] =
00069 next_child == next_next_child ? oldest_child : next_next_child;
00070 next_sibling[next_child] = next_child;
00071 }
00072 }
00073
00074
00075 template <class Container, class Edge>
00076 void erase_from_child(Container& heir,
00077 Container& next_sibling,
00078 Container& previous_sibling,
00079 const Edge& e)
00080 {
00081 typedef typename Container::value_type index;
00082 index parent = first(e);
00083 index child = second(e);
00084 index oldest_child = heir[parent];
00085 index next_child = next_sibling[oldest_child];
00086 index previous_child = previous_sibling[oldest_child];
00087 if (child == oldest_child)
00088 heir[parent] = oldest_child != next_child ? next_child : parent;
00089 next_sibling[child] = child;
00090 previous_sibling[child] = child;
00091 next_sibling[oldest_child] = oldest_child;
00092 previous_sibling[next_child] = next_child;
00093 }
00094
00095 template <class Parent, class Edge>
00096 void insert(Parent& parent, const Edge& edge)
00097 {
00098 parent[second(edge)] = first(edge);
00099 }
00100
00101 template <class Container, class Edge>
00102 void insert(Container& parents,
00103 Container& heir,
00104 Container& next_sibling,
00105 const Edge& edge) {
00106 typedef typename Parent::index Index;
00107 Index child = second(edge);
00108 Index parent = first(edge);
00109 Index oldest_child = heir[parent];
00110 next_sibling[child] = (oldest_child == parent)
00111 ? child : oldest_child;
00112 heir[parent] = child;
00113 parents[child] = parent;
00114 }
00115
00116 template <class Container, class Edge>
00117 void insert(Container& parents,
00118 Container& heir,
00119 Container& next_sibling,
00120 Container& prev_sibling,
00121 const Edge& edge)
00122 {
00123 typedef typename Parent::index Index;
00124 Index child = second(edge);
00125 Index parent = first(edge);
00126 Index oldest_child = heir[parent];
00127 prev_sibling[child] = child;
00128 if (oldest_child == parent) {
00129 next_sibling[child] = child;
00130 } else {
00131 next_silbing[child] = oldest_child;
00132 prev_silbing[oldest_child] = child;
00133 }
00134 heir[parent] = child;
00135 parents[child] = parent;
00136 }
00137
00138
00139 }
00140
00141 #endif
00142
00143
00144
00145