Skip to content

Commit

Permalink
Kambites hpp (libsemigroups#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-mitchell authored Dec 9, 2024
1 parent 35f0c5e commit 182529f
Show file tree
Hide file tree
Showing 16 changed files with 1,366 additions and 849 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ detailinclude_HEADERS += include/libsemigroups/detail/formatters.hpp
detailinclude_HEADERS += include/libsemigroups/detail/function-ref.hpp
detailinclude_HEADERS += include/libsemigroups/detail/int-range.hpp
detailinclude_HEADERS += include/libsemigroups/detail/iterator.hpp
detailinclude_HEADERS += include/libsemigroups/detail/kambites-normal-form-range.hpp
detailinclude_HEADERS += include/libsemigroups/detail/kambites-nf.hpp
detailinclude_HEADERS += include/libsemigroups/detail/kbe.hpp
detailinclude_HEADERS += include/libsemigroups/detail/kbe.tpp
detailinclude_HEADERS += include/libsemigroups/detail/ke.hpp
Expand Down
4 changes: 4 additions & 0 deletions docs/DoxygenLayout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
<tab type="user" visible="yes" url="@ref cong_intf_helpers_group" title="Helper functions"/>
</tab>
<tab type="user" visible="yes" url="@ref froidure_pin_group" title="Froidure-Pin" />
<tab type="usergroup" visible="yes" url="@ref kambites_group" title="Kambites">
<tab type="user" visible="yes" url="@ref libsemigroups::Kambites" title="The Kambites class" />
<tab type="user" visible="yes" url="@ref libsemigroups::kambites" title="Kambites helper functions" />
</tab>
<tab type="usergroup" visible="yes" url="@ref knuth_bendix_group" title="Knuth-Bendix">
<tab type="usergroup" visible="yes" url="@ref knuth_bendix_class_group" title="The KnuthBendix class">
<tab type="user" visible="yes" url="@ref knuth_bendix_class_mem_types_group" title="Member types"/>
Expand Down
3 changes: 2 additions & 1 deletion include/libsemigroups/cong.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ namespace libsemigroups {
} else if (cong.has<KnuthBendix<>>()
&& cong.get<KnuthBendix<>>()->finished()) {
return knuth_bendix::partition(*cong.get<KnuthBendix<>>(), r);
} else if (cong.has<Kambites<word_type>>()) {
} else if (cong.has<Kambites<word_type>>()
&& cong.get<Kambites<word_type>>()->success()) {
return kambites::partition(*cong.get<Kambites<word_type>>(), r);
}
LIBSEMIGROUPS_EXCEPTION("Cannot compute the non-trivial classes!");
Expand Down
106 changes: 106 additions & 0 deletions include/libsemigroups/detail/kambites-nf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// libsemigroups - C++ library for semigroups and monoids
// Copyright (C) 2024 James D. Mitchell
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

// This file contains an implementation of a range object for producing normal
// forms for a Kambites object.

#ifndef LIBSEMIGROUPS_DETAIL_KAMBITES_NF_HPP_
#define LIBSEMIGROUPS_DETAIL_KAMBITES_NF_HPP_

namespace detail {
template <typename Word>
class KambitesNormalFormRange {
private:
mutable typename Kambites<Word>::native_word_type _current;
FroidurePinBase::const_normal_form_iterator _end;
std::unique_ptr<FroidurePinBase> _fpb;
FroidurePinBase::const_normal_form_iterator _it;
Kambites<Word>* _k;

public:
using output_type = typename Kambites<Word>::native_word_type const&;

KambitesNormalFormRange() = delete;

explicit KambitesNormalFormRange(Kambites<Word>& k)
: _current(), _end(), _fpb(), _it(), _k() {
init(k);
}

KambitesNormalFormRange& init(Kambites<Word>& k) {
_current.clear();
_fpb = to_froidure_pin(k);
_it = _fpb->cbegin_current_normal_forms();
_k = &k;
_end = _fpb->cend_current_normal_forms();
return *this;
}

KambitesNormalFormRange(KambitesNormalFormRange const& that)
: KambitesNormalFormRange(*that._k) {}

KambitesNormalFormRange(KambitesNormalFormRange&& that) = default;

KambitesNormalFormRange& operator=(KambitesNormalFormRange const& that) {
return init(*that._k);
}

KambitesNormalFormRange& operator=(KambitesNormalFormRange&&) = default;

// TODO(0) init?
// TODO(1) allow setting of min/max etc like Paths

output_type get() const {
// TODO don't do this more than once per call
auto const& w = *_it;
_current.clear();
for (auto c : w) {
_current.push_back(_k->presentation().letter_no_checks(c));
}
return _current;
}

void next() {
++_it;
if (_it == _end) {
_fpb->enumerate(_fpb->current_size() + 1);
_end = _fpb->cend_current_normal_forms();
}
}

[[nodiscard]] bool at_end() const {
return false;
}

[[nodiscard]] uint64_t size_hint() const {
return POSITIVE_INFINITY;
}

[[nodiscard]] uint64_t count() const {
return size_hint();
}

static constexpr bool is_finite = false;
static constexpr bool is_idempotent = true;
};

template <typename Word>
KambitesNormalFormRange(Kambites<Word>&) -> KambitesNormalFormRange<Word>;

} // namespace detail
#endif // LIBSEMIGROUPS_DETAIL_KAMBITES_NF_HPP_
92 changes: 0 additions & 92 deletions include/libsemigroups/detail/kambites-normal-form-range.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion include/libsemigroups/detail/ke.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace libsemigroups {
template <typename Word>
class KE {
public:
using value_type = typename Kambites<Word>::value_type;
using value_type = typename Kambites<Word>::native_word_type;

private:
value_type _value;
Expand Down
8 changes: 4 additions & 4 deletions include/libsemigroups/detail/race.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ namespace libsemigroups {
return;
}
for (size_t i = 0; i < _runners.size(); ++i) {
if (_runners[i]->finished()) {
if (_runners[i]->success()) {
report_default("using 0 additional threads\n");
_winner = _runners[i];
_winner_index = i;
report_default("#{} is already finished!\n", i);
report_default("#{} already finished successfully!\n", i);
// delete the other runners?
return;
}
Expand All @@ -293,7 +293,7 @@ namespace libsemigroups {
// Stop two Runner* objects from killing each other
{
std::lock_guard<std::mutex> lg(_mtx);
if (_runners.at(pos)->finished()) {
if (_runners.at(pos)->success()) {
for (auto it = _runners.begin(); it < _runners.begin() + pos;
it++) {
(*it)->kill();
Expand All @@ -319,7 +319,7 @@ namespace libsemigroups {
report_default("\n");
for (auto method = _runners.begin(); method < _runners.end();
++method) {
if ((*method)->finished()) {
if ((*method)->success()) {
LIBSEMIGROUPS_ASSERT(_winner == nullptr);
_winner = *method;
_winner_index = method - _runners.begin();
Expand Down
Loading

0 comments on commit 182529f

Please sign in to comment.