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