Loading...
Searching...
No Matches
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
17#ifndef PM_ROW_ACCESS_H
18#define PM_ROW_ACCESS_H
19
20#include <utility> //std::swap
21
22namespace Gudhi {
23namespace persistence_matrix {
24
32{
33 friend void swap([[maybe_unused]] Dummy_row_access& d1, [[maybe_unused]] Dummy_row_access& d2) {}
34
36 template <typename index, class Row_container_type>
37 Dummy_row_access([[maybe_unused]] index columnIndex, [[maybe_unused]] Row_container_type& rows) {}
38};
39
48template <class Master_matrix>
50{
51 public:
52 using index = typename Master_matrix::index;
53 using id_index = typename Master_matrix::id_index;
54 using Cell_type = typename Master_matrix::Cell_type;
55 using Row_container_type = typename Master_matrix::row_container_type;
61 Row_access();
68 Row_access(index columnIndex, Row_container_type* rows);
74 Row_access(Row_access&& other) noexcept;
75
82 void insert_cell(id_index rowIndex, Cell_type* cell);
88 void unlink(Cell_type* cell);
98 void update_cell(const Cell_type& cell);
104 index get_column_index() const;
105
109 friend void swap(Row_access& r1, Row_access& r2) {
110 std::swap(r1.rows_, r2.rows_);
111 std::swap(r1.columnIndex_, r2.columnIndex_);
112 }
113
114 // void set_rows(Row_container_type *rows);
115
116 protected:
117 index columnIndex_;
118 Row_container_type* rows_;
120 private:
121 using base_hook_matrix_row = typename Master_matrix::base_hook_matrix_row;
122};
123
124template <class Master_matrix>
125inline Row_access<Master_matrix>::Row_access() : columnIndex_(-1), 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(*cell);
150 } else {
151 rows_->operator[](rowIndex).insert(*cell);
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 cell->base_hook_matrix_row::unlink();
162 } else {
163 if constexpr (Master_matrix::Option_list::has_removable_rows) {
164 auto it = rows_->find(cell->get_row_index());
165 it->second.erase(*cell);
166 } else {
167 rows_->operator[](cell->get_row_index()).erase(*cell);
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(cell.get_row_index());
178 auto it = row.find(cell);
179 it = row.erase(it);
180 row.insert(it, cell);
181 }
182}
183
184template <class Master_matrix>
186{
187 return columnIndex_;
188}
189
190// template<class Master_matrix>
191// inline void Row_access<Master_matrix>::set_rows(Row_container_type *rows)
192// {
193// rows_ = rows;
194// }
195
196} // namespace persistence_matrix
197} // namespace Gudhi
198
199#endif // PM_ROW_ACCESS_H
Class managing the row access for the columns.
Definition row_access.h:50
void unlink(Cell_type *cell)
Removes the given cell from its row.
Definition row_access.h:156
typename Master_matrix::index index
Definition row_access.h:52
typename Master_matrix::id_index id_index
Definition row_access.h:53
Row_access()
Default constructor. Sets the column index to -1 and the row container to nullptr....
Definition row_access.h:125
typename Master_matrix::Cell_type Cell_type
Definition row_access.h:54
typename Master_matrix::row_container_type Row_container_type
Definition row_access.h:55
index get_column_index() const
Returns the MatIdx column index.
Definition row_access.h:185
void update_cell(const Cell_type &cell)
If PersistenceMatrixOptions::has_intrusive_rows is false, updates the copy of the cell in its row....
Definition row_access.h:173
friend void swap(Row_access &r1, Row_access &r2)
Swap operator.
Definition row_access.h:109
void insert_cell(id_index rowIndex, Cell_type *cell)
Inserts the given cell at the given row index.
Definition row_access.h:139
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of Row_access, if the row access is not enabled.
Definition row_access.h:32