diff options
author | hschreiber <hannah.schreiber.k@gmail.com> | 2022-09-09 11:22:06 +0200 |
---|---|---|
committer | hschreiber <hannah.schreiber.k@gmail.com> | 2022-09-09 11:22:06 +0200 |
commit | 122a9db751c392910fd09097ad50226c2a557a38 (patch) | |
tree | ec4c67607fc8e276020a0ac77337cab4a2fcca63 /src/Coxeter_triangulation/include/gudhi/Permutahedral_representation/Integer_combination_iterator.h | |
parent | 82d7f179d7db317cfe8714bf679f50739bab1173 (diff) |
restore indentation
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 | 159 |
1 files changed, 80 insertions, 79 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 155995f5..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 @@ -25,85 +25,86 @@ typedef unsigned uint; * 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> { - 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_; } - - void increment() { - uint j1 = 0; - uint s = 0; - 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; - } - j2++; - } - if (j2 >= k_) { - is_end_ = true; - return; - } - s += value_[j1] - 1; - value_[j1] = 0; - value_[j2]++; - uint i = 0; - while (s >= bounds_[i]) { - value_[i] = bounds_[i]; - s -= bounds_[i]; - i++; - } - value_[i++] = s; - } - -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), k_(k) { - bounds_.reserve(k + 2); - uint sum_radices = 0; - for (auto b : bounds) { - bounds_.push_back(b); - sum_radices += b; - } - bounds_.push_back(2); - bounds_.push_back(1); - if (n > sum_radices) { - is_end_ = true; - return; - } - uint i = 0; - uint s = n; - while (s >= bounds_[i]) { - value_[i] = bounds_[i]; - s -= bounds_[i]; - i++; - } - value_[i++] = s; - - while (i < k_) value_[i++] = 0; - value_[k] = 1; - value_[k + 1] = 0; - } - - // Used for the creating an end iterator - Integer_combination_iterator() : is_end_(true), k_(0) {} - -private: - value_t value_; // the dereference value - bool is_end_; // is true when the current integer combination is the final one - - uint k_; - std::vector<uint> bounds_; + : 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_; } + + void increment() { + uint j1 = 0; + uint s = 0; + 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; + } + j2++; + } + if (j2 >= k_) { + is_end_ = true; + return; + } + s += value_[j1] - 1; + value_[j1] = 0; + value_[j2]++; + uint i = 0; + while (s >= bounds_[i]) { + value_[i] = bounds_[i]; + s -= bounds_[i]; + i++; + } + value_[i++] = s; + } + + 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); + uint sum_radices = 0; + for (auto b : bounds) { + bounds_.push_back(b); + sum_radices += b; + } + bounds_.push_back(2); + bounds_.push_back(1); + if (n > sum_radices) { + is_end_ = true; + return; + } + uint i = 0; + uint s = n; + while (s >= bounds_[i]) { + value_[i] = bounds_[i]; + s -= bounds_[i]; + i++; + } + value_[i++] = s; + + while (i < k_) value_[i++] = 0; + value_[k] = 1; + 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 + + uint n_; + uint k_; + std::vector<uint> bounds_; }; } // namespace coxeter_triangulation |