Implement copy.

This commit is contained in:
chriseth 2022-08-22 15:51:40 +02:00
parent b1319eb3ee
commit df50762498
2 changed files with 14 additions and 0 deletions

View File

@ -40,6 +40,14 @@ SparseMatrix::SparseMatrixIterator SparseMatrix::IteratorCombiner::end()
return SparseMatrixIterator(nullptr, m_isRow);
}
SparseMatrix::SparseMatrix(SparseMatrix const& _other)
{
ensureSize(_other.rows(), _other.columns());
for (size_t row = 0; row < _other.rows(); row++)
for (auto&& entry: const_cast<SparseMatrix&>(_other).iterateRow(row))
prependInRow(nullptr, row, entry.col, entry.value);
}
SparseMatrix::IteratorCombiner SparseMatrix::iterateColumn(size_t _column)
{
return IteratorCombiner{

View File

@ -239,6 +239,12 @@ public:
SparseMatrixIterator end();
};
SparseMatrix() = default;
SparseMatrix(SparseMatrix const&);
SparseMatrix(SparseMatrix&&) = default;
SparseMatrix& operator=(SparseMatrix const& _other) { *this = SparseMatrix(_other); return *this; }
SparseMatrix& operator=(SparseMatrix&&) = default;
size_t rows() const { return m_row_start.size(); }
size_t columns() const { return m_col_start.size(); }