]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/parray.hh
cleanup. Separate into internal
[lilypond.git] / flower / include / parray.hh
index 08fe766f5d3f2b9eb61a9d29ba5ab90d5a6637d9..e37a316503cdf6ba5376e3c26f453439ce203f43 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the Flower Library
 
-  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
 
@@ -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)
     {
@@ -126,7 +130,7 @@ public:
   Array<void*>::size;
   Array<void*>::clear;
   Array<void*>::set_size;
-  Array<void*>::empty;
+  Array<void*>::is_empty;
   Array<void*>::reverse;
   Array<void*>::tighten_maxsize;
 
@@ -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