Skip to content

Commit 8eb96ac

Browse files
Konieczny: remove constructor from vector
1 parent 3815e7a commit 8eb96ac

7 files changed

Lines changed: 256 additions & 230 deletions

include/libsemigroups/konieczny.hpp

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
#ifndef LIBSEMIGROUPS_KONIECZNY_HPP_
2626
#define LIBSEMIGROUPS_KONIECZNY_HPP_
2727

28-
#include <algorithm> // for binary_search
29-
#include <cstddef> // for size_t
28+
#include <algorithm> // for binary_search
29+
#include <cstddef> // for size_t
30+
#include <initializer_list>
3031
#include <set> // for set
3132
#include <type_traits> // for is_pointer
3233
#include <unordered_map> // for unordered_map
@@ -423,28 +424,6 @@ namespace libsemigroups {
423424
//! \brief Move assignment operator.
424425
Konieczny& operator=(Konieczny&&);
425426

426-
//! \brief Construct from generators.
427-
//!
428-
//! This function constructs a Konieczny instance generated by the
429-
//! specified container of generators. There can be duplicate generators
430-
//! and although they do not count as distinct elements, they do count as
431-
//! distinct generators. In other words, the generators are precisely (a
432-
//! copy of) \p gens in the same order they occur in \p gens.
433-
//!
434-
//! \param gens the generators represented by \c this.
435-
//!
436-
//! \throws LibsemigroupsException if any of the following hold:
437-
//! * \p gens is empty
438-
//! * Degree`{}(x)` != Degree`{}(y)` for some \c x, \c y in \p gens.
439-
explicit Konieczny(std::vector<element_type> const& gens) : Konieczny() {
440-
if (gens.empty()) {
441-
LIBSEMIGROUPS_EXCEPTION(
442-
"expected a positive number of generators, but got 0");
443-
}
444-
add_generators(gens.cbegin(), gens.cend());
445-
init_data();
446-
}
447-
448427
~Konieczny();
449428

450429
////////////////////////////////////////////////////////////////////////
@@ -1902,8 +1881,53 @@ namespace libsemigroups {
19021881
typename Konieczny<Element, Traits>::const_element_type> coll) {
19031882
K.add_generators(coll.begin(), coll.end());
19041883
}
1884+
19051885
} // namespace konieczny
19061886

1887+
// TODO(0) update the doc
1888+
//! \relates Konieczny
1889+
//!
1890+
//! \brief Construct from generators.
1891+
//!
1892+
//! This function constructs a Konieczny instance generated by the
1893+
//! specified container of generators. There can be duplicate generators
1894+
//! and although they do not count as distinct elements, they do count as
1895+
//! distinct generators. In other words, the generators are precisely (a
1896+
//! copy of) \p gens in the same order they occur in \p gens.
1897+
//!
1898+
//! \param gens the generators represented by \c this.
1899+
//!
1900+
//! \throws LibsemigroupsException if any of the following hold:
1901+
//! * \p gens is empty
1902+
//! * Degree`{}(x)` != Degree`{}(y)` for some \c x, \c y in \p gens.
1903+
template <template <typename...> typename Thing,
1904+
typename Container,
1905+
typename Traits = KoniecznyTraits<typename Container::value_type>>
1906+
[[nodiscard]] std::enable_if_t<
1907+
std::is_same_v<Konieczny<typename Container::value_type, Traits>,
1908+
Thing<typename Container::value_type, Traits>>,
1909+
Konieczny<typename Container::value_type, Traits>>
1910+
make(Container const& gens) {
1911+
if (gens.size() == 0) {
1912+
LIBSEMIGROUPS_EXCEPTION(
1913+
"expected a positive number of generators, but got 0");
1914+
}
1915+
Konieczny<typename Container::value_type, Traits> result;
1916+
result.add_generators(std::begin(gens), std::end(gens));
1917+
return result;
1918+
}
1919+
1920+
// TODO(0) doc
1921+
template <template <typename...> typename Thing,
1922+
typename Element,
1923+
typename Traits = KoniecznyTraits<Element>>
1924+
[[nodiscard]] std::enable_if_t<
1925+
std::is_same_v<Konieczny<Element, Traits>, Thing<Element, Traits>>,
1926+
Konieczny<Element, Traits>>
1927+
make(std::initializer_list<Element> const& gens) {
1928+
return make<Konieczny, std::initializer_list<Element>>(gens);
1929+
}
1930+
19071931
} // namespace libsemigroups
19081932
#include "konieczny.tpp"
19091933
#endif // LIBSEMIGROUPS_KONIECZNY_HPP_

tests/test-konieczny-bmat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace libsemigroups {
3535
BMat<4>) {
3636
auto rg = ReportGuard(false);
3737

38-
Konieczny S(
38+
Konieczny S = make<Konieczny>(
3939
{TestType({{0, 1, 0, 1}, {1, 0, 0, 0}, {0, 1, 1, 1}, {0, 1, 1, 0}}),
4040
TestType({{0, 1, 1, 1}, {1, 1, 0, 0}, {0, 0, 0, 0}, {1, 1, 1, 1}}),
4141
TestType({{0, 1, 1, 0}, {0, 1, 1, 0}, {0, 1, 1, 1}, {1, 1, 1, 1}})});
@@ -51,7 +51,7 @@ namespace libsemigroups {
5151
BMat<4>) {
5252
auto rg = ReportGuard(false);
5353

54-
Konieczny S(
54+
Konieczny S = make<Konieczny>(
5555
{TestType({{1, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 0}}),
5656
TestType({{1, 0, 0, 1}, {1, 0, 0, 1}, {1, 1, 1, 1}, {0, 1, 1, 0}}),
5757
TestType({{1, 0, 1, 0}, {1, 0, 1, 1}, {0, 0, 1, 1}, {0, 1, 0, 1}}),
@@ -85,7 +85,7 @@ namespace libsemigroups {
8585
BMat<4>) {
8686
auto rg = ReportGuard(false);
8787
REQUIRE_THROWS_AS(
88-
Konieczny(
88+
make<Konieczny>(
8989
{make<TestType>(
9090
{{1, 0, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 0}}),
9191
make<TestType>({{1, 0, 0}, {1, 0, 0}, {1, 1, 1}})}),
@@ -120,7 +120,7 @@ namespace libsemigroups {
120120
{0, 1, 1, 1, 0},
121121
{1, 0, 0, 0, 1}})};
122122

123-
Konieczny<TestType> S(gens);
123+
Konieczny S = make<Konieczny>(gens);
124124
REQUIRE(S.size() == 513);
125125
}
126126
} // namespace libsemigroups

tests/test-konieczny-bmat8-1.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ namespace libsemigroups {
4141
using BMat = BMatFastest<4>;
4242
auto rg = ReportGuard(false);
4343

44-
Konieczny KS(
44+
Konieczny KS = make<Konieczny>(
4545
{BMat({{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
4646
BMat({{0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}}),
4747
BMat({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {1, 0, 0, 1}}),
@@ -82,10 +82,10 @@ namespace libsemigroups {
8282
"regular D-class 01",
8383
"[quick][bmat8]") {
8484
auto rg = ReportGuard(false);
85-
Konieczny KS({BMat8({{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}),
86-
BMat8({{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}),
87-
BMat8({{1, 0, 0}, {1, 1, 0}, {0, 0, 1}}),
88-
BMat8({{1, 1, 0}, {0, 1, 1}, {1, 0, 1}})});
85+
Konieczny KS = make<Konieczny>({BMat8({{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}),
86+
BMat8({{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}),
87+
BMat8({{1, 0, 0}, {1, 1, 0}, {0, 0, 1}}),
88+
BMat8({{1, 1, 0}, {0, 1, 1}, {1, 0, 1}})});
8989
REQUIRE(KS.size() == 247);
9090

9191
BMat8 x({{1, 0, 0}, {1, 1, 0}, {1, 0, 1}});
@@ -102,7 +102,7 @@ namespace libsemigroups {
102102
"[quick][bmat8][no-valgrind]") {
103103
auto rg = ReportGuard(false);
104104

105-
Konieczny KS(
105+
Konieczny KS = make<Konieczny>(
106106
{BMat8({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
107107
BMat8({{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
108108
BMat8({{0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}}),
@@ -122,7 +122,7 @@ namespace libsemigroups {
122122
"[quick][no-valgrind][bmat8]") {
123123
auto rg = ReportGuard(false);
124124

125-
Konieczny KS(
125+
Konieczny KS = make<Konieczny>(
126126
{BMat8({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
127127
BMat8({{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
128128
BMat8({{0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0}}),
@@ -148,10 +148,10 @@ namespace libsemigroups {
148148
"[quick][bmat8]") {
149149
auto rg = ReportGuard(false);
150150

151-
Konieczny KS({BMat8({{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}),
152-
BMat8({{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}),
153-
BMat8({{1, 0, 0}, {1, 1, 0}, {0, 0, 1}}),
154-
BMat8({{1, 1, 0}, {0, 1, 1}, {1, 0, 1}})});
151+
auto KS = make<Konieczny>({BMat8({{0, 1, 0}, {0, 0, 1}, {1, 0, 0}}),
152+
BMat8({{0, 1, 0}, {1, 0, 0}, {0, 0, 1}}),
153+
BMat8({{1, 0, 0}, {1, 1, 0}, {0, 0, 1}}),
154+
BMat8({{1, 1, 0}, {0, 1, 1}, {1, 0, 1}})});
155155
KS.run();
156156

157157
REQUIRE(KS.number_of_regular_D_classes() == 9);
@@ -245,7 +245,7 @@ namespace libsemigroups {
245245
"[quick][bmat8]") {
246246
auto rg = ReportGuard(false);
247247

248-
Konieczny KS(
248+
Konieczny KS = make<Konieczny>(
249249
{BMat8({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
250250
BMat8({{0, 1, 0, 0}, {1, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
251251
BMat8({{0, 1, 0, 1}, {1, 0, 1, 0}, {1, 0, 1, 0}, {0, 0, 1, 1}}),
@@ -265,7 +265,7 @@ namespace libsemigroups {
265265
"[quick][no-valgrind][bmat8]") {
266266
auto rg = ReportGuard(false);
267267

268-
Konieczny S(
268+
Konieczny S = make<Konieczny>(
269269
{BMat8({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}),
270270
BMat8({{1, 1, 1, 0}, {1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1}}),
271271
BMat8({{1, 1, 0, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}}),

0 commit comments

Comments
 (0)