git-svn-id: svn://db.shs.com.ru/pip@490 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2017-04-28 12:49:03 +00:00
parent 2754a78ff7
commit fc66f351df
15 changed files with 92 additions and 13 deletions

View File

@@ -21,8 +21,10 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PILIST_H
#define PILIST_H
#include "pibase.h"
#include <list>

View File

@@ -21,6 +21,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PIPAIR_H
#define PIPAIR_H

View File

@@ -57,8 +57,10 @@ public:
inline size_t rows() const {return rows_;}
inline size_t cols() const {return cols_;}
inline size_t size_all() const {return mat.size();}
inline ssize_t size_s_all() const {return mat.size_s();}
inline size_t size() const {return mat.size();}
inline ssize_t size_s() const {return mat.size_s();}
inline size_t length() const {return mat.length();}
inline size_t capacity() const {return mat.capacity();}
inline bool isEmpty() const {return mat.isEmpty();}
class Row {
@@ -71,6 +73,19 @@ public:
inline size_t size() const {return p_->cols_;}
inline T & operator [](size_t index) {return p_->mat[st_ + index];}
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
inline T * data(size_t index = 0) {return p_->mat.data(st_ + index);}
inline const T * data(size_t index = 0) const {return p_->mat.data(st_ + index);}
inline Row & operator =(const Row & other) {
if (p_ == other.p_ && st_ == other.st_) return *this;
size_t sz = piMin<size_t>(p_->cols_, other.p_->cols_);
p_->copyRow(st_, other.data(), sz);
return *this;
}
inline Row & operator =(const PIVector<T> & other) {
size_t sz = piMin<size_t>(p_->cols_, other.size());
p_->copyRow(st_, other.data(), sz);
return *this;
}
};
class RowConst {
@@ -82,11 +97,26 @@ public:
public:
inline size_t size() const {return p_->cols_;}
inline const T & operator [](size_t index) const {return p_->mat[st_ + index];}
inline const T * data(size_t index = 0) const {return p_->mat.data(st_ + index);}
};
inline Row operator[](size_t index) {return Row(this, index);}
inline RowConst operator[](size_t index) const {return RowConst(this, index);}
inline T * data(size_t index = 0) {return mat.data(index);}
inline const T * data(size_t index = 0) const {return mat.data(index);}
inline Row row(size_t index) {return Row(this, index);}
inline PIVector2D<T> & setRow(size_t row, const Row & other) {
size_t sz = piMin<size_t>(cols_, other.p_->cols_);
copyRow(cols_ * row, other.data(), sz);
return *this;
}
inline PIVector2D<T> & setRow(size_t row, const PIVector<T> & other) {
size_t sz = piMin<size_t>(cols_, other.size());
copyRow(cols_ * row, other.data(), sz);
return *this;
}
PIVector<PIVector<T> > toVectors() const {
PIVector<PIVector<T> > ret;
@@ -97,9 +127,13 @@ public:
PIVector<T> toPlainVector() const {return mat;}
private:
inline void copyRow(size_t start, const T * data, size_t size) {
for (size_t i = 0; i < size; i++)
mat[start + i] = data[i];
}
size_t rows_, cols_;
PIVector<T> mat;
};