HPCombi
High Performance Combinatorics in C++ using vector instructions v1.0.0
Loading...
Searching...
No Matches
perm_generic_impl.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
20// NOLINT(build/header_guard)
21
22namespace HPCombi {
23
24template <size_t Size, typename Expo>
25PermGeneric<Size, Expo>::PermGeneric(std::initializer_list<Expo> il) {
26 HPCOMBI_ASSERT(il.size() <= Size);
27 std::copy(il.begin(), il.end(), this->v.begin());
28 for (Expo i = il.size(); i < Size; i++)
29 this->v[i] = i;
30}
31
32template <size_t Size, typename Expo>
35 HPCOMBI_ASSERT(i < Size);
36 PermGeneric res{{}};
37 res[i] = i + 1;
38 res[i + 1] = i;
39 return res;
40}
41
42template <size_t Size, typename Expo>
45 for (uint64_t i = 0; i < Size; i++)
46 res[this->v[i]] = i;
47 return res;
48}
49
50template <size_t Size, typename Expo>
52 static std::random_device rd;
53 static std::mt19937 g(rd());
54
55 PermGeneric res{{}};
56 std::shuffle(res.v.begin(), res.v.end(), g);
57 return res;
58}
59
60template <size_t Size, typename Expo>
62 vect res{};
63 for (size_t i = 0; i < Size; i++)
64 for (size_t j = i + 1; j < Size; j++)
65 if (this->v[i] > this->v[j])
66 res[i]++;
67 return res;
68}
69
70template <size_t Size, typename Expo>
72 uint64_t res = 0;
73 for (size_t i = 0; i < Size; i++)
74 for (size_t j = i + 1; j < Size; j++)
75 if (this->v[i] > this->v[j])
76 res++;
77 return res;
78}
79
80template <size_t Size, typename Expo>
82 uint64_t res = 0;
83 for (size_t i = 0; i < Size - 1; i++)
84 if (this->v[i] > this->v[i + 1])
85 res++;
86 return res;
87}
88
89template <size_t Size, typename Expo>
91 std::array<bool, Size> b{};
92 uint64_t c = 0;
93 for (size_t i = 0; i < Size; i++) {
94 if (!b[i]) {
95 for (size_t j = i; !b[j]; j = this->v[j])
96 b[j] = true;
97 c++;
98 }
99 }
100 return c;
101}
102
103template <size_t Size, typename Expo>
105 for (size_t i = 0; i < Size; i++) {
106 for (size_t j = i + 1; j < Size; j++) {
107 if ((this->v[i] > this->v[j]) && (other[i] < other[j]))
108 return false;
109 }
110 }
111 return true;
112}
113
114}; // namespace HPCombi
115
116namespace std {
117
118template <size_t Size, typename Expo>
119struct hash<HPCombi::PermGeneric<Size, Expo>> {
121 return hash<HPCombi::VectGeneric<Size, Expo>>()(ar);
122 }
123};
124
125} // namespace std
#define HPCOMBI_ASSERT(x)
Definition debug.hpp:28
std::array< std::tuple< uint16_t, uint16_t, std::array< uint16_t, gens.size()> >, 65536 > res
Definition image.cpp:66
Definition bmat8.hpp:41
Definition bmat8.hpp:364
Definition perm_generic.hpp:39
uint64_t length() const
Definition perm_generic_impl.hpp:71
bool left_weak_leq(PermGeneric other) const
Definition perm_generic_impl.hpp:104
static PermGeneric elementary_transposition(uint64_t i)
Definition perm_generic_impl.hpp:34
static PermGeneric random()
Definition perm_generic_impl.hpp:51
PermGeneric inverse() const
Definition perm_generic_impl.hpp:43
uint64_t nb_cycles() const
Definition perm_generic_impl.hpp:90
vect lehmer() const
Definition perm_generic_impl.hpp:61
uint64_t nb_descents() const
Definition perm_generic_impl.hpp:81
A generic class for combinatorial integer vectors.
Definition vect_generic.hpp:48
size_t operator()(const HPCombi::PermGeneric< Size, Expo > &ar) const
Definition perm_generic_impl.hpp:120