GF2++
Loading...
Searching...
No Matches
BitSpan.h
Go to the documentation of this file.
1#pragma once
2// SPDX-FileCopyrightText: 2025 Nessan Fitzmaurice <nzznfitz+gh@icloud.com>
3// SPDX-License-Identifier: MIT
4
8
9#include <gf2/BitStore.h>
10#include <gf2/Iterators.h>
11#include <gf2/BitRef.h>
12#include <gf2/BitVector.h>
13
14namespace gf2 {
15
29template<Unsigned Word = usize>
30class BitSpan {
31private:
32 // A pointer to the first word containing bits in the span (it may be partially occupied).
33 Word* m_store = nullptr;
34
35 // The bit-span begins at this bit-offset inside `m_store[0]`.
36 u8 m_offset = 0;
37
38 // The number of bits in the span.
39 usize m_size = 0;
40
41 // The number of words (synthesised) needed to hold the bits in the span (cached for efficiency).
42 usize m_words = 0;
43
44public:
45 // The underlying span uses words of this type (where we remove any `const` qualifier).
46 using word_type = std::remove_const_t<Word>;
47
49 static constexpr u8 bits_per_word = BITS<Word>;
50
53
75 BitSpan(Word* data, u8 offset, usize size) {
76
77 // Check that offset is valid.
78 gf2_debug_assert(offset < bits_per_word, "Span begins at bit-offset {} > bits in a word ({})!", offset,
80
81 // Set the member variables.
82 m_store = data;
83 m_offset = offset;
84 m_size = size;
85 m_words = gf2::words_needed<Word>(m_size);
86 }
87
91
100 constexpr usize size() const { return m_size; }
101
116 constexpr usize words() const { return m_words; }
117
133 constexpr word_type word(usize i) const {
134 // Get the recipe for the "word" at index `i` (we may need two real words to synthesise it).
135 auto [w0_bits, w1_bits] = recipe_for_word(i);
136
137 // Our return value starts with all unset bits.
138 word_type result = 0;
139
140 // Replace `w0_bits` low-order bits in `result` with the same number of high-order bits from `w0`
141 Word w0 = m_store[i];
142 gf2::replace_bits(result, 0, w0_bits, w0 >> m_offset);
143
144 // Perhaps our result spans two words.
145 if (w1_bits > 0) {
146 // Replace `w1_bits` high-order bits in result with the same number of low-order bits from `w1`
147 Word w1 = m_store[i + 1];
148 gf2::replace_bits(result, w0_bits, w0_bits + w1_bits, w1 << w0_bits);
149 }
150 return result;
151 }
152
170 constexpr void set_word(usize i, word_type value) {
171 if constexpr (std::is_const_v<Word>) {
172 // This should never get called for const bit-spans.
173 throw std::logic_error("Cannot set a word in a const bit-span.");
174 } else {
175 // Get the recipe for the "word" at index `i` (it may be a synthesis of two real words).
176 auto [w0_bits, w1_bits] = recipe_for_word(i);
177
178 // Replace `w0_bits` low-order bits in `w0` with the same number of high-order bits from `value`
179 // Shift `value` to the left to align its bits with the start of `w0`.
180 gf2::replace_bits(m_store[i], m_offset, m_offset + w0_bits, value << m_offset);
181
182 // Perhaps we also need to overwrite some bits in the second word.
183 if (w1_bits > 0) {
184 // Replace `w1_bits` low-order bits in `w1` with the same number of high-order bits from `value`
185 gf2::replace_bits(m_store[i + 1], 0, w1_bits, value >> w0_bits);
186 }
187 }
188 }
189
191 constexpr const Word* store() const { return m_store; }
192
194 constexpr Word* store() { return m_store; }
195
197 constexpr u8 offset() const { return m_offset; }
198
202
216 constexpr bool get(usize i) const { return gf2::get(*this, i); }
217
229 constexpr bool operator[](usize i) const { return gf2::get(*this, i); }
230
242 constexpr bool front() const { return gf2::front(*this); }
243
255 constexpr bool back() const { return gf2::back(*this); }
256
260
276 constexpr auto set(usize i, bool value = true) {
277 gf2::set(*this, i, value);
278 return *this;
279 }
280
304 constexpr auto operator[](usize i) { return gf2::ref(*this, i); }
305
320 constexpr auto flip(usize i) {
321 gf2::flip(*this, i);
322 return *this;
323 }
324
341 constexpr auto swap(usize i0, usize i1) {
342 gf2::swap(*this, i0, i1);
343 return *this;
344 }
345
349
360 constexpr bool is_empty() const { return gf2::is_empty(*this); }
361
374 constexpr bool any() const { return gf2::any(*this); }
375
390 constexpr bool all() const { return gf2::all(*this); }
391
404 constexpr bool none() const { return gf2::none(*this); }
405
409
422 auto set_all(bool value = true) { return gf2::set_all(*this, value); }
423
434 auto flip_all() { return gf2::flip_all(*this); }
435
439
464 template<Unsigned Src>
465 constexpr auto copy(Src src) {
466 gf2::copy(src, *this);
467 return *this;
468 }
469
487 template<typename Iter>
488 requires std::is_unsigned_v<typename std::iterator_traits<Iter>::value_type>
489 constexpr void copy(Iter src_begin, Iter src_end) {
490 gf2::copy(src_begin, src_end, *this);
491 }
492
493
512 template<BitStore Src>
513 constexpr auto copy(Src const& src) {
514 gf2::copy(src, *this);
515 return *this;
516 ;
517 }
518
536 template<usize N>
537 constexpr auto copy(std::bitset<N> const& src) {
538 gf2::copy(src, *this);
539 return *this;
540 ;
541 }
542
546
557 constexpr auto copy(std::invocable<usize> auto f) {
558 gf2::copy(*this, f);
559 return *this;
560 }
561
581 constexpr auto fill_random(double p = 0.5, u64 seed = 0) {
582 gf2::fill_random(*this, p, seed);
583 return *this;
584 }
585
589
600 constexpr usize count_ones() const { return gf2::count_ones(*this); }
601
612 constexpr usize count_zeros() const { return gf2::count_zeros(*this); }
613
626 constexpr usize leading_zeros() const { return gf2::leading_zeros(*this); }
627
640 constexpr usize trailing_zeros() const { return gf2::trailing_zeros(*this); }
641
645
658 constexpr std::optional<usize> first_set() const { return gf2::first_set(*this); }
659
673 constexpr std::optional<usize> last_set() const { return gf2::last_set(*this); }
674
687 constexpr std::optional<usize> next_set(usize index) const { return gf2::next_set(*this, index); }
688
701 constexpr std::optional<usize> previous_set(usize index) const { return gf2::previous_set(*this, index); }
702
706
719 constexpr std::optional<usize> first_unset() const { return gf2::first_unset(*this); }
720
734 constexpr std::optional<usize> last_unset() const { return gf2::last_unset(*this); }
735
749 constexpr std::optional<usize> next_unset(usize index) const { return gf2::next_unset(*this, index); }
750
763 constexpr std::optional<usize> previous_unset(usize index) const { return gf2::previous_unset(*this, index); }
764
768
783 constexpr auto bits() const { return gf2::bits(*this); }
784
801 constexpr auto bits() { return gf2::bits(*this); }
802
815 constexpr auto set_bits() const { return gf2::set_bits(*this); }
816
829 constexpr auto unset_bits() const { return gf2::unset_bits(*this); }
830
850 constexpr auto store_words() const { return gf2::store_words(*this); }
851
855
876 constexpr void to_words(std::output_iterator<word_type> auto out) { gf2::to_words(*this, out); }
877
890 constexpr auto to_words() const { return gf2::to_words(*this); }
891
895
911 constexpr auto span(usize begin, usize end) const { return gf2::span(*this, begin, end); }
912
932 constexpr auto span(usize begin, usize end) { return gf2::span(*this, begin, end); }
933
937
954 constexpr auto sub(usize begin, usize end) const { return gf2::sub(*this, begin, end); }
955
959
983 constexpr void split_at(usize at, BitVector<word_type>& left, BitVector<word_type>& right) const {
984 return gf2::split(*this, at, left, right);
985 }
986
1006 constexpr auto split_at(usize at) const { return gf2::split(*this, at); }
1007
1011
1026 constexpr void riffled(BitVector<word_type>& dst) const { return gf2::riffle(*this, dst); }
1027
1040 constexpr auto riffled() const { return gf2::riffle(*this); }
1041
1045
1063 std::string to_binary_string(std::string_view sep = "", std::string_view pre = "",
1064 std::string_view post = "") const {
1065 return gf2::to_binary_string(*this, sep, pre, post);
1066 }
1067
1085 std::string to_string(std::string_view sep = "", std::string_view pre = "", std::string_view post = "") const {
1086 return gf2::to_string(*this, sep, pre, post);
1087 }
1088
1102 std::string to_pretty_string() const { return gf2::to_pretty_string(*this); }
1103
1129 std::string to_hex_string() const { return gf2::to_hex_string(*this); }
1130
1134 std::string describe() const { return gf2::describe(*this); }
1135
1137
1138private:
1139 // A helper method to get the recipe used to "bake" the (generally synthetic) `word(i)`.
1140 //
1141 // Spans may not be aligned with the underlying unsigneds so we need to synthesise "words" as needed.
1142 // To synthesise word `i`, we use two contiguous words from the underlying vector of words, `w0`, and `w1`,
1143 // where `w0` is always m_words[i] and `w1` is always m_words[i + 1].
1144 //
1145 // We copy `w0_bits` high-order bits from `w0` and they become the low-order bits in the span "word": `word(i)`.
1146 // We copy `w1_bits` low-order bits from `w1` and they become the high-order bits in the span "word": `word(i)`.
1147 //
1148 // This "recipe" method returns the pair: `(w0_bits, w1_bits)` which tells you the numbers of needed bits.
1149 //
1150 // The only tricky part is that the last span word may not be fully occupied so we need to handle it differently
1151 // from the others.
1152 //
1153 // In debug mode we also check that the index `i` is valid.
1154 constexpr auto recipe_for_word(usize i) const {
1155 gf2_debug_assert(i < m_words, "Index {} should be less than {}", i, m_words);
1156
1157 // The default recipe (these sum to a whole word of bits).
1158 u8 w0_bits = bits_per_word - m_offset;
1159 u8 w1_bits = m_offset;
1160
1161 // The last word in the span may not be fully occupied so we need to adjust the bits accordingly.
1162 if (i == m_words - 1) {
1163 auto last_offset = static_cast<u8>((m_offset + m_size - 1) % bits_per_word);
1164 if (last_offset < m_offset) {
1165 // Still need to use two words but `w1-bits` may shrink.
1166 w1_bits = static_cast<u8>(last_offset + 1);
1167 } else {
1168 // Only need to use one word so no need for `w1_bits`.
1169 w0_bits = static_cast<u8>(last_offset - m_offset + 1);
1170 w1_bits = 0;
1171 }
1172 }
1173 return std::pair{w0_bits, w1_bits};
1174 }
1175};
1176
1177} // namespace gf2
A BitRef is a proxy type that references a single bit in a bit-store. See the BitRef page for more ...
A concept for types that can access individual bits packed into contiguous primitive unsigned words,...
Vectors over GF(2) with compactly stored bit-elements in a standard vector of primitive unsigned word...
Five bit-store iterators that serve different purposes. See the Iterators page for more details.
#define gf2_debug_assert(cond,...)
A confirmation macro that checks a boolean condition cond. On failure, the confirmation prints an e...
Definition assert.h:68
constexpr usize leading_zeros() const
Returns the number of leading zeros in the bit-span.
Definition BitSpan.h:626
constexpr auto sub(usize begin, usize end) const
Returns a clone of the span elements in the half-open range [begin, end) as a new bit-vector.
Definition BitSpan.h:954
constexpr auto copy(std::bitset< N > const &src)
Copies all the bits from an equal-sized std::bitset and returns a reference to this for chaining.
Definition BitSpan.h:537
auto set_all(bool value=true)
Sets the bits in the bit-span to the boolean value and returns a reference to this for chaining.
Definition BitSpan.h:422
constexpr std::optional< usize > first_set() const
Returns the index of the first set bit in the bit-span or {} if no bits are set.
Definition BitSpan.h:658
constexpr void copy(Iter src_begin, Iter src_end)
Copies all the bits from an iteration of any unsigned integral src values to this equal-sized bit-spa...
Definition BitSpan.h:489
std::string describe() const
Returns a multi-line string describing the bit-span in some detail.
Definition BitSpan.h:1134
constexpr auto unset_bits() const
Returns an iterator over the indices of any unset bits in the bit-span.
Definition BitSpan.h:829
constexpr bool front() const
Returns true if the first bit element is set, false otherwise.
Definition BitSpan.h:242
constexpr usize size() const
Returns the number of bits in the bit-span.
Definition BitSpan.h:100
constexpr std::optional< usize > next_set(usize index) const
Returns the index of the next set bit after index in the bit-span or {} if no more set bits exist.
Definition BitSpan.h:687
constexpr auto set(usize i, bool value=true)
Sets the bit-element i to the specified boolean value & returns this for chaining....
Definition BitSpan.h:276
constexpr bool any() const
Returns true if at least one bit in the bit-span is set, false otherwise.
Definition BitSpan.h:374
static constexpr u8 bits_per_word
A constant – the number of bits in a Word.
Definition BitSpan.h:49
constexpr auto flip(usize i)
Flips the value of the bit-element i and returns this for chaining.
Definition BitSpan.h:320
constexpr bool operator[](usize i) const
Returns the boolean value of the bit element i.
Definition BitSpan.h:229
constexpr auto split_at(usize at) const
Views a bit-span as two parts containing the elements [0, at) and [at, size()) respectively.
Definition BitSpan.h:1006
constexpr auto bits()
Returns a non-const iterator over the values of the bits in the mutable bit-span.
Definition BitSpan.h:801
constexpr auto copy(Src const &src)
Copies all the bits from an equal-sized src bit-store and returns a reference to this for chaining.
Definition BitSpan.h:513
constexpr auto swap(usize i0, usize i1)
Swaps the bits in the bit-span at indices i0 and i1 and returns this for chaining.
Definition BitSpan.h:341
constexpr word_type word(usize i) const
Returns a "word"'s worth of bits from the bit-span.
Definition BitSpan.h:133
BitSpan(Word *data, u8 offset, usize size)
Constructs a non-owning view over bits stored in contiguous words — a bit-span.
Definition BitSpan.h:75
constexpr std::optional< usize > next_unset(usize index) const
Returns the index of the next unset bit after index in the bit-span or {} if no more unset bits exist...
Definition BitSpan.h:749
constexpr auto span(usize begin, usize end)
Returns an mutable sub-span encompassing the bit-span's bits in the half-open range [begin,...
Definition BitSpan.h:932
constexpr usize trailing_zeros() const
Returns the number of trailing zeros in the bit-span.
Definition BitSpan.h:640
constexpr bool all() const
Returns true if all bits in the bit-span are set, false otherwise.
Definition BitSpan.h:390
constexpr const Word * store() const
Returns a pointer to the first bit-span word in some underlying span of words (const version).
Definition BitSpan.h:191
constexpr auto bits() const
Returns a const iterator over the bool values of the bits in the const bit-span.
Definition BitSpan.h:783
std::string to_binary_string(std::string_view sep="", std::string_view pre="", std::string_view post="") const
Returns a binary string representation of the bit-span.
Definition BitSpan.h:1063
std::string to_string(std::string_view sep="", std::string_view pre="", std::string_view post="") const
Returns a binary string representation of the bit-span.
Definition BitSpan.h:1085
constexpr Word * store()
Returns a pointer to the first bit-span word in some underlying span of words (non-const version).
Definition BitSpan.h:194
constexpr bool is_empty() const
Returns true if the bit-span is empty, false otherwise.
Definition BitSpan.h:360
constexpr std::optional< usize > first_unset() const
Returns the index of the first unset bit in the bit-span or {} if no bits are unset.
Definition BitSpan.h:719
constexpr void set_word(usize i, word_type value)
Sets a "word"'s worth of bits in the bit-span.
Definition BitSpan.h:170
constexpr auto span(usize begin, usize end) const
Returns an immutable sub-span encompassing the bit-span's bits in the half-open range [begin,...
Definition BitSpan.h:911
std::string to_hex_string() const
Returns the "hex" string representation of the bits in the bit-span.
Definition BitSpan.h:1129
constexpr auto store_words() const
Returns a const iterator over all the words underlying the bit-span.
Definition BitSpan.h:850
std::string to_pretty_string() const
Returns a "pretty" string representation of the bit-span.
Definition BitSpan.h:1102
constexpr auto set_bits() const
Returns an iterator over the indices of any set bits in the bit-span.
Definition BitSpan.h:815
constexpr std::optional< usize > previous_set(usize index) const
Returns the index of the previous set bit before index in the bit-span or {} if there are none.
Definition BitSpan.h:701
constexpr std::optional< usize > last_unset() const
Returns the index of the last unset bit in the bit-span or {} if no bits are unset.
Definition BitSpan.h:734
constexpr usize count_zeros() const
Returns the number of unset bits in the bit-span.
Definition BitSpan.h:612
constexpr u8 offset() const
Returns the offset (in bits) of the first bit in the bit-span within the first bit-span word.
Definition BitSpan.h:197
auto flip_all()
Flips the value of the bits in the bit-span and returns a reference to this for chaining.
Definition BitSpan.h:434
constexpr std::optional< usize > last_set() const
Returns the index of the last set bit in the bit-span or {} if no bits are set.
Definition BitSpan.h:673
constexpr usize words() const
Returns the minimum number of words needed to hold the bits in the bit-span.
Definition BitSpan.h:116
constexpr void to_words(std::output_iterator< word_type > auto out)
Returns a copy of the words underlying this bit-span and puts them into the passed output iterator.
Definition BitSpan.h:876
constexpr std::optional< usize > previous_unset(usize index) const
Returns the index of the previous unset bit before index in the bit-span or {} if no more unset bits ...
Definition BitSpan.h:763
constexpr auto operator[](usize i)
Returns a "reference" to the bit element i.
Definition BitSpan.h:304
constexpr bool back() const
Returns true if the last bit element is set, false otherwise.
Definition BitSpan.h:255
constexpr auto copy(std::invocable< usize > auto f)
Fill the bit-span by repeatedly calling f(i) and returns a reference to this for chaining.
Definition BitSpan.h:557
constexpr void split_at(usize at, BitVector< word_type > &left, BitVector< word_type > &right) const
Views a bit-span as two parts containing the elements [0, at) and [at, size()) respectively.
Definition BitSpan.h:983
constexpr auto copy(Src src)
Copies all the bits from any unsigned integral src value to this equal-sized bit-span and returns a r...
Definition BitSpan.h:465
constexpr bool get(usize i) const
Returns true if the bit at the given index i is set, false otherwise.
Definition BitSpan.h:216
constexpr bool none() const
Returns true if no bits in the bit-span are set, false otherwise.
Definition BitSpan.h:404
constexpr void riffled(BitVector< word_type > &dst) const
Interleaves the bits of this bit-span with zeros storing the result into the bit-vector dst.
Definition BitSpan.h:1026
constexpr auto riffled() const
Returns a new bit-vector that is the result of riffling the bits in this bit-span with zeros.
Definition BitSpan.h:1040
constexpr auto fill_random(double p=0.5, u64 seed=0)
Fill the bit-span with random bits and returns a reference to this for chaining.
Definition BitSpan.h:581
constexpr usize count_ones() const
Returns the number of set bits in the bit-span.
Definition BitSpan.h:600
constexpr auto to_words() const
Returns a copy of the words underlying this bit-span as a std::vector<word_type>.
Definition BitSpan.h:890
A dynamically-sized vector over GF(2) with bit elements compactly stored in a standard vector of prim...
Definition BitVector.h:23
The namespace for the gf2 library.
Definition assert.h:119
constexpr void set(Store &store, usize i, bool value=true)
Sets the bit-element at the given index to the specified boolean value (default value is true).
Definition BitStore.h:254
constexpr void set_all(Store &store, bool value=true)
Sets the bits in the store to the boolean value.
Definition BitStore.h:439
constexpr std::optional< usize > first_unset(Store const &store)
Returns the index of the first unset bit in the bit-store or {} if no bits are unset.
Definition BitStore.h:974
constexpr std::optional< usize > first_set(Store const &store)
Returns the index of the first set bit in the bit-store or {} if no bits are set.
Definition BitStore.h:841
constexpr bool is_empty(Store const &store)
Returns true if the store is empty, false otherwise.
Definition BitStore.h:345
constexpr std::optional< usize > next_unset(Store const &store, usize index)
Returns the index of the next unset bit after index in the store or {} if no more unset bits exist.
Definition BitStore.h:1039
constexpr void swap(Store &store, usize i0, usize i1)
Swaps the bits in the bit-store at indices i0 and i1.
Definition BitStore.h:307
constexpr void replace_bits(Word &word, u8 begin, u8 end, Other other)
Replace the bits of word in the range [begin, end) with the bits from other leaving the rest unchange...
Definition Unsigned.h:272
static std::string to_string(Store const &store, std::string_view sep="", std::string_view pre="", std::string_view post="")
Returns a binary string representation of a store.
Definition BitStore.h:1588
constexpr auto ref(Store &store, usize i)
Returns a "reference" to the bit element i in the given bit-store.
Definition BitStore.h:197
constexpr usize count_zeros(Store const &store)
Returns the number of unset bits in the store.
Definition BitStore.h:762
constexpr void split(Store const &store, usize at, BitVector< typename Store::word_type > &left, BitVector< typename Store::word_type > &right)
Views a bit-store as two parts containing the elements [0, at) and [at, size()) respectively....
Definition BitStore.h:1387
constexpr bool get(Store const &store, usize i)
Returns the bool value of the bit at index i in the given bit-store.
Definition BitStore.h:168
constexpr auto set_bits(Store const &store)
Returns an iterator over the indices of any set bits in the bit-store.
Definition BitStore.h:1170
constexpr bool back(Store const &store)
Returns true if the final bit element is set, false otherwise.
Definition BitStore.h:235
static std::string to_pretty_string(Store const &store)
Returns a "pretty" string representation of a store.
Definition BitStore.h:1606
std::uint64_t u64
Word type alias for a 64-bit unsigned integer.
Definition Unsigned.h:39
constexpr std::optional< usize > previous_set(Store const &store, usize index)
Returns the index of the previous set bit before index in the store or {} if there are none.
Definition BitStore.h:928
constexpr auto store_words(Store const &store)
Returns a const iterator over all the words underlying the bit-store.
Definition BitStore.h:1211
constexpr std::optional< usize > next_set(Store const &store, usize index)
Returns the index of the next set bit after index in the store or {} if no more set bits exist.
Definition BitStore.h:890
std::uint8_t u8
Word type alias for an 8-bit unsigned integer.
Definition Unsigned.h:30
constexpr bool all(Store const &store)
Returns true if all bits in the store are set, false otherwise.
Definition BitStore.h:385
constexpr auto sub(Store const &store, usize begin, usize end)
Returns a clone of the elements in the half-open range [begin, end) as a new bit-vector.
Definition BitStore.h:1356
static constexpr auto span(Store const &store, usize begin, usize end)
Constructs a read-only bit-span over the const bit-store store for its bits in the range [begin,...
Definition BitStore.h:1277
constexpr void flip_all(Store &store)
Flips the value of the bits in the store.
Definition BitStore.h:455
constexpr auto bits(Store const &store)
Returns a const iterator over the bool values of the bits in the const bit-store.
Definition BitStore.h:1133
constexpr auto unset_bits(Store const &store)
Returns an iterator over the indices of any unset bits in the bit-store.
Definition BitStore.h:1187
constexpr void flip(Store &store, usize i)
Flips the value of the bit-element at the given index.
Definition BitStore.h:279
static std::string to_hex_string(Store const &store)
Returns the "hex" string representation of the bits in the bit-store.
Definition BitStore.h:1642
constexpr usize count_ones(Store const &store)
Returns the number of set bits in the store.
Definition BitStore.h:745
constexpr usize leading_zeros(Store const &store)
Returns the number of leading zeros in the store.
Definition BitStore.h:779
constexpr std::optional< usize > previous_unset(Store const &store, usize index)
Returns the index of the previous unset bit before index in the store or {} if no more unset bits exi...
Definition BitStore.h:1084
constexpr void copy(Src src, Store &store)
Copies all the bits from any unsigned integral src value to an equal-sized bit-store.
Definition BitStore.h:485
constexpr bool front(Store const &store)
Returns true if the first bit element is set, false otherwise.
Definition BitStore.h:216
constexpr void to_words(Store const &store, std::output_iterator< typename Store::word_type > auto out)
Returns a copy of the words underlying this bit-store and puts them into the passed output iterator.
Definition BitStore.h:1235
constexpr usize trailing_zeros(Store const &store)
Returns the number of trailing zeros in the store.
Definition BitStore.h:800
std::size_t usize
Word type alias for the platform's "native"-sized unsigned integer.
Definition Unsigned.h:42
constexpr bool none(Store const &store)
Returns true if no bits in the store are set, false otherwise.
Definition BitStore.h:419
constexpr void riffle(Store const &store, BitVector< typename Store::word_type > &dst)
Interleaves the bits of a bit-store with zeros storing the result into the passed bit-vector dst.
Definition BitStore.h:1468
constexpr void fill_random(Store &store, double p=0.5, u64 seed=0)
Fill the store with random bits based on an optional probability p and an optional seed for the RNG.
Definition BitStore.h:697
constexpr u8 BITS
The number of bits in an Unsigned returned as a u8.
Definition Unsigned.h:55
constexpr bool any(Store const &store)
Returns true if at least one bit in the store is set, false otherwise.
Definition BitStore.h:363
constexpr std::optional< usize > last_unset(Store const &store)
Returns the index of the last unset bit in the bit-store or {} if no bits are unset.
Definition BitStore.h:1007
constexpr usize words_needed(usize n_bits)
Returns the number of Unsigneds needed to store n_bits bits.
Definition Unsigned.h:530
static std::string describe(Store const &store)
Detailed Description of a Bit-Store.
Definition BitStore.h:1685
static std::string to_binary_string(Store const &store, std::string_view sep="", std::string_view pre="", std::string_view post="")
Returns a binary string representation of a store.
Definition BitStore.h:1537
constexpr std::optional< usize > last_set(Store const &store)
Returns the index of the last set bit in the bit-store or {} if no bits are set.
Definition BitStore.h:866