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 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
17
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
32struct Dummy_row_access {
33 friend void swap([[maybe_unused]] Dummy_row_access& d1, [[maybe_unused]] Dummy_row_access& d2) noexcept {}
34
35 Dummy_row_access() = default;
36
37 template <typename Index, class Row_container>
38 Dummy_row_access([[maybe_unused]] Index columnIndex, [[maybe_unused]] Row_container& rows)
39 {}
40};
41
50template <class Master_matrix>
52{
53 public:
54 using Index = typename Master_matrix::Index;
55 using ID_index = typename Master_matrix::ID_index;
56 using Matrix_entry = typename Master_matrix::Matrix_entry;
57 using Row_container = typename Master_matrix::Row_container;
58
63 Row_access();
70 Row_access(Index columnIndex, Row_container* rows);
76 Row_access(Row_access&& other) noexcept;
77
78 Row_access(const Row_access& other) = delete;
79 ~Row_access() = default;
80
87 void insert_entry(ID_index rowIndex, Matrix_entry* entry);
88
94 void unlink(Matrix_entry* entry);
95
105 void update_entry(const Matrix_entry& entry);
106
112 Index get_column_index() const;
113
114 Row_access& operator=(const Row_access& other) = delete;
115 Row_access& operator=(Row_access&& other) noexcept = delete;
116
120 friend void swap(Row_access& r1, Row_access& r2) noexcept
121 {
122 std::swap(r1.rows_, r2.rows_);
123 std::swap(r1.columnIndex_, r2.columnIndex_);
124 }
125
126 private:
127 Index columnIndex_;
128 Row_container* rows_;
129
130 using Base_hook_matrix_row = typename Master_matrix::Base_hook_matrix_row;
131};
132
133template <class Master_matrix>
135 : columnIndex_(Master_matrix::template get_null_value<Index>()), rows_(nullptr)
136{}
137
138template <class Master_matrix>
140 : columnIndex_(columnIndex), rows_(rows)
141{}
142
143template <class Master_matrix>
145 : columnIndex_(std::exchange(other.columnIndex_, 0)), rows_(other.rows_)
146{}
147
148template <class Master_matrix>
150{
151 if (rows_ == nullptr) return;
152
153 if constexpr (!Master_matrix::Option_list::has_removable_rows) {
154 if (rows_->size() < rowIndex + 1) rows_->resize(rowIndex + 1);
155 }
156
157 // if has_removable_rows should op[] create non existing entry? If not, use try_emplace()
158 if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
159 rows_->operator[](rowIndex).push_back(*entry);
160 } else {
161 rows_->operator[](rowIndex).insert(*entry);
162 }
163}
164
165template <class Master_matrix>
167{
168 if (rows_ == nullptr) return;
169
170 if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
171 entry->Base_hook_matrix_row::unlink();
172 } else {
173 if constexpr (Master_matrix::Option_list::has_removable_rows) {
174 auto it = rows_->find(entry->get_row_index());
175 it->second.erase(*entry);
176 } else {
177 rows_->operator[](entry->get_row_index()).erase(*entry);
178 }
179 }
180}
181
182template <class Master_matrix>
184{
185 if constexpr (!Master_matrix::Option_list::has_intrusive_rows) {
186 if (rows_ == nullptr) return;
187 auto& row = rows_->at(entry.get_row_index());
188 auto it = row.find(entry);
189 it = row.erase(it);
190 row.insert(it, entry);
191 }
192}
193
194template <class Master_matrix>
196{
197 return columnIndex_;
198}
199
200} // namespace persistence_matrix
201} // namespace Gudhi
202
203#endif // PM_ROW_ACCESS_H
typename Master_matrix::Matrix_entry Matrix_entry
Definition row_access.h:56
Row_access()
Default constructor. Sets the column index to null index and the row container to nullptr....
Definition row_access.h:134
typename Master_matrix::ID_index ID_index
Definition row_access.h:55
typename Master_matrix::Row_container Row_container
Definition row_access.h:57
void unlink(Matrix_entry *entry)
Removes the given entry from its row.
Definition row_access.h:166
void insert_entry(ID_index rowIndex, Matrix_entry *entry)
Inserts the given entry at the given row index.
Definition row_access.h:149
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:183
friend void swap(Row_access &r1, Row_access &r2) noexcept
Swap operator.
Definition row_access.h:120
typename Master_matrix::Index Index
Definition row_access.h:54
Index get_column_index() const
Returns the MatIdx column index.
Definition row_access.h:195
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14