--- /dev/null
+#ifndef COMPARE_HH
+#define COMPARE_HH
+
+/// handy notations for a signed comparison
+#define instantiate_compare(type, function) \
+inline bool operator>(type t1, type t2) { return function(t1, t2) > 0; } \
+ inline bool operator>=(type t1, type t2) { return function(t1, t2) >= 0; } \
+ inline bool operator==(type t1, type t2) { return function(t1, t2) == 0; } \
+ inline bool operator<=(type t1, type t2) { return function(t1, t2) <= 0; } \
+ inline bool operator<(type t1, type t2) { return function(t1, t2) < 0; } \
+ inline type MAX(type t1, type t2) { return (t1 > t2 )? t1 : t2; }\
+ inline type MIN(type t1, type t2) { return (t1 < t2 )? t1 : t2; }\
+ \
+ bool operator<(type t1, type t2) /* stupid fix to allow ; */
+ /**
+ make the operators{<,<=,==,>=,>} and the MAX and MIN of two.
+ Please fill a & in the type argument if necessary.
+ */
+
+
+
+
+#endif
+
--- /dev/null
+#include "unionfind.hh"
+/*
+ see a book on data structures
+ */
+
+Union_find::Union_find(int n)
+{
+ classes.set_size(n);
+
+ for (int i=0; i < n; i++) {
+ classes[i] = i;
+ }
+}
+
+int
+Union_find::find(int i)
+{
+ int rep = i;
+ while (classes[rep] != rep)
+ rep = classes[rep];
+ while (classes[i] != rep) {
+ int next =classes[i];
+ classes[i] = rep;
+ i = next;
+ }
+ return rep;
+}
+
+void
+Union_find::connect(int i, int j)
+{
+ i = find(i);
+ j = find(j);
+ classes[i] = j;
+}
--- /dev/null
+#ifndef UNIONFIND_HH
+#define UNIONFIND_HH
+#include "vray.hh"
+
+/// which points of a graph are connected?
+struct Union_find {
+ void connect(int i, int j);
+ int find(int i);
+ bool equiv(int i, int j) { return find(i) == find(j); }
+ Union_find(int sz);
+
+private:
+ svec<int> classes;
+
+};
+/*
+ Union find, a standard algorithm:
+
+ Union_find represents an undirected graph of N points. You can
+ connect two points using #connect()#. #find(i)# finds a uniquely
+ determined representant of the equivalence class of points
+ connected to #i#.
+
+ */
+#endif