4 # include <tpl_dynArray.H>
5 # include <tpl_dynSetTree.H>
12 # define UNION_ROOT_IMPL \
21 # define UNION_DEPTH \
22 size_t depth(size_t i) \
24 const int & parent = id(i); \
29 return 1 + depth(parent); \
38 for (int i = 0; i < n; ++i) \
45 # define UNION_PUBLIC_ROUTINES \
46 size_t size() const { return id.size(); } \
48 size_t get_num_blocks() const { return num_blocks; } \
50 bool are_connected(size_t i, size_t j) \
52 return root(i) == root(j); \
55 void join(size_t i, size_t j) \
103 size_t root(
size_t i)
115 UNION_PUBLIC_ROUTINES
137 void verify_if_add_new_points(
size_t n)
145 for (
int i = l; i <= n; ++i)
150 num_blocks += n - l + 1;
153 size_t root(
size_t i)
155 verify_if_add_new_points(i);
166 UNION_PUBLIC_ROUTINES
187 template <
typename T,
class Compare = Aleph::less<T>>
197 Pair(
const T & __item,
size_t __i)
198 : item(__item), i(__i) { }
203 bool operator () (
const Pair & p1,
const Pair & p2)
const
205 return Compare() (p1.item, p2.item);
212 size_t test_and_insert_new_item(
const T & item)
225 size_t i = test_and_insert_new_item(p);
226 size_t j = test_and_insert_new_item(q);
228 return Relation::are_connected(i, j);
232 void join(
const T & p,
const T & q)
234 size_t i = test_and_insert_new_item(p);
235 size_t j = test_and_insert_new_item(q);
240 # endif // TPL_UNION_H
Definition: tpl_union.H:133
Definition: tpl_union.H:99
Node * join(Node *t1, Node *t2, Node *&dup)
Definition: tpl_binNodeUtils.H:2337
bool are_connected(const T &p, const T &q)
Retorna true is i y j están conectados.
Definition: tpl_union.H:223
void join(const T &p, const T &q)
Une p con q.
Definition: tpl_union.H:232
Definition: tpl_union.H:188
Key * search_or_insert(const Key &key)
Definition: tpl_dynSetTree.H:225