// // libsemigroups - C++ library for semigroups and monoids // Copyright (C) 2020 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/>. //
#include <array> // for array #include <bitset> // for bitset #include <climits> // for CHAR_BIT #include <cstddef> // for size_t #include <iosfwd> // for operator<<, ostringstream #include <type_traits> // for false_type #include <utility> // for hash
#include"config.hpp"// for LIBSEMIGROUPS_SIZEOF_VOID_P #include"debug.hpp"// for LIBSEMIGROUPS_ASSERT #include"exception.hpp"// for LIBSEMIGROUPS_EXCEPTION #include"string.hpp"// for detail::to_string
namespace libsemigroups {
// The code below for popcnt is borrowed/adapted from GAP.
template <size_t N> class BitSet {
static_assert(N > 0, "BitSet does not support 0 entries"); #if LIBSEMIGROUPS_SIZEOF_VOID_P == 8
static_assert(N <= 64, "BitSet does not support more than 64 entries"); #else
static_assert(N <= 32, "BitSet does not support more than 32 entries"); #endif
public: using block_type = std::conditional_t<
N <= 8,
uint_fast8_t,
std::conditional_t<
N <= 16,
uint_fast16_t,
std::conditional_t<N <= 32, uint_fast32_t, uint64_t>>>;
template <typename T>
BitSet(T first, T last) : BitSet() {
LIBSEMIGROUPS_ASSERT(first <= last);
size_t const K = std::distance(first, last); if (K > size()) {
LIBSEMIGROUPS_EXCEPTION( "the size of the container is %llu, trying to initialize with %llu " "items", static_cast<uint64_t>(size()), static_cast<uint64_t>(K))
} auto it = first; for (size_t i = 0; i < K; ++i, ++it) {
set(i, *it);
}
}
~BitSet() = default;
// Could be static
constexpr size_t size() const noexcept { return N;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.