23#ifndef LIBSEMIGROUPS_IS_TRANSF_HPP_
24#define LIBSEMIGROUPS_IS_TRANSF_HPP_
31#include <unordered_map>
34#include "constants.hpp"
36#include "detail/print.hpp"
46 template <
typename Iterator>
47 std::pair<Iterator, size_t> find_duplicates(
50 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t>& seen);
52 template <
typename Iterator>
53 [[nodiscard]] std::pair<Iterator, size_t> find_duplicates(Iterator first,
55 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t> seen;
56 return find_duplicates(first, last, seen);
59 template <
typename Iterator>
60 [[nodiscard]]
bool has_duplicates(Iterator first, Iterator last) {
61 return find_duplicates(first, last).first != last;
64 template <
typename Iterator>
65 void throw_if_duplicates(
68 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t>& seen,
69 std::string_view where);
71 template <
typename Iterator>
72 void throw_if_duplicates(Iterator first,
74 std::string_view where) {
75 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t> seen;
76 throw_if_duplicates(first, last, seen, where);
79 template <
typename Iterator,
typename Func>
80 void throw_if_value_out_of_range(Iterator first,
83 std::string_view where);
85 template <
typename Iterator>
86 void throw_if_not_ptransf(Iterator first, Iterator last,
size_t deg);
88 template <
typename Iterator>
89 void throw_if_not_ptransf(Iterator first, Iterator last) {
90 throw_if_not_ptransf(first, last,
std::distance(first, last));
93 template <
typename Iterator>
94 void throw_if_not_ptransf(Iterator dom_first,
100 template <
typename Iterator>
101 void throw_if_not_transf(Iterator first, Iterator last,
size_t deg);
103 template <
typename Iterator>
104 void throw_if_not_transf(Iterator first, Iterator last) {
105 throw_if_not_transf(first, last,
std::distance(first, last));
108 template <
typename Iterator>
109 void throw_if_not_perm(Iterator first, Iterator last,
size_t deg) {
110 throw_if_not_transf(first, last, deg);
111 throw_if_duplicates(first, last,
"image");
114 template <
typename Iterator>
115 void throw_if_not_perm(Iterator first, Iterator last) {
119 template <
typename Iterator>
120 void throw_if_not_pperm(Iterator first, Iterator last,
size_t deg) {
121 throw_if_not_ptransf(first, last, deg);
122 throw_if_duplicates(first, last,
"image");
125 template <
typename Iterator>
126 void throw_if_not_pperm(Iterator first, Iterator last) {
127 throw_if_not_ptransf(first, last);
128 throw_if_duplicates(first, last,
"image");
131 template <
typename Iterator>
132 void throw_if_not_pperm(Iterator dom_first,
137 throw_if_not_ptransf(dom_first, dom_last, img_first, img_last, deg);
138 throw_if_duplicates(img_first, img_last,
"image");
171 template <
typename Iterator>
172 [[nodiscard]]
bool is_ptransf(Iterator first, Iterator last,
size_t deg) {
174 std::is_unsigned_v<std::decay_t<decltype(*std::declval<Iterator>())>>);
204 template <
typename Iterator>
205 [[nodiscard]]
bool is_ptransf(Iterator first, Iterator last) {
234 template <
typename Iterator>
235 [[nodiscard]]
bool is_transf(Iterator first, Iterator last,
size_t deg) {
237 std::is_unsigned_v<std::decay_t<decltype(*std::declval<Iterator>())>>);
238 return std::none_of(first, last, [°](
auto val) {
return val >= deg; });
264 template <
typename Iterator>
265 [[nodiscard]]
bool is_transf(Iterator first, Iterator last) {
297 template <
typename Iterator>
298 [[nodiscard]]
bool is_pperm(Iterator first, Iterator last,
size_t deg) {
299 return is_ptransf(first, last, deg) && !detail::has_duplicates(first, last);
328 template <
typename Iterator>
329 [[nodiscard]]
bool is_pperm(Iterator first, Iterator last) {
357 template <
typename Iterator>
358 [[nodiscard]]
bool is_perm(Iterator first, Iterator last,
size_t deg) {
359 return is_transf(first, last, deg) && !detail::has_duplicates(first, last);
386 template <
typename Iterator>
387 [[nodiscard]]
bool is_perm(Iterator first, Iterator last) {
392#include "is-transf.tpp"
Undefined const UNDEFINED
Value for something undefined.
bool is_ptransf(Iterator first, Iterator last, size_t deg)
Returns whether or not the argument describes a partial transformation.
Definition is-transf.hpp:172
bool is_transf(Iterator first, Iterator last, size_t deg)
Returns whether or not the argument describes a transformation.
Definition is-transf.hpp:235
bool is_pperm(Iterator first, Iterator last, size_t deg)
Returns whether or not the argument describes a partial permutation.
Definition is-transf.hpp:298
bool is_perm(Iterator first, Iterator last, size_t deg)
Returns whether or not the argument describes a permutation.
Definition is-transf.hpp:358
Namespace for everything in the libsemigroups library.
Definition action.hpp:44