]> git.donarmstrong.com Git - lilypond.git/commitdiff
Import of flower-1.0.0
authorfred <fred>
Mon, 30 Sep 1996 07:48:31 +0000 (07:48 +0000)
committerfred <fred>
Mon, 30 Sep 1996 07:48:31 +0000 (07:48 +0000)
flower/compare.hh [new file with mode: 0644]
flower/unionfind.cc [new file with mode: 0644]
flower/unionfind.hh [new file with mode: 0644]

diff --git a/flower/compare.hh b/flower/compare.hh
new file mode 100644 (file)
index 0000000..05b6e89
--- /dev/null
@@ -0,0 +1,24 @@
+#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
+     
diff --git a/flower/unionfind.cc b/flower/unionfind.cc
new file mode 100644 (file)
index 0000000..e7b0831
--- /dev/null
@@ -0,0 +1,35 @@
+#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;    
+}
diff --git a/flower/unionfind.hh b/flower/unionfind.hh
new file mode 100644 (file)
index 0000000..8fcc6b4
--- /dev/null
@@ -0,0 +1,25 @@
+#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