]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/parray.hh
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / flower / include / parray.hh
index 08fe766f5d3f2b9eb61a9d29ba5ab90d5a6637d9..21a40429c60af407a835c0525f9b7bfe56bc26b0 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "array.hh"
 
+
+
 /**
   an array of pointers.
 
 template<class T>
 class Link_array : private Array<void *>
 {
-  static int default_compare (T *const& p1, T  *const&p2) {
-    /* can't do p1 -p2, since T might be an incomplete type */
-    if (p1 < p2)
-      return -1 ;
-    if (p2 < p1)
-      return 1;
-    return 0;
-  }
+
   Link_array (Array<void*> v)
     :Array<void*> (v)
     {
@@ -37,6 +32,15 @@ public:
   Link_array ()
     {}
 
+  static int default_compare (T *const& p1, T  *const&p2)
+  {
+    /* can't do p1 -p2, since T might be an incomplete type */
+    if (p1 < p2)
+      return -1 ;
+    if (p2 < p1)
+      return 1;
+    return 0;
+  }
   Link_array (T * const *tp, int n)
     : Array<void*> ((void **)tp, n)
     {
@@ -179,7 +183,6 @@ public:
       else
        return 0;
     }
-  
 };
 
 template<class T, class V>
@@ -295,5 +298,30 @@ binsearch_links (Link_array<T> const &arr, T *t,
 }
 
 
+template<class T>
+void
+binary_search_bounds (Link_array<T> const &table,
+                     T const *key, int (*compare) (T * const& , T *const &),
+                     int *lo,
+                     int *hi)
+{
+  int cmp;
+  int result;
+
+  /* binary search */
+  do
+  {
+      cmp = (*lo + *hi) / 2;
+
+      result = (*compare)  ((T*) key, table[cmp]);
+
+      if (result < 0)
+          *hi = cmp;
+      else
+          *lo = cmp;
+    }
+  while (*hi - *lo > 1);
+}
+
 #endif // PARRAY_HH