]> git.donarmstrong.com Git - lilypond.git/blob - flower/full-storage.cc
release: 0.1.11
[lilypond.git] / flower / full-storage.cc
1 /*
2   full-storage.cc -- implement Full_storage
3
4   source file of the Flower Library
5
6   (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 */
8
9 #include "full-storage.hh"
10
11
12 void
13 Full_storage::operator=(Full_storage const &fs)
14 {
15   resize (fs.height_i_, fs.width_i_);
16   OK();
17   fs.OK();
18   for (int i=0; i<height_i_; i++)
19         for (int j=0; j<width_i_; j++)
20             els_p_p_[i][j]= fs.els_p_p_[i][j];
21 }
22
23
24 void
25 Full_storage::OK() const
26 {
27 #ifndef NDEBUG
28
29   assert (max_height_i_ >= height_i_ && max_width_i_ >= width_i_);
30   assert (height_i_ >= 0 && width_i_ >= 0);
31   assert (els_p_p_||!max_height_i_);
32 #endif
33 }
34
35
36
37
38 Full_storage::~Full_storage() 
39 {
40   for (int i=0; i < max_height_i_; i++)
41         delete [] els_p_p_[i];
42   delete[] els_p_p_;
43 }
44
45 void
46
47 Full_storage::resize (int rows, int cols)
48 {
49   OK();
50   resize_cols (rows);
51   resize_rows (cols);
52 }
53
54
55
56 bool
57 Full_storage::mult_ok (int i, int) const
58 {
59   return i < height_i_;
60 }
61
62
63 bool
64 Full_storage::trans_ok (int , int j) const
65 {
66      return j < width_i_;
67
68
69
70
71 void
72 Full_storage::trans_next (int &i, int &j) const
73 {
74   assert (trans_ok (i,j));
75   i++;
76   if (i >= height_i_) 
77     {
78         i=0;
79         j ++;
80     }
81 }
82
83
84 void
85 Full_storage::mult_next (int &i, int &j) const
86 {
87   assert (mult_ok (i,j));
88   j++;
89   if (j >= width_i_) 
90     {
91         j=0;
92         i++;
93     }
94 }
95
96
97 void
98 Full_storage::delete_column (int k)
99 {
100   assert (0 <= k &&k<width_i_);    
101   for (int i=0; i< height_i_ ; i++)
102         for (int j=k+1; j <width_i_; j++)
103             els_p_p_[i][j-1]=els_p_p_[i][j];
104   width_i_--;
105 }
106
107
108 void
109 Full_storage::delete_row (int k)
110 {
111   assert (0 <= k &&k<height_i_);
112   for (int i=k+1; i < height_i_ ; i++)
113         for (int j=0; j < width_i_; j++)
114             els_p_p_[i-1][j]=els_p_p_[i][j];
115   height_i_--;
116 }
117
118
119
120 void
121 Full_storage::insert_row (int k)
122 {
123   assert (0 <= k&& k <=height_i_);
124   resize_cols (height_i_+1);
125   for (int i=height_i_-1; i > k ; i--)
126         for (int j=0; j <width_i_; j++)
127             els_p_p_[i][j]=els_p_p_[i-1][j];
128
129 }
130
131 bool
132 Full_storage::try_right_multiply (Matrix_storage * dest, Matrix_storage const * right) const
133 {
134   if (dest->name() != Full_storage::static_name () ||
135         right->name() != Full_storage::static_name ())
136         return false;
137
138   Full_storage *d_l = (Full_storage*)dest;
139   Full_storage *r_l = (Full_storage*)right;
140   
141   d_l->set_size (height_i_, r_l->width_i_);
142   for (int i=0; i < d_l->height_i_; i++)
143         for (int j = 0; j < d_l->width_i_; j++) 
144           {
145             Real &r (d_l->els_p_p_[i][j]);
146             r=0.0;
147             for (int k = 0; k < width_i_; k++)
148                 r += els_p_p_[i][k] * r_l->els_p_p_[k][j];
149             
150           }
151   return true;
152   
153   
154 }
155 IMPLEMENT_IS_TYPE_B1(Full_storage,Matrix_storage);
156 void
157 Full_storage::resize_cols (int newh)
158 {
159   if (newh <= max_height_i_) 
160     {
161         height_i_=newh;
162         return;
163     }
164    
165   Real ** newa=new Real*[newh];
166   int j=0;
167   for (; j < height_i_; j++)
168         newa[j] = els_p_p_[j];
169   for (; j < newh; j++)
170         newa[j] = new Real[max_width_i_];
171   delete[] els_p_p_;
172   els_p_p_=newa;
173
174   height_i_ = max_height_i_ = newh;
175 }
176
177
178
179 Full_storage::Full_storage (Matrix_storage*m)
180 {
181   set_size (m->rows(), m->cols ());
182   if ( !m->is_type_b ( Full_storage::static_name()))
183         for (int i=0; i<height_i_; i++)
184             for (int j=0; j<width_i_; j++)
185                 els_p_p_[i][j]=0.0;
186   for (int i,j=0; m->mult_ok (i,j); m->mult_next (i,j))
187         els_p_p_[i][j] = m->elem (i,j);
188 }
189
190
191 void
192 Full_storage::resize_rows (int neww)
193 {
194   if (neww <= max_width_i_) 
195     {
196         width_i_=neww;
197         return;
198     }
199   for (int i=0; i < max_height_i_ ; i++) 
200     {
201         Real* newa = new Real[neww];
202         for (int k=0; k < width_i_; k++)
203             newa[k] = els_p_p_[i][k];
204
205         delete[] els_p_p_[i];
206         els_p_p_[i] = newa;
207     }
208   width_i_ = max_width_i_ = neww;       
209 }
210
211 #ifdef INLINE
212 #undef INLINE
213 #endif
214 #define INLINE
215
216 #include "full-storage.icc"