Ordered_set_partition_iterator.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): Siargey Kachanovich
4  *
5  * Copyright (C) 2019 Inria
6  *
7  * Modification(s):
8  * - YYYY/MM Author: Description of the modification
9  */
10 
11 #ifndef PERMUTAHEDRAL_REPRESENTATION_ORDERED_SET_PARTITION_ITERATOR_H_
12 #define PERMUTAHEDRAL_REPRESENTATION_ORDERED_SET_PARTITION_ITERATOR_H_
13 
14 #include <vector>
15 #include <limits>
16 
17 #include <gudhi/Permutahedral_representation/Permutation_iterator.h>
18 #include <gudhi/Permutahedral_representation/Set_partition_iterator.h>
19 
20 #include <boost/range/iterator_range.hpp>
21 
22 namespace Gudhi {
23 
24 namespace coxeter_triangulation {
25 
26 typedef unsigned uint;
27 
35 
36  // Ordered_set_partition(const Set_partition_iterator& s_it, const Permutation_iterator& p_it)
37  // : s_it_(s_it), p_it_(p_it) {}
38 
39  const std::vector<uint> operator[](const uint& i) const { return (*s_it_)[(*p_it_)[i]]; }
40 
41  std::size_t size() const { return s_it_->size(); }
42 };
43 
48  : public boost::iterator_facade<Ordered_set_partition_iterator, Ordered_set_partition const,
49  boost::forward_traversal_tag> {
51 
52  private:
53  friend class boost::iterator_core_access;
54 
55  bool equal(Ordered_set_partition_iterator const& other) const { return (is_end_ && other.is_end_); }
56 
57  value_t const& dereference() const { return value_; }
58 
59  void increment() {
60  if (++value_.p_it_ == p_end_) {
61  if (++value_.s_it_ == s_end_) {
62  is_end_ = true;
63  return;
64  } else
65  value_.p_it_.reinitialize();
66  }
67  }
68 
69  public:
70  Ordered_set_partition_iterator(const uint& n, const uint& k)
71  : value_({Set_partition_iterator(n, k), Permutation_iterator(k)}), is_end_(n == 0) {}
72 
73  // Used for the creating an end iterator
74  Ordered_set_partition_iterator() : is_end_(true) {}
75 
76  void reinitialize() {
77  is_end_ = false;
78  value_.p_it_.reinitialize();
79  value_.s_it_.reinitialize();
80  }
81 
82  private:
83  Set_partition_iterator s_end_; // Set partition iterator and the corresponding end iterator
84  Permutation_iterator p_end_; // Permutation iterator and the corresponding end iterator
85  value_t value_; // the dereference value
86  bool is_end_; // is true when the current permutation is the final one
87 };
88 
89 } // namespace coxeter_triangulation
90 
91 } // namespace Gudhi
92 
93 #endif
Class that allows the user to generate set partitions of a set {0,...,n-1} in k parts.
Definition: Ordered_set_partition_iterator.h:49
Class that allows the user to generate permutations. Based on the optimization of the Heap's algorith...
Definition: Permutation_iterator.h:29
Class that allows the user to generate set partitions of a set {0,...,n-1} in k parts.
Definition: Set_partition_iterator.h:29
Gudhi namespace.
Definition: SimplicialComplexForAlpha.h:14
Class that represents an ordered set partition of a set {0,...,n-1} in k parts as a pair of an unorde...
Definition: Ordered_set_partition_iterator.h:32