]> git.donarmstrong.com Git - lilypond.git/blob - flower/full-storage.cc
5e05c1bb4bd99a9ce8a667664fb862ea51219a10
[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 Full_storage::resize (int rows, int cols)
47 {
48   OK();
49   resize_cols (rows);
50   resize_rows (cols);
51 }
52
53 bool
54 Full_storage::mult_ok (int i, int) const
55 {
56   return i < height_i_;
57 }
58
59
60 bool
61 Full_storage::trans_ok (int , int j) const
62 {
63      return j < width_i_;
64
65
66
67
68 void
69 Full_storage::trans_next (int &i, int &j) const
70 {
71   assert (trans_ok (i,j));
72   i++;
73   if (i >= height_i_) 
74     {
75         i=0;
76         j ++;
77     }
78 }
79
80
81 void
82 Full_storage::mult_next (int &i, int &j) const
83 {
84   assert (mult_ok (i,j));
85   j++;
86   if (j >= width_i_) 
87     {
88         j=0;
89         i++;
90     }
91 }
92
93
94 void
95 Full_storage::delete_column (int k)
96 {
97   assert (0 <= k &&k<width_i_);    
98   for (int i=0; i< height_i_ ; i++)
99         for (int j=k+1; j <width_i_; j++)
100             els_p_p_[i][j-1]=els_p_p_[i][j];
101   width_i_--;
102 }
103
104
105 void
106 Full_storage::delete_row (int k)
107 {
108   assert (0 <= k &&k<height_i_);
109   for (int i=k+1; i < height_i_ ; i++)
110         for (int j=0; j < width_i_; j++)
111             els_p_p_[i-1][j]=els_p_p_[i][j];
112   height_i_--;
113 }
114
115
116
117 void
118 Full_storage::insert_row (int k)
119 {
120   assert (0 <= k&& k <=height_i_);
121   resize_cols (height_i_+1);
122   for (int i=height_i_-1; i > k ; i--)
123         for (int j=0; j <width_i_; j++)
124             els_p_p_[i][j]=els_p_p_[i-1][j];
125
126 }
127
128 bool
129 Full_storage::try_right_multiply (Matrix_storage * dest, Matrix_storage const * right) const
130 {
131   if (dest->name() != Full_storage::static_name () ||
132         right->name() != Full_storage::static_name ())
133         return false;
134
135   Full_storage *d_l = (Full_storage*)dest;
136   Full_storage *r_l = (Full_storage*)right;
137   
138   d_l->set_size (height_i_, r_l->width_i_);
139   for (int i=0; i < d_l->height_i_; i++)
140         for (int j = 0; j < d_l->width_i_; j++) 
141           {
142             Real &r (d_l->els_p_p_[i][j]);
143             r=0.0;
144             for (int k = 0; k < width_i_; k++)
145                 r += els_p_p_[i][k] * r_l->els_p_p_[k][j];
146             
147           }
148   return true;
149   
150   
151 }
152 IMPLEMENT_IS_TYPE_B1(Full_storage,Matrix_storage);
153 void
154 Full_storage::resize_cols (int newh)
155 {
156   if (newh <= max_height_i_) 
157     {
158         height_i_=newh;
159         return;
160     }
161    
162   Real ** newa=new Real*[newh];
163   int j=0;
164   for (; j < height_i_; j++)
165         newa[j] = els_p_p_[j];
166   for (; j < newh; j++)
167         newa[j] = new Real[max_width_i_];
168   delete[] els_p_p_;
169   els_p_p_=newa;
170
171   height_i_ = max_height_i_ = newh;
172 }
173
174
175
176 Full_storage::Full_storage (Matrix_storage*m)
177 {
178   set_size (m->rows(), m->cols ());
179   if (!m->is_type_b (Full_storage::static_name()))
180         for (int i=0; i<height_i_; i++)
181             for (int j=0; j<width_i_; j++)
182                 els_p_p_[i][j]=0.0;
183   for (int i,j=0; m->mult_ok (i,j); m->mult_next (i,j))
184         els_p_p_[i][j] = m->elem (i,j);
185 }
186
187
188 void
189 Full_storage::resize_rows (int neww)
190 {
191   if (neww <= max_width_i_) 
192     {
193         width_i_=neww;
194         return;
195     }
196   for (int i=0; i < max_height_i_ ; i++) 
197     {
198         Real* newa = new Real[neww];
199         for (int k=0; k < width_i_; k++)
200             newa[k] = els_p_p_[i][k];
201
202         delete[] els_p_p_[i];
203         els_p_p_[i] = newa;
204     }
205   width_i_ = max_width_i_ = neww;       
206 }
207
208 #ifdef INLINE
209 #undef INLINE
210 #endif
211 #define INLINE
212
213 INLINE
214 IMPLEMENT_VIRTUAL_COPY_CONS(Full_storage,Matrix_storage);
215
216 #include "full-storage.icc"