18#ifndef PM_RU_PAIRING_H
19#define PM_RU_PAIRING_H
21#include <unordered_map>
26namespace persistence_matrix {
48template <
class Master_matrix>
50 Master_matrix::Option_list::has_removable_columns,
51 Cell_position_to_ID_mapper<typename Master_matrix::ID_index, typename Master_matrix::Pos_index>,
56 using Pos_index =
typename Master_matrix::Pos_index;
57 using ID_index =
typename Master_matrix::ID_index;
59 using PIDM =
typename std::conditional<Master_matrix::Option_list::has_removable_columns,
60 Cell_position_to_ID_mapper<ID_index, Pos_index>,
65 using Barcode =
typename Master_matrix::Barcode;
83 swap(
static_cast<PIDM&
>(pairing1),
static_cast<PIDM&
>(pairing2));
84 pairing1.barcode_.swap(pairing2.barcode_);
85 pairing1.indexToBar_.swap(pairing2.indexToBar_);
86 pairing1.idToPosition_.swap(pairing2.idToPosition_);
90 using Dimension =
typename Master_matrix::Dimension;
91 using Dictionary =
typename Master_matrix::Bar_dictionary;
94 Dictionary indexToBar_;
98 std::unordered_map<ID_index, Pos_index> idToPosition_;
100 void _update_barcode(ID_index birthPivot, Pos_index death) {
101 auto it = idToPosition_.find(birthPivot);
102 Pos_index pivotBirth = it == idToPosition_.end() ? birthPivot : it->second;
103 if constexpr (Master_matrix::hasFixedBarcode || !Master_matrix::Option_list::has_removable_columns) {
104 barcode_[indexToBar_[pivotBirth]].death = death;
105 indexToBar_.push_back(indexToBar_[pivotBirth]);
107 auto& barIt = indexToBar_.at(pivotBirth);
108 barIt->death = death;
109 indexToBar_.try_emplace(death, barIt);
113 void _add_bar(Dimension dim, Pos_index birth) {
114 barcode_.emplace_back(birth, Master_matrix::template get_null_value<Pos_index>(), dim);
115 if constexpr (Master_matrix::hasFixedBarcode || !Master_matrix::Option_list::has_removable_columns) {
116 indexToBar_.push_back(barcode_.size() - 1);
118 indexToBar_.try_emplace(birth, --barcode_.end());
122 void _remove_last(Pos_index eventIndex) {
123 static_assert(Master_matrix::Option_list::has_removable_columns,
"_remove_last not available.");
124 constexpr const Pos_index nullDeath = Master_matrix::template get_null_value<Pos_index>();
126 if constexpr (Master_matrix::hasFixedBarcode) {
127 auto& bar = barcode_[indexToBar_[eventIndex]];
128 if (bar.death == nullDeath) {
131 bar.death = nullDeath;
133 indexToBar_.pop_back();
135 auto it = indexToBar_.find(eventIndex);
136 typename Barcode::iterator bar = it->second;
138 if (bar->death == nullDeath)
141 bar->death = nullDeath;
143 indexToBar_.erase(it);
146 auto it = PIDM::map_.find(eventIndex);
147 if (it != PIDM::map_.end()){
148 idToPosition_.erase(it->second);
149 PIDM::map_.erase(it);
Contains the Gudhi::persistence_matrix::Cell_position_to_ID_mapper class and Gudhi::persistence_matri...
Class managing the barcode for RU_matrix if the option was enabled.
Definition: ru_pairing.h:54
friend void swap(RU_pairing &pairing1, RU_pairing &pairing2)
Swap operator.
Definition: ru_pairing.h:82
const Barcode & get_current_barcode() const
Returns the current barcode which is maintained at any insertion, removal or vine swap.
Definition: ru_pairing.h:77
typename Master_matrix::Barcode Barcode
Definition: ru_pairing.h:65
RU_pairing()
Default constructor.
Definition: ru_pairing.h:70
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Empty structure. Inherited instead of RU_pairing, when the computation of the barcode was not enabled...
Definition: ru_pairing.h:36