Mackey  V3.3
A C++ library for computing RO(G) graded homology
Generators.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <algorithm>
3 #include <vector>
4 #include <array>
5 
8 
9 namespace mackey
10 {
11 
23  template <class spec_t, class gen_t>
25  {
26  public:
27  const gen_t &operator*() const;
28  bool operator!=(const FactoryGenerator &other) const;
29  spec_t &operator++();
30  static spec_t end();
31  protected:
32  bool completed;
34  };
35 
44  template <class T>
46  {
47  const T n;
48 
49  public:
52  size_t size() const;
53 
57 
60  class ConstIterator : public FactoryGenerator<PermutationGenerator::ConstIterator, std::vector<T>>
61  {
62  void update();
63  friend class PermutationGenerator;
64  friend class FactoryGenerator<PermutationGenerator::ConstIterator, std::vector<T>>;
65  };
66 
70 
73  ConstIterator end() const;
74  };
75 
84  template <class T>
86  {
87  const T total, choices;
88 
89  public:
92  auto size() const;
93 
97  CombinationGenerator(T total, T choices);
98 
101  class ConstIterator : public FactoryGenerator<CombinationGenerator::ConstIterator, std::vector<T>>
102  {
103  void update();
104  friend class CombinationGenerator;
105  friend class FactoryGenerator<CombinationGenerator::ConstIterator, std::vector<T>>;
106  T total, choices;
107  };
108 
112 
116  };
117 
122  template <class T>
123  std::vector<std::vector<T>> all_permutations(T n);
124 
130  template <class T>
131  std::vector<std::vector<T>> all_combinations(T n, T m);
132 }
133 #include "impl/Generators.ipp"
Constant iterator that is used in a ranged for loop to generate the combinations.
Definition: Generators.hpp:102
Generates all combinations on a number of letters making a number of choices.
Definition: Generators.hpp:86
CombinationGenerator(T total, T choices)
Sets up the generator.
auto size() const
Computes total number of combinations.
Prototype for coroutine-like iterators that generate elements such as combinations.
Definition: Generators.hpp:25
bool operator!=(const FactoryGenerator &other) const
Inequality of iterators (used to detect if generation has been completed)
spec_t & operator++()
Generates next element.
static spec_t end()
Terminal iterator.
bool completed
1 if the iterator is end() i.e. if all elements have been generated
Definition: Generators.hpp:32
const gen_t & operator*() const
Returns the generated element.
gen_t generated
The currently generated element.
Definition: Generators.hpp:33
Constant iterator that is used in a ranged for loop to generate the permutations.
Definition: Generators.hpp:61
Generates all permutations on a number of letters.
Definition: Generators.hpp:46
size_t size() const
Computes total number of permutations.
PermutationGenerator(T n)
Constructor sets up the generator.
ConstIterator begin() const
Begin iterator.
Everything in this library is under this namespace.
Definition: Box.hpp:9
std::vector< std::vector< T > > all_permutations(T n)
Returns vector of all permutations on n letters.
std::vector< std::vector< T > > all_combinations(T n, T m)
Returns vector of all combinations on n letters choosing m many.
typename Homology< rank_t, diff_t >::gen_t gen_t
Type of generators in homology.
Definition: Aliases.hpp:72