All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
matrix_row_access.h
Go to the documentation of this file.
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Hannah Schreiber
4 *
5 * Copyright (C) 2022-24 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
18#ifndef PM_BASE_MATRIX_RA_H
19#define PM_BASE_MATRIX_RA_H
20
21#include <utility> //std::move
22
23namespace Gudhi {
24namespace persistence_matrix {
25
33{
34 Dummy_matrix_row_access([[maybe_unused]] unsigned int numberOfRows = 0){};
35
36 friend void swap([[maybe_unused]] Dummy_matrix_row_access& d1, [[maybe_unused]] Dummy_matrix_row_access& d2) {}
37};
38
52template <typename Row, typename Row_container, bool has_removable_rows, typename ID_index>
54{
55 public:
59 Matrix_row_access() : rows_(new Row_container()){};
67 Matrix_row_access(unsigned int numberOfRows) : rows_(new Row_container()) {
68 if constexpr (!has_removable_rows) {
69 rows_->resize(numberOfRows);
70 }
71 }
78 : rows_(new Row_container()) // as the matrix is rebuild, the rows should not be copied.
79 {
80 if constexpr (!has_removable_rows) {
81 rows_->resize(toCopy.rows_->size());
82 }
83 }
89 Matrix_row_access(Matrix_row_access&& other) noexcept : rows_(std::exchange(other.rows_, nullptr)) {}
93 ~Matrix_row_access() { delete rows_; }
94
103 Row& get_row(ID_index rowIndex) {
104 if constexpr (has_removable_rows) {
105 return rows_->at(rowIndex);
106 } else {
107 return rows_->operator[](rowIndex);
108 }
109 }
118 const Row& get_row(ID_index rowIndex) const {
119 if constexpr (has_removable_rows) {
120 return rows_->at(rowIndex);
121 } else {
122 return rows_->operator[](rowIndex);
123 }
124 }
131 void erase_empty_row(ID_index rowIndex) {
132 static_assert(has_removable_rows, "'erase_empty_row' is not implemented for the chosen options.");
133
134 auto it = rows_->find(rowIndex);
135 if (it != rows_->end() && it->second.empty()) rows_->erase(it);
136 }
137
142 if constexpr (has_removable_rows)
143 rows_->reserve(other.rows_->size());
144 else
145 rows_->resize(other.rows_->size());
146 return *this;
147 }
151 friend void swap(Matrix_row_access& matrix1, Matrix_row_access& matrix2) { std::swap(matrix1.rows_, matrix2.rows_); }
152
153 protected:
158 Row_container* rows_;
159};
160
161} // namespace persistence_matrix
162} // namespace Gudhi
163
164#endif // PM_BASE_MATRIX_RA_H
Class managing the row access for the inheriting matrix.
Definition: matrix_row_access.h:54
friend void swap(Matrix_row_access &matrix1, Matrix_row_access &matrix2)
Swap operator.
Definition: matrix_row_access.h:151
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
Matrix_row_access()
Default constructor.
Definition: matrix_row_access.h:59
Matrix_row_access & operator=(const Matrix_row_access &other)
Assign operator.
Definition: matrix_row_access.h:141
~Matrix_row_access()
Destructor.
Definition: matrix_row_access.h:93
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
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
Matrix_row_access(const Matrix_row_access &toCopy)
Copy constructor.
Definition: matrix_row_access.h:77
Matrix_row_access(unsigned int numberOfRows)
Constructor reserving space for the given number of rows.
Definition: matrix_row_access.h:67
Matrix_row_access(Matrix_row_access &&other) noexcept
Move constructor.
Definition: matrix_row_access.h:89
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of Matrix_row_access, when the the row access is not enabled.
Definition: matrix_row_access.h:33