Regina 7.4 Calculation Engine
|
A lightweight array-like object that supports fast lookup and iteration for permutations on n objects. More...
#include <maths/permsn.h>
Classes | |
class | iterator |
An iterator over all permutations of n objects. More... | |
Public Types | |
using | const_iterator = iterator |
An iterator over all permutations of n objects. | |
Public Member Functions | |
constexpr Perm< n > | operator[] (Perm< n >::Index index) const |
Returns the permutation at the given index in Sn, according to the chosen ordering. | |
constexpr Perm< n >::Index | size () const |
Returns the total number of permutations of n objects. | |
constexpr iterator | begin () const |
Returns an iterator pointing to the first permutation according to the chosen ordering. | |
constexpr iterator | end () const |
Returns an iterator pointing beyond the last permutation. | |
auto | __iter__ () const |
Returns a Python iterator over all permutations of n objects. | |
constexpr bool | operator== (const PermSn &) const |
A trivial equality test that always returns true . | |
A lightweight array-like object that supports fast lookup and iteration for permutations on n objects.
Typically you would access this object through static constants such as Perm<n>::Sn
or Perm<n>::orderedSn
. There should be no need for end users to refer to this type directly.
There are two main ways in which you can use this object. For the examples below, we assume that we are accessing Perm<n>::Sn
.
Perm<n>::Sn[i]
and Perm<n>::Sn::size()
. Instead of size(), you can also use the standard len()
function in Python.Perm<n>::Sn
in a range-based for
loop, or use begin/end pairs such as Perm<n>::Sn.begin()
and Perm<n>::Sn.end()
.Regarding indices and iteration:
(n!-1)
inclusive, and permutations are indexed according to the chosen ordering, i.e., the template parameter order. In particular: Perm<n>::Sn
uses sign-based ordering, beginning with the identity permutation at index 0 and alternating between even and odd permutations, whereas Perm<n>::orderedSn
uses lexicographical ordering according the images of 0,...,n-1
under each permutation.Perm<n>::Sn
) is typically faster than using array-like access for each index in turn (e.g., accessing Sn[0]
, Sn[1]
, etc.). This is particularly true when n is larger. See the notes on time complexity below.Regarding time complexity:
Objects of this type contain no data at all, which means they are trivial to pass by value or swap with std::swap(), and all objects of this type are essentially identical.
n | the number of objects being permuted. This must be between 2 and 16 inclusive. |
order | the way in which this class orders permutations for the purposes of indexing and iteration. |
codeType | the constant Perm<n>::codeType . You should allow the compiler to deduce this and not attempt to set it yourself. |
using regina::PermSn< n, order, codeType >::const_iterator = iterator |
An iterator over all permutations of n objects.
Both iterator and const_iterator are the same type, since PermSn only offers read-only access to its permutations. See the PermSn::iterator class for further details.
auto regina::PermSn< n, order, codeType >::__iter__ | ( | ) | const |
Returns a Python iterator over all permutations of n objects.
See the PermSn class notes for further details on how iteration works.
for
loop.
|
inlineconstexpr |
Returns an iterator pointing to the first permutation according to the chosen ordering.
For all supported orderings, this first permutation is the identity permutation; however, as the iterator steps through from begin() to end(), the order in which subsequent permutations appear will depend upon the template parameter order.
See the PermSn class notes for further details on how iteration works over all permutations of n objects.
|
inlineconstexpr |
Returns an iterator pointing beyond the last permutation.
See the PermSn class notes for further details on how iteration works over all permutations of n objects.
|
inlineconstexpr |
|
inlineconstexpr |
Returns the permutation at the given index in Sn, according to the chosen ordering.
See the PermSn class notes for further details on how array-like indexing works for permutations of n objects. In particular, note that which permutation corresponds to which index will depend upon the template parameter order.
For n ≤ 7, this operator is very fast constant time. However, for n ≥ 8 the current implementation is quadratic in n.
index | an index between 0 and n!-1 inclusive. |
|
inlineconstexpr |
Returns the total number of permutations of n objects.
This is of course just n!
.