Size_range.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_SIZE_RANGE_H_
12#define PERMUTAHEDRAL_REPRESENTATION_SIZE_RANGE_H_
13
14#include <cstdlib> // for std::size_t
15
16#include <boost/range/iterator_range.hpp>
17
18namespace Gudhi {
19
20namespace coxeter_triangulation {
21
24template <class T_it>
26 : public boost::iterator_facade<Size_iterator<T_it>, std::size_t const, boost::forward_traversal_tag> {
27 friend class boost::iterator_core_access;
28
29 private:
30 bool equal(Size_iterator const& other) const { return (is_end_ && other.is_end_); }
31
32 std::size_t const& dereference() const { return value_; }
33
34 void increment() {
35 if (++t_it_ == t_end_) {
36 is_end_ = true;
37 return;
38 }
39 value_ = t_it_->size() - 1;
40 }
41
42 public:
43 Size_iterator(const T_it& t_begin, const T_it& t_end) : t_it_(t_begin), t_end_(t_end), is_end_(t_begin == t_end) {
44 if (!is_end_) value_ = t_it_->size() - 1;
45 }
46
47 private:
48 T_it t_it_, t_end_;
49 bool is_end_;
50 std::size_t value_;
51};
52
53template <class T>
54class Size_range {
55 const T& t_;
56
57 public:
59
60 Size_range(const T& t) : t_(t) {}
61
62 std::size_t operator[](std::size_t i) const { return t_[i].size() - 1; }
63
64 iterator begin() const { return iterator(t_.begin(), t_.end()); }
65
66 iterator end() const { return iterator(t_.end(), t_.end()); }
67};
68
69} // namespace coxeter_triangulation
70
71} // namespace Gudhi
72
73#endif
Auxiliary iterator class for sizes of parts in an ordered set partition.
Definition: Size_range.h:26