Loading...
Searching...
No Matches
entry_types.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
20
21#ifndef PM_MATRIX_ENTRY_H
22#define PM_MATRIX_ENTRY_H
23
24#include <utility> //std::swap, std::exchange & std::move
25#include <functional> //std::hash
26
27namespace Gudhi {
28namespace persistence_matrix {
29
36struct Dummy_entry_column_index_mixin {
37 Dummy_entry_column_index_mixin() = default;
38
39 template <typename Index>
40 Dummy_entry_column_index_mixin([[maybe_unused]] Index columnIndex)
41 {}
42};
43
50struct Dummy_entry_field_element_mixin {
51 Dummy_entry_field_element_mixin() = default;
52
53 template <class Field_element>
54 Dummy_entry_field_element_mixin([[maybe_unused]] Field_element t)
55 {}
56
57 static constexpr bool get_element() { return true; };
58 static constexpr void set_element(bool /* element */) {}
59};
60
68template <typename Index>
70{
71 public:
75 Entry_column_index() : columnIndex_(-1) {};
81 Entry_column_index(Index columnIndex) : columnIndex_(columnIndex) {};
82
88 Index get_column_index() const { return columnIndex_; };
89
95 void set_column_index(Index columnIndex) { columnIndex_ = columnIndex; }
96
97 private:
98 Index columnIndex_;
99};
100
108template <class Field_element>
110{
111 public:
115 Entry_field_element() : element_(0) {};
121 Entry_field_element(Field_element element) : element_(std::move(element)) {};
122
128 Field_element& get_element() { return element_; };
129
135 const Field_element& get_element() const { return element_; };
136
142 void set_element(const Field_element& element) { element_ = element; }
143
144 private:
145 Field_element element_;
146};
147
158template <class Master_matrix>
159class Entry : public Master_matrix::Entry_column_index_option,
160 public Master_matrix::Entry_field_element_option,
161 public Master_matrix::Row_hook,
162 public Master_matrix::Column_hook
163{
164 private:
165 using col_opt = typename Master_matrix::Entry_column_index_option;
166 using field_opt = typename Master_matrix::Entry_field_element_option;
167
168 public:
169 using Master = Master_matrix;
170 using Index = typename Master_matrix::Index;
171 using ID_index = typename Master_matrix::ID_index;
172 using Field_element = typename Master_matrix::Element;
173
177 Entry() = default;
183 Entry(ID_index rowIndex) : col_opt(), field_opt(), rowIndex_(rowIndex) {};
190 Entry(Index columnIndex, ID_index rowIndex) : col_opt(columnIndex), field_opt(), rowIndex_(rowIndex) {};
196 Entry(const Entry& entry)
197 : col_opt(static_cast<const col_opt&>(entry)),
198 field_opt(static_cast<const field_opt&>(entry)),
199 rowIndex_(entry.rowIndex_) {};
200
205 Entry(Entry&& entry) noexcept
206 : col_opt(std::move(static_cast<col_opt&>(entry))),
207 field_opt(std::move(static_cast<field_opt&>(entry))),
208 rowIndex_(std::exchange(entry.rowIndex_, 0)) {};
209
210 ~Entry() = default;
211
217 ID_index get_row_index() const { return rowIndex_; };
218
224 void set_row_index(ID_index rowIndex) { rowIndex_ = rowIndex; };
225
230 {
231 col_opt::operator=(std::move(other));
232 field_opt::operator=(std::move(other));
233 std::swap(rowIndex_, other.rowIndex_);
234 return *this;
235 };
236
240 Entry& operator=(Entry&& other) && noexcept
241 {
242 if (this == &other) return *this;
243
244 col_opt::operator=(std::move(other));
245 field_opt::operator=(std::move(other));
246 rowIndex_ = std::exchange(other.rowIndex_, 0);
247 return *this;
248 };
249
258 friend bool operator<(const Entry& c1, const Entry& c2) { return c1.get_row_index() < c2.get_row_index(); }
259
268 friend bool operator==(const Entry& c1, const Entry& c2) { return c1.get_row_index() == c2.get_row_index(); }
269
275 operator ID_index() const { return rowIndex_; }
276
282 operator std::pair<ID_index, Field_element>() const
283 {
284 return {rowIndex_, field_opt::get_element()};
285 }
286
287 private:
288 ID_index rowIndex_;
289};
290
291} // namespace persistence_matrix
292} // namespace Gudhi
293
304template <class Master_matrix>
305struct std::hash<Gudhi::persistence_matrix::Entry<Master_matrix> > {
306 std::size_t operator()(const Gudhi::persistence_matrix::Entry<Master_matrix>& entry) const
307 {
308 return std::hash<unsigned int>()(entry.get_row_index());
309 }
310};
311
312#endif // PM_MATRIX_ENTRY_H
Entry_column_index()
Default constructor. Sets to the column index to -1.
Definition entry_types.h:75
Entry_column_index(Index columnIndex)
Stores the given column index.
Definition entry_types.h:81
void set_column_index(Index columnIndex)
Sets the column index to the given value.
Definition entry_types.h:95
Index get_column_index() const
Returns the MatIdx column index stored in the entry.
Definition entry_types.h:88
void set_element(const Field_element &element)
Sets the value.
Definition entry_types.h:142
const Field_element & get_element() const
Returns the value stored in the entry.
Definition entry_types.h:135
Field_element & get_element()
Returns the value stored in the entry.
Definition entry_types.h:128
Entry_field_element(Field_element element)
Stores the given element.
Definition entry_types.h:121
Entry_field_element()
Default constructor. Sets to the element to 0.
Definition entry_types.h:115
Matrix entry class. Stores by default only the row index it belongs to, but can also store its column...
Definition entry_types.h:163
Matrix< PersistenceMatrixOptions > Master
Definition entry_types.h:169
typename Matrix< PersistenceMatrixOptions >::Index Index
Definition entry_types.h:170
typename Matrix< PersistenceMatrixOptions >::ID_index ID_index
Definition entry_types.h:171
Entry(const Entry &entry)
Copy constructor.
Definition entry_types.h:196
Entry & operator=(Entry &&other) &&noexcept
Move assign operator.
Definition entry_types.h:240
void set_row_index(ID_index rowIndex)
Sets the row index stored in the entry.
Definition entry_types.h:224
friend bool operator==(const Entry &c1, const Entry &c2)
Equality comparator.
Definition entry_types.h:268
Entry(ID_index rowIndex)
Constructs an entry with given row index. Other possible attributes are set at default values.
Definition entry_types.h:183
Entry & operator=(Entry other) &
Assign operator.
Definition entry_types.h:229
Entry(Index columnIndex, ID_index rowIndex)
Constructs an entry with given row and column index. Other possible attributes are set at default val...
Definition entry_types.h:190
ID_index get_row_index() const
Returns the row index stored in the entry.
Definition entry_types.h:217
typename Matrix< PersistenceMatrixOptions >::Element Field_element
Definition entry_types.h:172
Entry()=default
Constructs an entry with all attributes at default values.
friend bool operator<(const Entry &c1, const Entry &c2)
Strictly smaller than comparator.
Definition entry_types.h:258
Entry(Entry &&entry) noexcept
Move constructor.
Definition entry_types.h:205
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
STL namespace.