This commit is contained in:
chriseth 2022-08-14 22:10:13 +02:00
parent d308cf8d96
commit 64e41febf2
2 changed files with 17 additions and 36 deletions

View File

@ -53,10 +53,7 @@ void SparseMatrix::addMultipleOfRow(size_t _sourceRow, size_t _targetRow, ration
target = next;
}
}
else if (!target)
target = appendToRow(_targetRow, source->col, _factor * source->value)->next_in_row;
else
target = prependInRow(*target, source->col, _factor * source->value)->next_in_row;
target = prependInRow(target, _targetRow, source->col, _factor * source->value)->next_in_row;
source = source->next_in_row;
}
@ -95,52 +92,37 @@ void SparseMatrix::remove(SparseMatrix::Entry& _e)
m_col_end[_e.col] = _e.prev_in_col;
}
SparseMatrix::Entry* SparseMatrix::appendToRow(size_t _row, size_t _column, rational _value)
SparseMatrix::Entry* SparseMatrix::prependInRow(Entry* _successor, size_t _row, size_t _column, rational _value)
{
// TODO could be combined with prependInRow
// with successor being nullptr
m_elements.emplace_back(make_unique<Entry>(Entry{
move(_value),
_row,
_column,
m_row_end[_row],
nullptr,
_successor,
nullptr,
nullptr
}));
Entry* e = m_elements.back().get();
if (m_row_end[_row])
m_row_end[_row]->next_in_row = e;
if (_successor)
{
e->prev_in_row = _successor->prev_in_row;
_successor->prev_in_row = e;
}
else
{
e->prev_in_row = m_row_end[_row];
m_row_end[_row] = e;
if (!m_row_start[_row])
}
if (e->prev_in_row)
e->prev_in_row->next_in_row = e;
else
m_row_start[_row] = e;
adjustColumnProperties(*e);
return e;
}
SparseMatrix::Entry* SparseMatrix::prependInRow(Entry& _successor, size_t _column, rational _value)
{
size_t row = _successor.row;
m_elements.emplace_back(make_unique<Entry>(Entry{
move(_value),
row,
_column,
_successor.prev_in_row,
&_successor,
nullptr,
nullptr
}));
Entry* e = m_elements.back().get();
_successor.prev_in_row = e;
if (m_row_start[row] == &_successor)
m_row_start[row] = e;
adjustColumnProperties(*e);
return e;
}
void SparseMatrix::adjustColumnProperties(Entry& _entry)
{
size_t column = _entry.col;

View File

@ -211,8 +211,7 @@ public:
private:
void remove(Entry& _entry);
Entry* appendToRow(size_t _row, size_t _column, rational _value);
Entry* prependInRow(Entry& _successor, size_t _column, rational _value);
Entry* prependInRow(Entry* _successor, size_t _row, size_t _column, rational _value);
void adjustColumnProperties(Entry& _entry);
std::vector<std::unique_ptr<Entry>> m_elements;