Loading...
Searching...
No Matches
entry_types.h
Go to the documentation of this file.
/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
* See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
* Author(s): Hannah Schreiber
*
* Copyright (C) 2022-24 Inria
*
* Modification(s):
* - YYYY/MM Author: Description of the modification
*/
#ifndef PM_MATRIX_ENTRY_H
#define PM_MATRIX_ENTRY_H
#include <utility> //std::swap, std::exchange & std::move
#include <functional> //std::hash
namespace Gudhi {
namespace persistence_matrix {
struct Dummy_entry_column_index_mixin
{
Dummy_entry_column_index_mixin() {}
template <typename Index>
Dummy_entry_column_index_mixin([[maybe_unused]] Index columnIndex) {}
};
struct Dummy_entry_field_element_mixin
{
Dummy_entry_field_element_mixin() {}
template <class Field_element>
Dummy_entry_field_element_mixin([[maybe_unused]] Field_element t) {}
};
template <typename Index>
class Entry_column_index
{
public:
Entry_column_index() : columnIndex_(-1){};
Entry_column_index(Index columnIndex) : columnIndex_(columnIndex){};
Entry_column_index(const Entry_column_index& entry) : columnIndex_(entry.columnIndex_){};
Entry_column_index(Entry_column_index&& entry) noexcept : columnIndex_(std::exchange(entry.columnIndex_, 0)){};
Index get_column_index() const { return columnIndex_; };
void set_column_index(Index columnIndex) { columnIndex_ = columnIndex; }
Entry_column_index& operator=(Entry_column_index other) {
std::swap(columnIndex_, other.columnIndex_);
return *this;
};
private:
Index columnIndex_;
};
template <class Field_element>
class Entry_field_element
{
public:
Entry_field_element() : element_(0){};
Entry_field_element(Field_element element) : element_(element){};
Entry_field_element(const Entry_field_element& entry) : element_(entry.element_){};
Entry_field_element(Entry_field_element&& entry) noexcept : element_(std::move(entry.element_)){};
Field_element& get_element() { return element_; };
const Field_element& get_element() const { return element_; };
void set_element(const Field_element& element) { element_ = element; }
Entry_field_element& operator=(Entry_field_element other) {
std::swap(element_, other.element_);
return *this;
};
private:
Field_element element_;
};
template <class Master_matrix>
class Entry : public Master_matrix::Entry_column_index_option,
public Master_matrix::Entry_field_element_option,
public Master_matrix::Row_hook,
public Master_matrix::Column_hook
{
private:
using col_opt = typename Master_matrix::Entry_column_index_option;
using field_opt = typename Master_matrix::Entry_field_element_option;
public:
using Master = Master_matrix;
using Index = typename Master_matrix::Index;
using ID_index = typename Master_matrix::ID_index;
using Field_element = typename Master_matrix::Element;
Entry(){};
Entry(ID_index rowIndex) : col_opt(), field_opt(), rowIndex_(rowIndex){};
Entry(Index columnIndex, ID_index rowIndex) : col_opt(columnIndex), field_opt(), rowIndex_(rowIndex){};
Entry(const Entry& entry)
: col_opt(static_cast<const col_opt&>(entry)),
field_opt(static_cast<const field_opt&>(entry)),
rowIndex_(entry.rowIndex_){};
Entry(Entry&& entry) noexcept
: col_opt(std::move(static_cast<col_opt&>(entry))),
field_opt(std::move(static_cast<field_opt&>(entry))),
rowIndex_(std::exchange(entry.rowIndex_, 0)){};
ID_index get_row_index() const { return rowIndex_; };
void set_row_index(ID_index rowIndex) { rowIndex_ = rowIndex; };
Entry& operator=(Entry other) {
col_opt::operator=(other);
field_opt::operator=(other);
std::swap(rowIndex_, other.rowIndex_);
return *this;
};
friend bool operator<(const Entry& c1, const Entry& c2) { return c1.get_row_index() < c2.get_row_index(); }
friend bool operator==(const Entry& c1, const Entry& c2) { return c1.get_row_index() == c2.get_row_index(); }
operator ID_index() const { return rowIndex_; }
operator std::pair<ID_index, Field_element>() const {
if constexpr (Master_matrix::Option_list::is_z2) {
return {rowIndex_, 1};
} else {
return {rowIndex_, field_opt::element_};
}
}
private:
ID_index rowIndex_;
};
} // namespace persistence_matrix
} // namespace Gudhi
template <class Master_matrix>
struct std::hash<Gudhi::persistence_matrix::Entry<Master_matrix> > {
std::size_t operator()(const Gudhi::persistence_matrix::Entry<Master_matrix>& entry) const {
return std::hash<unsigned int>()(entry.get_row_index());
}
};
#endif // PM_MATRIX_ENTRY_H
Gudhi::persistence_matrix::Entry_column_index::operator=
Entry_column_index & operator=(Entry_column_index other)
Assign operator.
Definition entry_types.h:106
Gudhi::persistence_matrix::Entry_column_index::Entry_column_index
Entry_column_index()
Default constructor. Sets to the column index to -1.
Definition entry_types.h:70
Gudhi::persistence_matrix::Entry_column_index::Entry_column_index
Entry_column_index(Index columnIndex)
Stores the given column index.
Definition entry_types.h:76
Gudhi::persistence_matrix::Entry_column_index::Entry_column_index
Entry_column_index(const Entry_column_index &entry)
Copy constructor.
Definition entry_types.h:82
Gudhi::persistence_matrix::Entry_column_index::set_column_index
void set_column_index(Index columnIndex)
Sets the column index to the given value.
Definition entry_types.h:101
Gudhi::persistence_matrix::Entry_column_index::Entry_column_index
Entry_column_index(Entry_column_index &&entry) noexcept
Move constructor.
Definition entry_types.h:88
Gudhi::persistence_matrix::Entry_column_index::get_column_index
Index get_column_index() const
Returns the MatIdx column index stored in the entry.
Definition entry_types.h:95
Gudhi::persistence_matrix::Entry_field_element::set_element
void set_element(const Field_element &element)
Sets the value.
Definition entry_types.h:166
Gudhi::persistence_matrix::Entry_field_element::get_element
const Field_element & get_element() const
Returns the value stored in the entry.
Definition entry_types.h:160
Gudhi::persistence_matrix::Entry_field_element::Entry_field_element
Entry_field_element(const Entry_field_element &entry)
Copy constructor.
Definition entry_types.h:141
Gudhi::persistence_matrix::Entry_field_element::Entry_field_element
Entry_field_element(Entry_field_element &&entry) noexcept
Move constructor.
Definition entry_types.h:147
Gudhi::persistence_matrix::Entry_field_element::get_element
Field_element & get_element()
Returns the value stored in the entry.
Definition entry_types.h:154
Gudhi::persistence_matrix::Entry_field_element::Entry_field_element
Entry_field_element(Field_element element)
Stores the given element.
Definition entry_types.h:135
Gudhi::persistence_matrix::Entry_field_element::operator=
Entry_field_element & operator=(Entry_field_element other)
Assign operator.
Definition entry_types.h:171
Gudhi::persistence_matrix::Entry_field_element::Entry_field_element
Entry_field_element()
Default constructor. Sets to the element to 0.
Definition entry_types.h:129
Gudhi::persistence_matrix::Entry
Matrix entry class. Stores by default only the row index it belongs to, but can also store its column...
Definition entry_types.h:195
Gudhi::persistence_matrix::Entry< Matrix< PersistenceMatrixOptions > >::Master
Matrix< PersistenceMatrixOptions > Master
Definition entry_types.h:201
Gudhi::persistence_matrix::Entry< Matrix< PersistenceMatrixOptions > >::Index
typename Matrix< PersistenceMatrixOptions >::Index Index
Definition entry_types.h:202
Gudhi::persistence_matrix::Entry< Matrix< PersistenceMatrixOptions > >::ID_index
typename Matrix< PersistenceMatrixOptions >::ID_index ID_index
Definition entry_types.h:203
Gudhi::persistence_matrix::Entry::Entry
Entry(const Entry &entry)
Copy constructor.
Definition entry_types.h:228
Gudhi::persistence_matrix::Entry::Entry
Entry()
Constructs an entry with all attributes at default values.
Definition entry_types.h:209
Gudhi::persistence_matrix::Entry::set_row_index
void set_row_index(ID_index rowIndex)
Sets the row index stored in the entry.
Definition entry_types.h:253
Gudhi::persistence_matrix::Entry::operator==
friend bool operator==(const Entry &c1, const Entry &c2)
Equality comparator.
Definition entry_types.h:282
Gudhi::persistence_matrix::Entry::Entry
Entry(ID_index rowIndex)
Constructs an entry with given row index. Other possible attributes are set at default values.
Definition entry_types.h:215
Gudhi::persistence_matrix::Entry::Entry
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:222
Gudhi::persistence_matrix::Entry::operator=
Entry & operator=(Entry other)
Assign operator.
Definition entry_types.h:258
Gudhi::persistence_matrix::Entry::get_row_index
ID_index get_row_index() const
Returns the row index stored in the entry.
Definition entry_types.h:247
Gudhi::persistence_matrix::Entry< Matrix< PersistenceMatrixOptions > >::Field_element
typename Matrix< PersistenceMatrixOptions >::Element Field_element
Definition entry_types.h:204
Gudhi::persistence_matrix::Entry::operator<
friend bool operator<(const Entry &c1, const Entry &c2)
Strictly smaller than comparator.
Definition entry_types.h:273
Gudhi::persistence_matrix::Entry::Entry
Entry(Entry &&entry) noexcept
Move constructor.
Definition entry_types.h:237
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14