2 full-storage.cc -- implement Full_storage
4 source file of the Flower Library
6 (c) 1996,1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "full-storage.hh"
13 Full_storage::operator=(Full_storage const &fs)
15 resize (fs.height_i_, fs.width_i_);
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];
25 Full_storage::OK() const
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_);
38 Full_storage::~Full_storage()
40 for (int i=0; i < max_height_i_; i++)
41 delete [] els_p_p_[i];
47 Full_storage::resize (int rows, int cols)
57 Full_storage::mult_ok (int i, int) const
64 Full_storage::trans_ok (int , int j) const
72 Full_storage::trans_next (int &i, int &j) const
74 assert (trans_ok (i,j));
84 Full_storage::mult_next (int &i, int &j) const
86 assert (mult_ok (i,j));
96 Full_storage::delete_column (int k)
98 assert (0 <= k &&k<width_i_);
99 for (int i=0; i< height_i_ ; i++)
100 for (int j=k+1; j <width_i_; j++)
101 els_p_p_[i][j-1]=els_p_p_[i][j];
107 Full_storage::delete_row (int k)
109 assert (0 <= k &&k<height_i_);
110 for (int i=k+1; i < height_i_ ; i++)
111 for (int j=0; j < width_i_; j++)
112 els_p_p_[i-1][j]=els_p_p_[i][j];
119 Full_storage::insert_row (int k)
121 assert (0 <= k&& k <=height_i_);
122 resize_cols (height_i_+1);
123 for (int i=height_i_-1; i > k ; i--)
124 for (int j=0; j <width_i_; j++)
125 els_p_p_[i][j]=els_p_p_[i-1][j];
130 Full_storage::try_right_multiply (Matrix_storage * dest, Matrix_storage const * right)const
132 if (dest->name() != Full_storage::static_name () ||
133 right->name() != Full_storage::static_name ())
136 Full_storage *d_l = (Full_storage*)dest;
137 Full_storage *r_l = (Full_storage*)right;
139 d_l->set_size (height_i_, r_l->width_i_);
140 for (int i=0; i < d_l->height_i_; i++)
141 for (int j = 0; j < d_l->width_i_; j++) {
142 Real &r (d_l->els_p_p_[i][j]);
144 for (int k = 0; k < width_i_; k++)
145 r += els_p_p_[i][k] * r_l->els_p_p_[k][j];
152 IMPLEMENT_IS_TYPE_B1(Full_storage,Matrix_storage);
154 Full_storage::resize_cols (int newh)
156 if (newh <= max_height_i_) {
161 Real ** newa=new Real*[newh];
163 for (; j < height_i_; j++)
164 newa[j] = els_p_p_[j];
165 for (; j < newh; j++)
166 newa[j] = new Real[max_width_i_];
170 height_i_ = max_height_i_ = newh;
175 Full_storage::Full_storage (Matrix_storage*m)
177 set_size (m->rows(), m->cols ());
178 if ( !m->is_type_b ( Full_storage::static_name()))
179 for (int i=0; i<height_i_; i++)
180 for (int j=0; j<width_i_; j++)
182 for (int i,j=0; m->mult_ok (i,j); m->mult_next (i,j))
183 els_p_p_[i][j] = m->elem (i,j);
188 Full_storage::resize_rows (int neww)
190 if (neww <= max_width_i_) {
194 for (int i=0; i < max_height_i_ ; i++) {
195 Real* newa = new Real[neww];
196 for (int k=0; k < width_i_; k++)
197 newa[k] = els_p_p_[i][k];
199 delete[] els_p_p_[i];
202 width_i_ = max_width_i_ = neww;
210 #include "full-storage.icc"