Gudhi  1.2.0
 All Classes Functions Variables Typedefs Friends Groups Pages
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/tuple/tuple.hpp>
27 #include <boost/intrusive/set.hpp>
28 #include <boost/intrusive/list.hpp>
29 
30 #include <list>
31 
32 namespace Gudhi {
33 
34 namespace persistent_cohomology {
35 
36 template<typename SimplexKey, typename ArithmeticElement>
37 class Persistent_cohomology_column;
38 
39 struct cam_h_tag;
40 // for horizontal traversal in the CAM
41 struct cam_v_tag;
42 // for vertical traversal in the CAM
43 
44 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_h_tag>,
45  boost::intrusive::link_mode<boost::intrusive::auto_unlink> // allows .unlink()
46 > base_hook_cam_h;
47 
48 typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_v_tag>,
49  boost::intrusive::link_mode<boost::intrusive::normal_link> // faster hook, less safe
50 > base_hook_cam_v;
51 
56 template<typename SimplexKey, typename ArithmeticElement>
57 class Persistent_cohomology_cell : public base_hook_cam_h,
58  public base_hook_cam_v {
59  public:
60  template<class T1, class T2> friend class Persistent_cohomology;
61  friend class Persistent_cohomology_column<SimplexKey, ArithmeticElement>;
62 
63  typedef Persistent_cohomology_column<SimplexKey, ArithmeticElement> Column;
64 
65  Persistent_cohomology_cell(SimplexKey key, ArithmeticElement x,
66  Column * self_col)
67  : key_(key),
68  coefficient_(x),
69  self_col_(self_col) {
70  }
71 
72  SimplexKey key_;
73  ArithmeticElement coefficient_;
74  Column * self_col_;
75 };
76 
77 /*
78  * \brief Sparse column for the Compressed Annotation Matrix.
79  *
80  * The non-zero coefficients of the column are stored in a
81  * boost::intrusive::list. Contains a hook to be stored in a
82  * boost::intrusive::set.
83  *
84  * Movable but not Copyable.
85  */
86 template<typename SimplexKey, typename ArithmeticElement>
87 class Persistent_cohomology_column : public boost::intrusive::set_base_hook<
88  boost::intrusive::link_mode<boost::intrusive::normal_link> > {
89  template<class T1, class T2> friend class Persistent_cohomology;
90 
91  public:
92  typedef Persistent_cohomology_cell<SimplexKey, ArithmeticElement> Cell;
93  typedef boost::intrusive::list<Cell,
94  boost::intrusive::constant_time_size<false>,
95  boost::intrusive::base_hook<base_hook_cam_v> > Col_type;
96 
98  explicit Persistent_cohomology_column(SimplexKey key)
99  : col_(),
100  class_key_(key) {}
101 
103  bool is_null() const {
104  return col_.empty();
105  }
109  SimplexKey class_key() const {
110  return class_key_;
111  }
112 
114  friend bool operator<(const Persistent_cohomology_column& c1,
115  const Persistent_cohomology_column& c2) {
116  typename Col_type::const_iterator it1 = c1.col_.begin();
117  typename Col_type::const_iterator it2 = c2.col_.begin();
118  while (it1 != c1.col_.end() && it2 != c2.col_.end()) {
119  if (it1->key_ == it2->key_) {
120  if (it1->coefficient_ == it2->coefficient_) {
121  ++it1;
122  ++it2;
123  } else {
124  return it1->coefficient_ < it2->coefficient_;
125  }
126  } else {
127  return it1->key_ < it2->key_;
128  }
129  }
130  return (it2 != c2.col_.end());
131  }
132 
133  Col_type col_;
134  SimplexKey class_key_;
135 };
136 
137 } // namespace persistent_cohomology
138 
139 } // namespace Gudhi
140 
141 #endif // PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
Key type used as simplex identifier.
Definition: SimplexKey.h:27