Loading...
Searching...
No Matches
cell_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-24 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
19#ifndef PM_MATRIX_CELL_H
20#define PM_MATRIX_CELL_H
21
22#include <utility> //std::swap, std::exchange & std::move
23#include <functional> //std::hash
24
25namespace Gudhi {
26namespace persistence_matrix {
27
35{
37 template <typename index>
38 Dummy_cell_column_index_mixin([[maybe_unused]] index columnIndex) {}
39};
40
48{
50 template <class Field_element_type>
51 Dummy_cell_field_element_mixin([[maybe_unused]] Field_element_type t) {}
52};
53
61template <typename index>
63{
64 public:
68 Cell_column_index() : columnIndex_(-1){};
74 Cell_column_index(index columnIndex) : columnIndex_(columnIndex){};
80 Cell_column_index(const Cell_column_index& cell) : columnIndex_(cell.columnIndex_){};
86 Cell_column_index(Cell_column_index&& cell) noexcept : columnIndex_(std::exchange(cell.columnIndex_, 0)){};
87
93 index get_column_index() const { return columnIndex_; };
99 void set_column_index(index columnIndex) { columnIndex_ = columnIndex; }
100
105 std::swap(columnIndex_, other.columnIndex_);
106 return *this;
107 };
108
109 private:
110 index columnIndex_;
111};
112
120template <class Field_element_type>
122{
123 public:
127 Cell_field_element() : element_(0){};
133 Cell_field_element(Field_element_type element) : element_(element){};
139 Cell_field_element(const Cell_field_element& cell) : element_(cell.element_){};
145 Cell_field_element(Cell_field_element&& cell) noexcept : element_(std::move(cell.element_)){};
146
152 Field_element_type& get_element() { return element_; };
158 const Field_element_type& get_element() const { return element_; };
164 void set_element(const Field_element_type& element) { element_ = element; }
165
170 std::swap(element_, other.element_);
171 return *this;
172 };
173
174 private:
175 Field_element_type element_;
176};
177
188template <class Master_matrix>
189class Cell : public Master_matrix::Cell_column_index_option,
190 public Master_matrix::Cell_field_element_option,
191 public Master_matrix::row_hook_type,
192 public Master_matrix::column_hook_type
193{
194 private:
195 using col_opt = typename Master_matrix::Cell_column_index_option;
196 using field_opt = typename Master_matrix::Cell_field_element_option;
197
198 public:
199 using Master = Master_matrix;
200 using index = typename Master_matrix::index;
201 using id_index = typename Master_matrix::id_index;
202 using Field_element_type = typename Master_matrix::element_type;
207 Cell(){};
213 Cell(id_index rowIndex) : col_opt(), field_opt(), rowIndex_(rowIndex){};
220 Cell(index columnIndex, id_index rowIndex) : col_opt(columnIndex), field_opt(), rowIndex_(rowIndex){};
226 Cell(const Cell& cell)
227 : col_opt(static_cast<const col_opt&>(cell)),
228 field_opt(static_cast<const field_opt&>(cell)),
229 rowIndex_(cell.rowIndex_){};
235 Cell(Cell&& cell) noexcept
236 : col_opt(std::move(static_cast<col_opt&>(cell))),
237 field_opt(std::move(static_cast<field_opt&>(cell))),
238 rowIndex_(std::exchange(cell.rowIndex_, 0)){};
239
245 id_index get_row_index() const { return rowIndex_; };
251 void set_row_index(id_index rowIndex) { rowIndex_ = rowIndex; };
252
257 col_opt::operator=(other);
258 field_opt::operator=(other);
259 std::swap(rowIndex_, other.rowIndex_);
260 return *this;
261 };
262
271 friend bool operator<(const Cell& c1, const Cell& c2) { return c1.get_row_index() < c2.get_row_index(); }
280 friend bool operator==(const Cell& c1, const Cell& c2) { return c1.get_row_index() == c2.get_row_index(); }
281
287 operator id_index() const { return rowIndex_; }
293 operator std::pair<id_index, Field_element_type>() const {
294 if constexpr (Master_matrix::Option_list::is_z2) {
295 return {rowIndex_, 1};
296 } else {
297 return {rowIndex_, field_opt::element_};
298 }
299 }
300
301 private:
302 id_index rowIndex_;
303};
304
305} // namespace persistence_matrix
306} // namespace Gudhi
307
318template <class Master_matrix>
319struct std::hash<Gudhi::persistence_matrix::Cell<Master_matrix> > {
320 size_t operator()(const Gudhi::persistence_matrix::Cell<Master_matrix>& cell) const {
321 return std::hash<unsigned int>()(cell.get_row_index());
322 }
323};
324
325#endif // PM_MATRIX_CELL_H
Class managing the column index access of a cell.
Definition cell_types.h:63
void set_column_index(index columnIndex)
Sets the column index to the given value.
Definition cell_types.h:99
Cell_column_index & operator=(Cell_column_index other)
Assign operator.
Definition cell_types.h:104
Cell_column_index(Cell_column_index &&cell) noexcept
Move constructor.
Definition cell_types.h:86
Cell_column_index(index columnIndex)
Stores the given column index.
Definition cell_types.h:74
Cell_column_index()
Default constructor. Sets to the column index to -1.
Definition cell_types.h:68
index get_column_index() const
Returns the MatIdx column index stored in the cell.
Definition cell_types.h:93
Cell_column_index(const Cell_column_index &cell)
Copy constructor.
Definition cell_types.h:80
Class managing the value access of a cell.
Definition cell_types.h:122
Cell_field_element(const Cell_field_element &cell)
Copy constructor.
Definition cell_types.h:139
Cell_field_element(Field_element_type element)
Stores the given element.
Definition cell_types.h:133
Cell_field_element(Cell_field_element &&cell) noexcept
Move constructor.
Definition cell_types.h:145
Cell_field_element()
Default constructor. Sets to the element to 0.
Definition cell_types.h:127
Field_element_type & get_element()
Returns the value stored in the cell.
Definition cell_types.h:152
const Field_element_type & get_element() const
Returns the value stored in the cell.
Definition cell_types.h:158
void set_element(const Field_element_type &element)
Sets the value.
Definition cell_types.h:164
Cell_field_element & operator=(Cell_field_element other)
Assign operator.
Definition cell_types.h:169
Matrix cell class. Stores by default only the row index it belongs to, but can also store its column ...
Definition cell_types.h:193
typename Master_matrix::id_index id_index
Definition cell_types.h:201
Cell(index columnIndex, id_index rowIndex)
Constructs a cell with given row and column index. Other possible attributes are set at default value...
Definition cell_types.h:220
friend bool operator==(const Cell &c1, const Cell &c2)
Equality comparator.
Definition cell_types.h:280
Cell(id_index rowIndex)
Constructs a cell with given row index. Other possible attributes are set at default values.
Definition cell_types.h:213
id_index get_row_index() const
Returns the row index stored in the cell.
Definition cell_types.h:245
Cell & operator=(Cell other)
Assign operator.
Definition cell_types.h:256
Master_matrix Master
Definition cell_types.h:199
typename Master_matrix::index index
Definition cell_types.h:200
Cell(const Cell &cell)
Copy constructor.
Definition cell_types.h:226
Cell(Cell &&cell) noexcept
Move constructor.
Definition cell_types.h:235
typename Master_matrix::element_type Field_element_type
Definition cell_types.h:202
Cell()
Constructs an cell with all attributes at default values.
Definition cell_types.h:207
friend bool operator<(const Cell &c1, const Cell &c2)
Strictly smaller than comparator.
Definition cell_types.h:271
void set_row_index(id_index rowIndex)
Sets the row index stored in the cell.
Definition cell_types.h:251
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14
Empty structure. Inheritated instead of Cell_column_index, when the row access is disabled.
Definition cell_types.h:35
Empty structure. Inheritated instead of Cell_field_element, when PersistenceMatrixOptions::is_z2 is t...
Definition cell_types.h:48