Loading...
Searching...
No Matches
row_access.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_ROW_ACCESS_H
#define PM_ROW_ACCESS_H
#include <utility> //std::swap
namespace Gudhi {
namespace persistence_matrix {
struct Dummy_row_access
{
friend void swap([[maybe_unused]] Dummy_row_access& d1, [[maybe_unused]] Dummy_row_access& d2) {}
Dummy_row_access() {}
template <typename Index, class Row_container>
Dummy_row_access([[maybe_unused]] Index columnIndex, [[maybe_unused]] Row_container& rows) {}
};
template <class Master_matrix>
class Row_access
{
public:
using Index = typename Master_matrix::Index;
using ID_index = typename Master_matrix::ID_index;
using Matrix_entry = typename Master_matrix::Matrix_entry;
using Row_container = typename Master_matrix::Row_container;
Row_access();
Row_access(Index columnIndex, Row_container* rows);
Row_access(Row_access&& other) noexcept;
void insert_entry(ID_index rowIndex, Matrix_entry* entry);
void unlink(Matrix_entry* entry);
void update_entry(const Matrix_entry& entry);
Index get_column_index() const;
friend void swap(Row_access& r1, Row_access& r2) {
std::swap(r1.rows_, r2.rows_);
std::swap(r1.columnIndex_, r2.columnIndex_);
}
protected:
Index columnIndex_;
Row_container* rows_;
private:
using Base_hook_matrix_row = typename Master_matrix::Base_hook_matrix_row;
};
template <class Master_matrix>
inline Row_access<Master_matrix>::Row_access()
: columnIndex_(Master_matrix::template get_null_value<Index>()), rows_(nullptr)
{}
template <class Master_matrix>
inline Row_access<Master_matrix>::Row_access(Index columnIndex, Row_container* rows)
: columnIndex_(columnIndex), rows_(rows)
{}
template <class Master_matrix>
inline Row_access<Master_matrix>::Row_access(Row_access&& other) noexcept
: columnIndex_(std::exchange(other.columnIndex_, 0)), rows_(other.rows_)
{}
template <class Master_matrix>
inline void Row_access<Master_matrix>::insert_entry(ID_index rowIndex, Matrix_entry* entry)
{
if (rows_ == nullptr) return;
if constexpr (!Master_matrix::Option_list::has_removable_rows) {
if (rows_->size() < rowIndex + 1) rows_->resize(rowIndex + 1);
}
// if has_removable_rows should op[] create non existing entry? If not, use try_emplace()
if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
rows_->operator[](rowIndex).push_back(*entry);
} else {
rows_->operator[](rowIndex).insert(*entry);
}
}
template <class Master_matrix>
inline void Row_access<Master_matrix>::unlink(Matrix_entry* entry)
{
if (rows_ == nullptr) return;
if constexpr (Master_matrix::Option_list::has_intrusive_rows) {
entry->Base_hook_matrix_row::unlink();
} else {
if constexpr (Master_matrix::Option_list::has_removable_rows) {
auto it = rows_->find(entry->get_row_index());
it->second.erase(*entry);
} else {
rows_->operator[](entry->get_row_index()).erase(*entry);
}
}
}
template <class Master_matrix>
inline void Row_access<Master_matrix>::update_entry(const Matrix_entry& entry)
{
if constexpr (!Master_matrix::Option_list::has_intrusive_rows) {
if (rows_ == nullptr) return;
auto& row = rows_->at(entry.get_row_index());
auto it = row.find(entry);
it = row.erase(it);
row.insert(it, entry);
}
}
template <class Master_matrix>
inline typename Row_access<Master_matrix>::Index Row_access<Master_matrix>::get_column_index() const
{
return columnIndex_;
}
} // namespace persistence_matrix
} // namespace Gudhi
#endif // PM_ROW_ACCESS_H
Gudhi::persistence_matrix::Row_access::Matrix_entry
typename Master_matrix::Matrix_entry Matrix_entry
Definition row_access.h:55
Gudhi::persistence_matrix::Row_access::Row_access
Row_access()
Default constructor. Sets the column index to null index and the row container to nullptr....
Definition row_access.h:124
Gudhi::persistence_matrix::Row_access::ID_index
typename Master_matrix::ID_index ID_index
Definition row_access.h:54
Gudhi::persistence_matrix::Row_access::Row_container
typename Master_matrix::Row_container Row_container
Definition row_access.h:56
Gudhi::persistence_matrix::Row_access::unlink
void unlink(Matrix_entry *entry)
Removes the given entry from its row.
Definition row_access.h:156
Gudhi::persistence_matrix::Row_access::insert_entry
void insert_entry(ID_index rowIndex, Matrix_entry *entry)
Inserts the given entry at the given row index.
Definition row_access.h:139
Gudhi::persistence_matrix::Row_access::update_entry
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:173
Gudhi::persistence_matrix::Row_access::Index
typename Master_matrix::Index Index
Definition row_access.h:53
Gudhi::persistence_matrix::Row_access::swap
friend void swap(Row_access &r1, Row_access &r2)
Swap operator.
Definition row_access.h:110
Gudhi::persistence_matrix::Row_access::get_column_index
Index get_column_index() const
Returns the MatIdx column index.
Definition row_access.h:185
Gudhi::persistence_matrix
Persistence matrix namespace.
Definition FieldOperators.h:18
Gudhi
Gudhi namespace.
Definition SimplicialComplexForAlpha.h:14