Persistent_cohomology_column.h
1/* This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT.
2 * See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details.
3 * Author(s): Clément Maria
4 *
5 * Copyright (C) 2014 Inria
6 *
7 * Modification(s):
8 * - YYYY/MM Author: Description of the modification
9 */
10
11#ifndef PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
12#define PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
13
14#include <boost/intrusive/set.hpp>
15#include <boost/intrusive/list.hpp>
16
17#include <list>
18
19namespace Gudhi {
20
21namespace persistent_cohomology {
22
23template<typename SimplexKey, typename ArithmeticElement>
24class Persistent_cohomology_column;
25
26struct cam_h_tag;
27// for horizontal traversal in the CAM
28struct cam_v_tag;
29// for vertical traversal in the CAM
30
31typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_h_tag>,
32 boost::intrusive::link_mode<boost::intrusive::auto_unlink> // allows .unlink()
33> base_hook_cam_h;
34
35typedef boost::intrusive::list_base_hook<boost::intrusive::tag<cam_v_tag>,
36 boost::intrusive::link_mode<boost::intrusive::normal_link> // faster hook, less safe
37> base_hook_cam_v;
38
43template<typename SimplexKey, typename ArithmeticElement>
44class Persistent_cohomology_cell : public base_hook_cam_h,
45 public base_hook_cam_v {
46 public:
47 template<class T1, class T2> friend class Persistent_cohomology;
48 friend class Persistent_cohomology_column<SimplexKey, ArithmeticElement>;
49
50 typedef Persistent_cohomology_column<SimplexKey, ArithmeticElement> Column;
51
52 Persistent_cohomology_cell(SimplexKey key, ArithmeticElement x,
53 Column * self_col)
54 : key_(key),
55 coefficient_(x),
56 self_col_(self_col) {
57 }
58
59 SimplexKey key_;
60 ArithmeticElement coefficient_;
61 Column * self_col_;
62};
63
64/*
65 * \brief Sparse column for the Compressed Annotation Matrix.
66 *
67 * The non-zero coefficients of the column are stored in a
68 * boost::intrusive::list. Contains a hook to be stored in a
69 * boost::intrusive::set.
70 *
71 * Movable but not Copyable.
72 */
73template<typename SimplexKey, typename ArithmeticElement>
74class Persistent_cohomology_column : public boost::intrusive::set_base_hook<
75 boost::intrusive::link_mode<boost::intrusive::normal_link> > {
76 template<class T1, class T2> friend class Persistent_cohomology;
77
78 public:
79 typedef Persistent_cohomology_cell<SimplexKey, ArithmeticElement> Cell;
80 typedef boost::intrusive::list<Cell,
81 boost::intrusive::constant_time_size<false>,
82 boost::intrusive::base_hook<base_hook_cam_v> > Col_type;
83
85 explicit Persistent_cohomology_column(SimplexKey key)
86 : col_(),
87 class_key_(key) {}
88
90 bool is_null() const {
91 return col_.empty();
92 }
96 SimplexKey class_key() const {
97 return class_key_;
98 }
99
101 friend bool operator<(const Persistent_cohomology_column& c1,
102 const Persistent_cohomology_column& c2) {
103 typename Col_type::const_iterator it1 = c1.col_.begin();
104 typename Col_type::const_iterator it2 = c2.col_.begin();
105 while (it1 != c1.col_.end() && it2 != c2.col_.end()) {
106 if (it1->key_ == it2->key_) {
107 if (it1->coefficient_ == it2->coefficient_) {
108 ++it1;
109 ++it2;
110 } else {
111 return it1->coefficient_ < it2->coefficient_;
112 }
113 } else {
114 return it1->key_ < it2->key_;
115 }
116 }
117 return (it2 != c2.col_.end());
118 }
119
120 Col_type col_;
121 SimplexKey class_key_;
122};
123
124} // namespace persistent_cohomology
125
126} // namespace Gudhi
127
128#endif // PERSISTENT_COHOMOLOGY_PERSISTENT_COHOMOLOGY_COLUMN_H_
Computes the persistent cohomology of a filtered complex.
Definition: Persistent_cohomology.h:52
Key type used as simplex identifier.
Definition: SimplexKey.h:15