Loading...
Searching...
No Matches
matrix_row_access.h
Go to the documentation of this file.
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2022-24 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PM_BASE_MATRIX_RA_H
#define PM_BASE_MATRIX_RA_H
#include <utility> //std::move
namespace Gudhi {
namespace persistence_matrix {
struct Dummy_matrix_row_access
{
Dummy_matrix_row_access([[maybe_unused]] unsigned int numberOfRows = 0){};
friend void swap([[maybe_unused]] Dummy_matrix_row_access& d1, [[maybe_unused]] Dummy_matrix_row_access& d2) {}
};
template <typename Row, typename Row_container, bool has_removable_rows, typename ID_index>
class Matrix_row_access
{
public:
Matrix_row_access() : rows_(new Row_container()){};
Matrix_row_access(unsigned int numberOfRows) : rows_(new Row_container()) {
if constexpr (!has_removable_rows) {
rows_->resize(numberOfRows);
}
}
Matrix_row_access(const Matrix_row_access& toCopy)
: rows_(new Row_container()) // as the matrix is rebuild, the rows should not be copied.
{
if constexpr (!has_removable_rows) {
rows_->resize(toCopy.rows_->size());
}
}
Matrix_row_access(Matrix_row_access&& other) noexcept : rows_(std::exchange(other.rows_, nullptr)) {}
~Matrix_row_access() { delete rows_; }
Row& get_row(ID_index rowIndex) {
if constexpr (has_removable_rows) {
return rows_->at(rowIndex);
} else {
return rows_->operator[](rowIndex);
}
}
const Row& get_row(ID_index rowIndex) const {
if constexpr (has_removable_rows) {
return rows_->at(rowIndex);
} else {
return rows_->operator[](rowIndex);
}
}
void erase_empty_row(ID_index rowIndex) {
static_assert(has_removable_rows, "'erase_empty_row' is not implemented for the chosen options.");
auto it = rows_->find(rowIndex);
if (it != rows_->end() && it->second.empty()) rows_->erase(it);
}
Matrix_row_access& operator=(const Matrix_row_access& other) {
if constexpr (has_removable_rows)
rows_->reserve(other.rows_->size());
else
rows_->resize(other.rows_->size());
return *this;
}
friend void swap(Matrix_row_access& matrix1, Matrix_row_access& matrix2) { std::swap(matrix1.rows_, matrix2.rows_); }
protected:
Row_container* rows_;
};
} // namespace persistence_matrix
} // namespace Gudhi
#endif // PM_BASE_MATRIX_RA_H
Gudhi::persistence_matrix::Matrix_row_access::swap
friend void swap(Matrix_row_access &matrix1, Matrix_row_access &matrix2)
Swap operator.
Definition matrix_row_access.h:151
Gudhi::persistence_matrix::Matrix_row_access::get_row
const Row & get_row(ID_index rowIndex) const
Returns the row at the given row index. The type of the row depends on the chosen options,...
Definition matrix_row_access.h:118
Gudhi::persistence_matrix::Matrix_row_access::Matrix_row_access
Matrix_row_access()
Default constructor.
Definition matrix_row_access.h:59
Gudhi::persistence_matrix::Matrix_row_access::operator=
Matrix_row_access & operator=(const Matrix_row_access &other)
Assign operator.
Definition matrix_row_access.h:141
Gudhi::persistence_matrix::Matrix_row_access::~Matrix_row_access
~Matrix_row_access()
Destructor.
Definition matrix_row_access.h:93
Gudhi::persistence_matrix::Matrix_row_access::erase_empty_row
void erase_empty_row(ID_index rowIndex)
Only available if PersistenceMatrixOptions::has_removable_rows is true. Removes the given row from th...
Definition matrix_row_access.h:131
Gudhi::persistence_matrix::Matrix_row_access::get_row
Row & get_row(ID_index rowIndex)
Returns the row at the given row index. The type of the row depends on the chosen options,...
Definition matrix_row_access.h:103
Gudhi::persistence_matrix::Matrix_row_access::Matrix_row_access
Matrix_row_access(const Matrix_row_access &toCopy)
Copy constructor.
Definition matrix_row_access.h:77
Gudhi::persistence_matrix::Matrix_row_access::Matrix_row_access
Matrix_row_access(unsigned int numberOfRows)
Constructor reserving space for the given number of rows.
Definition matrix_row_access.h:67
Gudhi::persistence_matrix::Matrix_row_access::Matrix_row_access
Matrix_row_access(Matrix_row_access &&other) noexcept
Move constructor.
Definition matrix_row_access.h:89
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14