]> git.donarmstrong.com Git - lilypond.git/blob - flower/include/array.icc
release: 1.3.3
[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 #ifdef __powerpc__
26     {
27       /*
28         urg: wierd egcs-1.1.2-12c (stock LinuxPPC R5) bug on ppc
29         bug report filed
30         fixed in egcs-1.1.2-12f
31         ftp://dev.linuxppc.org/users/fsirl/R5/RPMS/ppc/ 
32       */
33       *dest = *src;
34       dest++, src++;
35     }
36 #else
37     *dest++ = *src++;
38 #endif
39 }
40
41 template<class T> INLINE void
42 Array<T>::insert (T k, int j) 
43 {
44   assert (j >=0 && j<= size_);
45   set_size (size_+1);
46   for (int i=size_-1; i > j; i--)
47     array_p_[i] = array_p_[i-1];
48   array_p_[j] = k;
49 }
50
51 template<class T> INLINE void
52 Array<T>::sort (int (*compare)(T const&,T const&),
53            int lower = -1, int upper = -1) 
54 {
55   if (lower < 0) 
56     {
57       lower = 0 ;
58       upper = size () - 1;
59     }
60   if (lower >= upper)
61     return;
62   swap (lower, (lower+upper)/2);
63   int last = lower;
64   for (int i= lower +1; i <= upper; i++)
65     if (compare (array_p_[i], array_p_[lower]) < 0)
66       swap (++last,i);
67   swap (lower, last);
68   sort (compare, lower, last-1);
69   sort (compare, last+1, upper);
70 }
71
72 template<class T> INLINE void
73 Array<T>::reverse () 
74 {
75   int h = size_/2;
76   for (int i =0,j = size_-1; i < h; i++,j--)
77     swap (i,j);
78 }
79
80 template<class T> INLINE
81 void
82 Array<T>::OK() const
83 {
84   assert (max_ >= size_ && size_ >=0);
85   if (max_) assert (array_p_);
86 }
87
88 template<class T> INLINE
89 T *
90 Array<T>::remove_array_p ()
91 {
92   T * p = array_p_;
93   size_ = 0;
94   max_ = 0;
95   array_p_ =0;
96   return p;
97 }
98
99 template<class T> INLINE
100 Array<T>
101 Array<T>::slice (int lower, int upper)
102 {
103   assert (lower >= 0 && lower <=upper&& upper <= size_);
104   Array<T> r;
105   int s =upper-lower;
106   r.set_size (s);
107   arrcpy (r.array_p_, array_p_  + lower, s);
108   return r;
109 }
110