]> git.donarmstrong.com Git - lilypond.git/blobdiff - flower/include/array.icc
*** empty log message ***
[lilypond.git] / flower / include / array.icc
index f5ccafee74e866d540d927d211cb4ef821e3c3d6..33f44a67787da568346fd0dd610c969a108b791e 100644 (file)
@@ -1,11 +1,11 @@
 /*
-  (c) 1995--2005  Han-Wen Nienhuys  <hanwen@cs.uu.nl>
+  (c) 1995--2006  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
   Distributed under GNU GPL
 */
 
 #if 0
-#include "array.hh"
+#include "std-vector.hh"
 #ifdef INLINE
 #undef INLINE
 #endif
@@ -18,9 +18,9 @@
 */
 
 template<class T> INLINE void
-arrcpy (T *dest, T const *src, int count)
+arrcpy (T *dest, T const *src, vsize count)
 {
-  for (int i_shadows_local = 0; i_shadows_local < count; i_shadows_local++)
+  for (vsize i_shadows_local = 0; i_shadows_local < count; i_shadows_local++)
 #ifdef __powerpc__
     {
       /*
@@ -37,81 +37,34 @@ arrcpy (T *dest, T const *src, int count)
 #endif
 }
 
-template<class T> INLINE void
-Array<T>::insert (T k, int j)
-{
-  assert (j >= 0 && j <= size_);
-  set_size (size_ + 1);
-  for (int i = size_ - 1; i > j; i--)
-    array_[i] = array_[i - 1];
-  array_[j] = k;
-}
-
-template<class T> INLINE void
-Array<T>::sort (int (*compare) (T const &, T const &), int lower, int upper)
-{
-  if (lower < 0)
-    {
-      lower = 0;
-      upper = size () - 1;
-    }
-  if (lower >= upper)
-    return;
-  swap (lower, (lower + upper) / 2);
-  int last = lower;
-  for (int i = lower +1; i <= upper; i++)
-    if (compare (array_[i], array_[lower]) < 0)
-      swap (++last, i);
-  swap (lower, last);
-  sort (compare, lower, last - 1);
-  sort (compare, last + 1, upper);
-}
-
-template<class T> INLINE void
-Array<T>::reverse ()
-{
-  int h = size_ / 2;
-  for (int i = 0, j = size_ - 1; i < h; i++, j--)
-    swap (i, j);
-}
-
 template<class T> INLINE
 void
 Array<T>::OK () const
 {
+#if !STD_VECTOR
   assert (max_ >= size_ && size_ >= 0);
-  if (max_) assert (array_);
-}
-
-template<class T> INLINE
-T *
-Array<T>::remove_array ()
-{
-  T *p = array_;
-  size_ = 0;
-  max_ = 0;
-  array_ = 0;
-  return p;
+#else
+  assert (max_ >= size_);
+#endif
+  if (max_)
+    assert (array_);
 }
 
 template<class T> INLINE
-Array<T>
-Array<T>::slice (int lower, int upper) const
+Array<T>::Array (const_iterator b, const_iterator e)
 {
-  assert (lower >= 0 && lower <= upper && upper <= size_);
-  Array<T> r;
-  int s = upper - lower;
-  r.set_size (s);
-  arrcpy (r.array_, array_ + lower, s);
-  return r;
+  vsize n = e - b;
+  array_ = new T[n];
+  max_ = size_ = n;
+  arrcpy (array_, b, n);
 }
 
 template<class T>
 void
 binary_search_bounds (Array<T> const &table,
                      T const &key, int (*compare) (T const &, T const &),
-                     int *lo,
-                     int *hi)
+                     vsize *lo,
+                     vsize *hi)
 {
   int cmp;
   int result;
@@ -135,19 +88,20 @@ binary_search_bounds (Array<T> const &table,
   lookup with binsearch, return array index.
 */
 template<class T>
-int
+vsize
 binary_search (Array<T> const &table,
               T const &key, int (*compare) (T const &, T const &),
-              int lo = 0,
-              int hi = -1)
+              vsize lo=0,
+              vsize hi=VPOS)
 {
-  if (hi < 0)
+  if (hi == VPOS)
     hi = table.size ();
 
   binary_search_bounds (table, key, compare, &lo, &hi);
 
   if (! (*compare) (key, table[lo]))
     return lo;
-  else
-    return -1;              /* not found */
+
+  /* not found */
+  return VPOS;
 }