]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/array.icc
release: 1.0.1
[lilypond.git] / flower / include / array.icc
1 /*
2   (c) Han-Wen Nienhuys 1995,96,97,98
3
4   Distributed under GNU GPL
5 */
6
7
8 #if 0
9 #include "array.hh"
10 #ifdef INLINE
11 #undef INLINE
12 #endif
13
14 #define INLINE
15 #endif
16
17 /*
18  functions with loops don't inline
19  */
20
21 template<class T> INLINE void 
22 arrcpy (T*dest, T*src, int count)
23 {
24   for (int i_shadows_local=0; i_shadows_local < count ; i_shadows_local++)
25     *dest++ = *src++;
26 }
27
28 template<class T> INLINE void
29 Array<T>::insert (T k, int j) 
30 {
31   assert (j >=0 && j<= size_);
32   set_size (size_+1);
33   for (int i=size_-1; i > j; i--)
34     array_p_[i] = array_p_[i-1];
35   array_p_[j] = k;
36 }
37
38 template<class T> INLINE void
39 Array<T>::sort (int (*compare)(T const&,T const&),
40            int lower = -1, int upper = -1) 
41 {
42   if (lower < 0) 
43     {
44       lower = 0 ;
45       upper = size () - 1;
46     }
47   if (lower >= upper)
48     return;
49   swap (lower, (lower+upper)/2);
50   int last = lower;
51   for (int i= lower +1; i <= upper; i++)
52     if (compare (array_p_[i], array_p_[lower]) < 0)
53       swap (++last,i);
54   swap (lower, last);
55   sort (compare, lower, last-1);
56   sort (compare, last+1, upper);
57 }
58
59 template<class T> INLINE void
60 Array<T>::reverse () 
61 {
62   int h = size_/2;
63   for (int i =0,j = size_-1; i < h; i++,j--)
64     swap (i,j);
65 }
66