Persistent_cohomology_column.h
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): Clément Maria
6  *
7  * Copyright (C) 2014 INRIA Sophia Antipolis-Méditerranée (France)
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
24 #define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
25 
26 #include <boost/intrusive/set.hpp>
27 #include <boost/intrusive/list.hpp>
28 
29 #include <list>
30 
31 namespace Gudhi {
32 
33 namespace persistent_cohomology {
34 
35 template<typename SimplexKey, typename ArithmeticElement>
36 class Persistent_cohomology_column;
37 
38 struct cam_h_tag;
39 // for horizontal traversal in the CAM
40 struct cam_v_tag;
41 // for vertical traversal in the CAM
42 
43 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_h_tag>,
44  boost::intrusive::link_mode<boost::intrusive::auto_unlink> // allows .unlink()
45 > base_hook_cam_h;
46 
47 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_v_tag>,
48  boost::intrusive::link_mode<boost::intrusive::normal_link> // faster hook, less safe
49 > base_hook_cam_v;
50 
55 template<typename SimplexKey, typename ArithmeticElement>
56 class Persistent_cohomology_cell : public base_hook_cam_h,
57  public base_hook_cam_v {
58  public:
59  template<class T1, class T2> friend class Persistent_cohomology;
60  friend class Persistent_cohomology_column<SimplexKey, ArithmeticElement>;
61 
62  typedef Persistent_cohomology_column<SimplexKey, ArithmeticElement> Column;
63 
64  Persistent_cohomology_cell(SimplexKey key, ArithmeticElement x,
65  Column * self_col)
66  : key_(key),
67  coefficient_(x),
68  self_col_(self_col) {
69  }
70 
71  SimplexKey key_;
72  ArithmeticElement coefficient_;
73  Column * self_col_;
74 };
75 
76 /*
77  * \brief Sparse column for the Compressed Annotation Matrix.
78  *
79  * The non-zero coefficients of the column are stored in a
80  * boost::intrusive::list. Contains a hook to be stored in a
81  * boost::intrusive::set.
82  *
83  * Movable but not Copyable.
84  */
85 template<typename SimplexKey, typename ArithmeticElement>
86 class Persistent_cohomology_column : public boost::intrusive::set_base_hook<
87  boost::intrusive::link_mode<boost::intrusive::normal_link> > {
88  template<class T1, class T2> friend class Persistent_cohomology;
89 
90  public:
91  typedef Persistent_cohomology_cell<SimplexKey, ArithmeticElement> Cell;
92  typedef boost::intrusive::list<Cell,
93  boost::intrusive::constant_time_size<false>,
94  boost::intrusive::base_hook<base_hook_cam_v> > Col_type;
95 
97  explicit Persistent_cohomology_column(SimplexKey key)
98  : col_(),
99  class_key_(key) {}
100 
102  bool is_null() const {
103  return col_.empty();
104  }
108  SimplexKey class_key() const {
109  return class_key_;
110  }
111 
113  friend bool operator<(const Persistent_cohomology_column& c1,
114  const Persistent_cohomology_column& c2) {
115  typename Col_type::const_iterator it1 = c1.col_.begin();
116  typename Col_type::const_iterator it2 = c2.col_.begin();
117  while (it1 != c1.col_.end() && it2 != c2.col_.end()) {
118  if (it1->key_ == it2->key_) {
119  if (it1->coefficient_ == it2->coefficient_) {
120  ++it1;
121  ++it2;
122  } else {
123  return it1->coefficient_ < it2->coefficient_;
124  }
125  } else {
126  return it1->key_ < it2->key_;
127  }
128  }
129  return (it2 != c2.col_.end());
130  }
131 
132  Col_type col_;
133  SimplexKey class_key_;
134 };
135 
136 } // namespace persistent_cohomology
137 
138 } // namespace Gudhi
139 
140 #endif // PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
Computes the persistent cohomology of a filtered complex.
Definition: Persistent_cohomology.h:64
Definition: SimplicialComplexForAlpha.h:26
Key type used as simplex identifier.
Definition: SimplexKey.h:27
GUDHI  Version 2.1.0  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding.  - Copyright : GPL v3 Generated on Thu Jun 14 2018 18:07:51 for GUDHI by Doxygen 1.8.13