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_ROW_ACCESS_H
19#define PM_ROW_ACCESS_H
20
21#include <utility> //std::swap
22
23namespace Gudhi {
24namespace persistence_matrix {
25
33{
34 friend void swap([[maybe_unused]] Dummy_row_access& d1, [[maybe_unused]] Dummy_row_access& d2) {}
35
37 template <typename Index, class Row_container>
38 Dummy_row_access([[maybe_unused]] Index columnIndex, [[maybe_unused]] Row_container& rows) {}
39};
40
49template <class Master_matrix>
51{
52 public:
53 using Index = typename Master_matrix::Index;
54 using ID_index = typename Master_matrix::ID_index;
55 using Matrix_entry = typename Master_matrix::Matrix_entry;
56 using Row_container = typename Master_matrix::Row_container;
62 Row_access();
69 Row_access(Index columnIndex, Row_container* rows);
75 Row_access(Row_access&& other) noexcept;
76
83 void insert_entry(ID_index rowIndex, Matrix_entry* entry);
89 void unlink(Matrix_entry* entry);
99 void update_entry(const Matrix_entry& entry);
105 Index get_column_index() const;
106
110 friend void swap(Row_access& r1, Row_access& r2) {
111 std::swap(r1.rows_, r2.rows_);
112 std::swap(r1.columnIndex_, r2.columnIndex_);
113 }
114
115 protected:
116 Index columnIndex_;
117 Row_container* rows_;
119 private:
120 using Base_hook_matrix_row = typename Master_matrix::Base_hook_matrix_row;
121};
122
123template <class Master_matrix>
125 : columnIndex_(Master_matrix::template get_null_value<Index>()), rows_(nullptr)
126{}
127
128template <class Master_matrix>
130 : columnIndex_(columnIndex), rows_(rows)
131{}
132
133template <class Master_matrix>
135 : columnIndex_(std::exchange(other.columnIndex_, 0)), rows_(other.rows_)
136{}
137
138template <class Master_matrix>
140{
141 if (rows_ == nullptr) return;
142
143 if constexpr (!Master_matrix::Option_list::has_removable_rows) {
144 if (rows_->size() < rowIndex + 1) rows_->resize(rowIndex + 1);
145 }
146
147 // if has_removable_rows should op[] create non existing entry? If not, use try_emplace()
148 if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
149 rows_->operator[](rowIndex).push_back(*entry);
150 } else {
151 rows_->operator[](rowIndex).insert(*entry);
152 }
153}
154
155template <class Master_matrix>
157{
158 if (rows_ == nullptr) return;
159
160 if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
161 entry->Base_hook_matrix_row::unlink();
162 } else {
163 if constexpr (Master_matrix::Option_list::has_removable_rows) {
164 auto it = rows_->find(entry->get_row_index());
165 it->second.erase(*entry);
166 } else {
167 rows_->operator[](entry->get_row_index()).erase(*entry);
168 }
169 }
170}
171
172template <class Master_matrix>
174{
175 if constexpr (!Master_matrix::Option_list::has_intrusive_rows) {
176 if (rows_ == nullptr) return;
177 auto& row = rows_->at(entry.get_row_index());
178 auto it = row.find(entry);
179 it = row.erase(it);
180 row.insert(it, entry);
181 }
182}
183
184template <class Master_matrix>
186{
187 return columnIndex_;
188}
189
190} // namespace persistence_matrix
191} // namespace Gudhi
192
193#endif // PM_ROW_ACCESS_H
Class managing the row access for the columns.
Definition: row_access.h:51
typename Master_matrix::Matrix_entry Matrix_entry
Definition: row_access.h:55
Row_access()
Default constructor. Sets the column index to null index and the row container to nullptr....
Definition: row_access.h:124
typename Master_matrix::ID_index ID_index
Definition: row_access.h:54
typename Master_matrix::Row_container Row_container
Definition: row_access.h:56
void unlink(Matrix_entry *entry)
Removes the given entry from its row.
Definition: row_access.h:156
void insert_entry(ID_index rowIndex, Matrix_entry *entry)
Inserts the given entry at the given row index.
Definition: row_access.h:139
void update_entry(const Matrix_entry &entry)
If PersistenceMatrixOptions::has_intrusive_rows is false, updates the copy of the entry in its row....
Definition: row_access.h:173
typename Master_matrix::Index Index
Definition: row_access.h:53
friend void swap(Row_access &r1, Row_access &r2)
Swap operator.
Definition: row_access.h:110
Index get_column_index() const
Returns the MatIdx column index.
Definition: row_access.h:185
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of Row_access, if the row access is not enabled.
Definition: row_access.h:33