GF2++
Loading...
Searching...
No Matches
unsigned_word.h

Utility functions that work on primitive unsigned word types.
See the unsigned word page for more details. More...

Go to the source code of this file.

Namespaces

namespace  gf2
 The namespace for the gf2 library.

Typedefs

Shorthand Type Aliases.
using gf2::u8 = std::uint8_t
 Word type alias for an 8-bit unsigned integer.
using gf2::u16 = std::uint16_t
 Word type alias for a 16-bit unsigned integer.
using gf2::u32 = std::uint32_t
 Word type alias for a 32-bit unsigned integer.
using gf2::u64 = std::uint64_t
 Word type alias for a 64-bit unsigned integer.
using gf2::usize = std::size_t
 Word type alias for the platform's "native"-sized unsigned integer.

Functions

Constructors:
template<unsigned_word Word>
constexpr Word gf2::with_set_bits (u8 begin, u8 end)
 Returns an unsigned_word with the bits in the half-open range [begin, end) set to 1 and the others set to 0.
template<unsigned_word Word>
constexpr Word gf2::with_unset_bits (u8 begin, u8 end)
 Returns an unsigned_word with the bits in the half-open range [begin, end) set to 0 and the others set to 1.
Bit mutators:
template<unsigned_word Word>
constexpr void gf2::set_bits (Word &word, u8 begin, u8 end)
 Sets the bits in the half-open range [begin, end) of word to one, leaving the others unchanged.
template<unsigned_word Word>
constexpr void gf2::reset_bits (Word &word, u8 begin, u8 end)
 Resets the bits in the half-open range [begin, end) of word to zero, leaving the others unchanged.
template<unsigned_word Word>
constexpr void gf2::set_except_bits (Word &word, u8 begin, u8 end)
 Sets the bits of word to 1 except for those in the half-open range [begin, end) which are unchanged.
template<unsigned_word Word>
constexpr void gf2::reset_except_bits (Word &word, u8 begin, u8 end)
 Sets the bits of word to 0 except for those in the half-open range [begin, end) which are unchanged.
template<unsigned_word Word>
constexpr Word gf2::reverse_bits (Word word)
 Returns a copy of word with all its bits reversed.
template<unsigned_word Word, typename Other>
requires std::convertible_to<Other, Word>
constexpr void gf2::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 unchanged.
Bit Riffling:
template<unsigned_word Word>
constexpr std::pair< Word, Word > gf2::riffle (Word word)
 Riffles an unsigned_word into a pair of others containing the bits in the original word interleaved with zeros.
Bit Counts:
template<unsigned_word Word>
constexpr u8 gf2::count_ones (Word word)
 Returns the number of set bits in an unsigned_word.
template<unsigned_word Word>
constexpr u8 gf2::count_zeros (Word word)
 Returns the number of unset bits in an unsigned_word.
template<unsigned_word Word>
constexpr u8 gf2::trailing_zeros (Word word)
 Returns the number of trailing zeros in an unsigned_word.
template<unsigned_word Word>
constexpr u8 gf2::leading_zeros (Word word)
 Returns the number of leading zeros in an unsigned_word.
template<unsigned_word Word>
constexpr u8 gf2::trailing_ones (Word word)
 Returns the number of trailing ones in an unsigned_word.
template<unsigned_word Word>
constexpr u8 gf2::leading_ones (Word word)
 Returns the number of leading ones in an unsigned_word.
template<unsigned_word Word>
constexpr std::optional< u8gf2::lowest_set_bit (Word word)
 Returns the index of the lowest set bit in an unsigned_word or std::nullopt if no bits are set.
Searches:
template<unsigned_word Word>
constexpr std::optional< u8gf2::highest_set_bit (Word word)
 Returns the index of the highest set bit in an unsigned_word or std::nullopt if no bits are set.
template<unsigned_word Word>
constexpr std::optional< u8gf2::lowest_unset_bit (Word word)
 Returns the index of the lowest unset bit in an unsigned_word or std::nullopt if there are no unset bits.
template<unsigned_word Word>
constexpr std::optional< u8gf2::highest_unset_bit (Word word)
 Returns the index of the highest unset bit in an unsigned_word or std::nullopt if there are none.
Stringification:
template<unsigned_word Word>
static std::string gf2::to_binary_string (Word word)
 Returns the binary string representation of an unsigned_word showing all the bits.
template<unsigned_word Word>
static std::string gf2::to_hex_string (Word word)
 Returns the hex string representation of an unsigned_word showing all the bits.
Bit Locations:
template<unsigned_word Word>
constexpr usize gf2::words_needed (usize n_bits)
 Returns the number of unsigned_words needed to store n_bits bits.
template<unsigned_word Word>
constexpr usize gf2::word_index (usize i)
 Returns the index of the unsigned_word word holding bit element i.
template<unsigned_word Word>
constexpr u8 gf2::bit_offset (usize i)
 Returns the bit position within the containing word for bit element i.
template<unsigned_word Word>
constexpr std::pair< usize, u8gf2::index_and_offset (usize i)
 Returns a pair of the index of the word and the bit position within the word for bit element i.
template<unsigned_word Word>
constexpr std::pair< usize, Word > gf2::index_and_mask (usize i)
 Returns a pair of the index of the word and a mask isolating bit element i.

Variables

Variables:
template<unsigned_word Word>
constexpr u8 gf2::BITS = std::numeric_limits<Word>::digits
 The number of bits in an unsigned_word returned as a u8.
template<unsigned_word Word>
constexpr Word gf2::ZERO = Word{0}
 The zero value for an unsigned_word type.
template<unsigned_word Word>
constexpr Word gf2::ONE = Word{1}
 The one value for an unsigned_word type.
template<unsigned_word Word>
constexpr Word gf2::MAX = std::numeric_limits<Word>::max()
 The unsigned_word instance with all its bits set to 1.
template<unsigned_word Word>
constexpr Word gf2::ALTERNATING = MAX<Word> / 3
 The unsigned_word instance with alternating bits set to 0 and 1.

Detailed Description

Utility functions that work on primitive unsigned word types.
See the unsigned word page for more details.