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

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

Go to the source code of this file.

Namespaces

namespace  gf2
 The namespace for the gf2 library.

Concepts

concept  gf2::Unsigned
 The Unsigned concept is the same as std::unsigned_integral. It is satisfied by all primitive unsigned integer types.

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>
constexpr Word gf2::with_set_bits (u8 begin, u8 end)
 Returns an Unsigned with the bits in the half-open range [begin, end) set to 1 and the others set to 0.
template<Unsigned Word>
constexpr Word gf2::with_unset_bits (u8 begin, u8 end)
 Returns an Unsigned with the bits in the half-open range [begin, end) set to 0 and the others set to 1.
Bit mutators:
template<Unsigned 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>
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>
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>
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>
constexpr Word gf2::reverse_bits (Word word)
 Returns a copy of word with all its bits reversed.
template<Unsigned 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>
constexpr std::pair< Word, Word > gf2::riffle (Word word)
 Riffles an Unsigned into a pair of others containing the bits in the original word interleaved with zeros.
Bit Counts:
template<Unsigned Word>
constexpr u8 gf2::count_ones (Word word)
 Returns the number of set bits in an Unsigned.
template<Unsigned Word>
constexpr u8 gf2::count_zeros (Word word)
 Returns the number of unset bits in an Unsigned.
template<Unsigned Word>
constexpr u8 gf2::trailing_zeros (Word word)
 Returns the number of trailing zeros in an Unsigned.
template<Unsigned Word>
constexpr u8 gf2::leading_zeros (Word word)
 Returns the number of leading zeros in an Unsigned.
template<Unsigned Word>
constexpr u8 gf2::trailing_ones (Word word)
 Returns the number of trailing ones in an Unsigned.
template<Unsigned Word>
constexpr u8 gf2::leading_ones (Word word)
 Returns the number of leading ones in an Unsigned.
template<Unsigned Word>
constexpr std::optional< u8gf2::lowest_set_bit (Word word)
 Returns the index of the lowest set bit in an Unsigned or std::nullopt if no bits are set.
Searches:
template<Unsigned Word>
constexpr std::optional< u8gf2::highest_set_bit (Word word)
 Returns the index of the highest set bit in an Unsigned or std::nullopt if no bits are set.
template<Unsigned Word>
constexpr std::optional< u8gf2::lowest_unset_bit (Word word)
 Returns the index of the lowest unset bit in an Unsigned or std::nullopt if there are no unset bits.
template<Unsigned Word>
constexpr std::optional< u8gf2::highest_unset_bit (Word word)
 Returns the index of the highest unset bit in an Unsigned or std::nullopt if there are none.
Stringification:
template<Unsigned Word>
static std::string gf2::to_binary_string (Word word)
 Returns the binary string representation of an Unsigned showing all the bits.
template<Unsigned Word>
static std::string gf2::to_hex_string (Word word)
 Returns the hex string representation of an Unsigned showing all the bits.
Bit Locations:
template<Unsigned Word>
constexpr usize gf2::words_needed (usize n_bits)
 Returns the number of Unsigneds needed to store n_bits bits.
template<Unsigned Word>
constexpr usize gf2::word_index (usize i)
 Returns the index of the Unsigned word holding bit element i.
template<Unsigned Word>
constexpr u8 gf2::bit_offset (usize i)
 Returns the bit position within the containing word for bit element i.
template<Unsigned 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>
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>
constexpr u8 gf2::BITS = std::numeric_limits<Word>::digits
 The number of bits in an Unsigned returned as a u8.
template<Unsigned Word>
constexpr Word gf2::ZERO = Word{0}
 The zero value for an Unsigned type.
template<Unsigned Word>
constexpr Word gf2::ONE = Word{1}
 The one value for an Unsigned type.
template<Unsigned Word>
constexpr Word gf2::MAX = std::numeric_limits<Word>::max()
 The Unsigned instance with all its bits set to 1.
template<Unsigned Word>
constexpr Word gf2::ALTERNATING = MAX<Word> / 3
 The Unsigned instance with alternating bits set to 0 and 1.

Detailed Description

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