diff options
Diffstat (limited to 'src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h')
-rw-r--r-- | src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h | 61 |
1 files changed, 25 insertions, 36 deletions
diff --git a/src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h b/src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h index c4e86a36..3ee73754 100644 --- a/src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h +++ b/src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h @@ -20,37 +20,32 @@ namespace coxeter_triangulation { typedef unsigned uint; -/** \brief Class that allows the user to generate combinations of +/** \brief Class that allows the user to generate combinations of * k elements in a set of n elements. * Based on the algorithm by Mifsud. -*/ -class Integer_combination_iterator : public boost::iterator_facade< Integer_combination_iterator, - std::vector<uint> const, - boost::forward_traversal_tag> { + */ +class Integer_combination_iterator + : public boost::iterator_facade<Integer_combination_iterator, std::vector<uint> const, + boost::forward_traversal_tag> { using value_t = std::vector<uint>; - + private: friend class boost::iterator_core_access; - - bool equal(Integer_combination_iterator const& other) const { - return (is_end_ && other.is_end_); - } - value_t const& dereference() const { - return value_; - } + bool equal(Integer_combination_iterator const& other) const { return (is_end_ && other.is_end_); } + + value_t const& dereference() const { return value_; } void increment() { uint j1 = 0; uint s = 0; - while (value_[j1] == 0 && j1 < k_) - j1++; - uint j2 = j1+1; + while (value_[j1] == 0 && j1 < k_) j1++; + uint j2 = j1 + 1; while (value_[j2] == bounds_[j2]) { if (bounds_[j2] != 0) { - s += value_[j1]; - value_[j1] = 0; - j1 = j2; + s += value_[j1]; + value_[j1] = 0; + j1 = j2; } j2++; } @@ -70,20 +65,15 @@ class Integer_combination_iterator : public boost::iterator_facade< Integer_comb value_[i++] = s; } -public: + public: template <class Bound_range> Integer_combination_iterator(const uint& n, const uint& k, const Bound_range& bounds) - : - value_(k+2), - is_end_(n == 0 || k == 0), - n_(n), - k_(k) - { - bounds_.reserve(k+2); + : value_(k + 2), is_end_(n == 0 || k == 0), n_(n), k_(k) { + bounds_.reserve(k + 2); uint sum_radices = 0; - for (auto b: bounds) { + for (auto b : bounds) { bounds_.push_back(b); - sum_radices += b; + sum_radices += b; } bounds_.push_back(2); bounds_.push_back(1); @@ -100,26 +90,25 @@ public: } value_[i++] = s; - while (i < k_) - value_[i++] = 0; + while (i < k_) value_[i++] = 0; value_[k] = 1; - value_[k+1] = 0; + value_[k + 1] = 0; } // Used for the creating an end iterator Integer_combination_iterator() : is_end_(true), n_(0), k_(0) {} private: - value_t value_; // the dereference value - bool is_end_; // is true when the current integer combination is the final one + value_t value_; // the dereference value + bool is_end_; // is true when the current integer combination is the final one uint n_; uint k_; std::vector<uint> bounds_; }; -} // namespace coxeter_triangulation +} // namespace coxeter_triangulation -} // namespace Gudhi +} // namespace Gudhi #endif |