HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.3
All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
perm_generic.hpp
Go to the documentation of this file.
1//****************************************************************************//
2// Copyright (C) 2016-2024 Florent Hivert <Florent.Hivert@lisn.fr>, //
3// //
4// This file is part of HP-Combi <https://github.com/libsemigroups/HPCombi> //
5// //
6// HP-Combi is free software: you can redistribute it and/or modify it //
7// under the terms of the GNU General Public License as published by the //
8// Free Software Foundation, either version 3 of the License, or //
9// (at your option) any later version. //
10// //
11// HP-Combi is distributed in the hope that it will be useful, but WITHOUT //
12// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or //
13// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License //
14// for more details. //
15// //
16// You should have received a copy of the GNU General Public License along //
17// with HP-Combi. If not, see <https://www.gnu.org/licenses/>. //
18//****************************************************************************//
19
22
23#ifndef HPCOMBI_PERM_GENERIC_HPP_
24#define HPCOMBI_PERM_GENERIC_HPP_
25
26#include <algorithm> // for shuffle
27#include <array> // for array
28#include <cstddef> // for size_t
29#include <cstdint> // for uint64_t, uint8_t
30#include <functional> // for hash
31#include <initializer_list> // for initializer_list
32#include <memory> // for hash
33#include <random> // for mt19937
34#include <type_traits> // for is_trivial
35
36#include "debug.hpp" // for HPCOMBI_ASSERT
37#include "vect_generic.hpp" // for VectGeneric
38
39namespace HPCombi {
40
49template <size_t Size, typename Expo = uint8_t>
50struct PermGeneric : public VectGeneric<Size, Expo> {
52
53 static constexpr size_t size() { return Size; }
54
55 PermGeneric() = default;
56 PermGeneric(const vect v) : vect(v) {} // NOLINT
57 // Not marked explicit because we want to be able to pass non-initializer
58 // lists here
59 PermGeneric(std::initializer_list<Expo> il); // NOLINT
60
62 return this->permuted(p);
63 }
64 static PermGeneric one() { return PermGeneric({}); }
65 static PermGeneric elementary_transposition(uint64_t i);
66
67 PermGeneric inverse() const;
68 static PermGeneric random();
69
70 vect lehmer() const;
71 uint64_t length() const;
72 uint64_t nb_descents() const;
73 uint64_t nb_cycles() const;
74
75 bool left_weak_leq(PermGeneric other) const;
76};
77
79// Memory layout concepts check //////////////////////////////////////////////
81
82static_assert(sizeof(VectGeneric<12>) == sizeof(PermGeneric<12>),
83 "VectGeneric and PermGeneric have a different memory layout !");
84static_assert(std::is_trivial<PermGeneric<12>>(),
85 "PermGeneric is not trivial !");
86
87} // namespace HPCombi
88
89#include "perm_generic_impl.hpp"
90
91#endif // HPCOMBI_PERM_GENERIC_HPP_
defines the macro HPCOMBI_ASSERT
Definition bmat16.hpp:39
implementation of perm_generic.hpp ; this file should not be included directly.
Vanilla (ie NOT optimized) implementation of a permutation, used to check for test correctness and as...
Definition perm_generic.hpp:50
uint64_t length() const
Definition perm_generic_impl.hpp:75
PermGeneric(const vect v)
Definition perm_generic.hpp:56
bool left_weak_leq(PermGeneric other) const
Definition perm_generic_impl.hpp:108
VectGeneric< Size, Expo > vect
Definition perm_generic.hpp:51
PermGeneric operator*(const PermGeneric &p) const
Definition perm_generic.hpp:61
static PermGeneric elementary_transposition(uint64_t i)
Definition perm_generic_impl.hpp:38
static PermGeneric random()
Definition perm_generic_impl.hpp:55
static constexpr size_t size()
Definition perm_generic.hpp:53
PermGeneric inverse() const
Definition perm_generic_impl.hpp:47
uint64_t nb_cycles() const
Definition perm_generic_impl.hpp:94
vect lehmer() const
Definition perm_generic_impl.hpp:65
static PermGeneric one()
Definition perm_generic.hpp:64
uint64_t nb_descents() const
Definition perm_generic_impl.hpp:85
array v
Definition vect_generic.hpp:59
VectGeneric permuted(const VectGeneric &u) const
Definition vect_generic.hpp:114
HPCombi::VectGeneric.