HPCombi
High Performance Combinatorics in C++ using vector instructions v1.1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
include
hpcombi
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
25
26
namespace
HPCombi
{
27
28
template
<
size_t
Size,
typename
Expo>
29
PermGeneric<Size, Expo>::PermGeneric
(std::initializer_list<Expo> il) {
30
HPCOMBI_ASSERT
(il.size() <= Size);
31
std::copy(il.begin(), il.end(), this->v.begin());
32
for
(Expo i = il.size(); i < Size; i++)
33
this->
v
[i] = i;
34
}
35
36
template
<
size_t
Size,
typename
Expo>
37
PermGeneric<Size, Expo>
38
PermGeneric<Size, Expo>::elementary_transposition
(uint64_t i) {
39
HPCOMBI_ASSERT
(i < Size);
40
PermGeneric
res
{{}};
41
res
[i] = i + 1;
42
res
[i + 1] = i;
43
return
res
;
44
}
45
46
template
<
size_t
Size,
typename
Expo>
47
PermGeneric<Size, Expo>
PermGeneric<Size, Expo>::inverse
()
const
{
48
PermGeneric
res
;
49
for
(uint64_t i = 0; i < Size; i++)
50
res
[this->
v
[i]] = i;
51
return
res
;
52
}
53
54
template
<
size_t
Size,
typename
Expo>
55
PermGeneric<Size, Expo>
PermGeneric<Size, Expo>::random
() {
56
static
std::random_device rd;
57
static
std::mt19937 g(rd());
58
59
PermGeneric
res
{{}};
60
std::shuffle(
res
.v.begin(),
res
.v.end(), g);
61
return
res
;
62
}
63
64
template
<
size_t
Size,
typename
Expo>
65
typename
PermGeneric<Size, Expo>::vect
PermGeneric<Size, Expo>::lehmer
()
const
{
66
vect
res
{};
67
for
(
size_t
i = 0; i < Size; i++)
68
for
(
size_t
j = i + 1; j < Size; j++)
69
if
(this->
v
[i] > this->
v
[j])
70
res
[i]++;
71
return
res
;
72
}
73
74
template
<
size_t
Size,
typename
Expo>
75
uint64_t
PermGeneric<Size, Expo>::length
()
const
{
76
uint64_t
res
= 0;
77
for
(
size_t
i = 0; i < Size; i++)
78
for
(
size_t
j = i + 1; j < Size; j++)
79
if
(this->
v
[i] > this->
v
[j])
80
res
++;
81
return
res
;
82
}
83
84
template
<
size_t
Size,
typename
Expo>
85
uint64_t
PermGeneric<Size, Expo>::nb_descents
()
const
{
86
uint64_t
res
= 0;
87
for
(
size_t
i = 0; i < Size - 1; i++)
88
if
(this->
v
[i] > this->
v
[i + 1])
89
res
++;
90
return
res
;
91
}
92
93
template
<
size_t
Size,
typename
Expo>
94
uint64_t
PermGeneric<Size, Expo>::nb_cycles
()
const
{
95
std::array<bool, Size> b{};
96
uint64_t c = 0;
97
for
(
size_t
i = 0; i < Size; i++) {
98
if
(!b[i]) {
99
for
(
size_t
j = i; !b[j]; j = this->
v
[j])
100
b[j] =
true
;
101
c++;
102
}
103
}
104
return
c;
105
}
106
107
template
<
size_t
Size,
typename
Expo>
108
bool
PermGeneric<Size, Expo>::left_weak_leq
(
PermGeneric
other)
const
{
109
for
(
size_t
i = 0; i < Size; i++) {
110
for
(
size_t
j = i + 1; j < Size; j++) {
111
if
((this->
v
[i] > this->
v
[j]) && (other[i] < other[j]))
112
return
false
;
113
}
114
}
115
return
true
;
116
}
117
118
};
// namespace HPCombi
119
120
namespace
std
{
121
124
template
<
size_t
Size,
typename
Expo>
125
struct
hash<
HPCombi
::PermGeneric<Size, Expo>> {
126
size_t
operator()
(
const
HPCombi::PermGeneric<Size, Expo>
&ar)
const
{
127
return
hash<HPCombi::VectGeneric<Size, Expo>>()(ar);
128
}
129
};
130
131
}
// namespace std
HPCOMBI_ASSERT
#define HPCOMBI_ASSERT(x)
Definition
debug.hpp:31
res
std::array< std::tuple< uint16_t, uint16_t, std::array< uint16_t, gens.size()> >, 65536 > res
Definition
image.cpp:66
HPCombi
Definition
bmat16.hpp:39
std
Definition
bmat16_impl.hpp:362
HPCombi::PermGeneric
Vanilla (ie NOT optimized) implementation of a permutation, used to check for test correctness and as...
Definition
perm_generic.hpp:50
HPCombi::PermGeneric::length
uint64_t length() const
Definition
perm_generic_impl.hpp:75
HPCombi::PermGeneric::left_weak_leq
bool left_weak_leq(PermGeneric other) const
Definition
perm_generic_impl.hpp:108
HPCombi::PermGeneric::vect
VectGeneric< Size, Expo > vect
Definition
perm_generic.hpp:51
HPCombi::PermGeneric::PermGeneric
PermGeneric()=default
HPCombi::PermGeneric::elementary_transposition
static PermGeneric elementary_transposition(uint64_t i)
Definition
perm_generic_impl.hpp:38
HPCombi::PermGeneric::random
static PermGeneric random()
Definition
perm_generic_impl.hpp:55
HPCombi::PermGeneric::inverse
PermGeneric inverse() const
Definition
perm_generic_impl.hpp:47
HPCombi::PermGeneric::nb_cycles
uint64_t nb_cycles() const
Definition
perm_generic_impl.hpp:94
HPCombi::PermGeneric::lehmer
vect lehmer() const
Definition
perm_generic_impl.hpp:65
HPCombi::PermGeneric::nb_descents
uint64_t nb_descents() const
Definition
perm_generic_impl.hpp:85
HPCombi::VectGeneric< Size, uint8_t >::v
array v
Definition
vect_generic.hpp:59
std::hash< HPCombi::PermGeneric< Size, Expo > >::operator()
size_t operator()(const HPCombi::PermGeneric< Size, Expo > &ar) const
Definition
perm_generic_impl.hpp:126
Generated by
1.17.0