word_array
The template class word_array
serves as the base for all other types that interpret underlying words as numbers.
Hint
The class word_array
is only used internally. The aarith end-user, most likely, will have no need to directly
interact with this class. No knowledge of it is necessary to use aarith.
-
template<size_t Width, class WordType = uint64_t>
class aarith::word_array Subclassed by aarith::integer< Width, WordType >, aarith::uinteger< Width, WordType >, aarith::uinteger< BitWidth+1, WordType >, aarith::uinteger< E, WordType >, aarith::uinteger< MW, WordType >
Public Functions
-
constexpr word_array() = default
Default constructor for the word array.
Initializes the word array to store only zeros.
-
inline explicit word_array(std::string_view bs)
Creates a word_array from a given bit string.
Example: word_array<5> w = word_array<5>::from_bit_string(“11010”);
If the supplied bit string is longer than the word_array to be created, the rest of the bits will be ignored. If the word_array has more bits than the string, these bits are initialized with zero.
- Parameters
bs – The bitstring to create the word array from
- Returns
A word_array with the same bits set as in the paramater bs
-
template<size_t V, typename T>
inline void set_bits(size_t end, const word_array<V, T> &other) - Template Parameters
V – Bit width of the word_array
T – Word type to store the data in
- Parameters
end –
other – The word_array to take the values from
-
inline constexpr auto msb() const -> bit_type
Returns ths most significant bit.
The most significant bit is the Width’s one (i.e. the one you can get via bit(Width-1)). This method is simply there for convenience.
-
inline void constexpr set_msb(const bool b)
Sets the value of the most significant bit (MSB)
- Parameters
b – The value the MSB is set to
-
inline auto constexpr bit(size_t index) const -> bit_type
Returns bit at given index.
Note
No bounds checking is performed! If your index is too large bad things will happen!
- Parameters
index – The index for which the bit is to be returned
- Returns
The bit at the indexed position
-
inline auto at(size_t pos) const
Returns a const reference to the element at specified location pos, with bounds checking.
If pos is not within the range of the container, an exception of type std::out_of_range is thrown.
- Parameters
pos – position of the element to return
- Returns
Const reference to the requested element.
-
inline auto operator[](size_t pos) const
Returns a reference to the element at specified location pos. No bounds checking is performed.
- Parameters
pos – position of the element to return
- Returns
Const reference to the requested element.
-
inline constexpr bool empty() const noexcept
Checks if the container has no elements.
- Returns
false
-
inline auto front() const
Returns a const reference to the first element in the container.
- Returns
Const reference to the first element
-
inline auto back() const
- Returns
Const reference to the last element.
-
inline constexpr size_t size() const noexcept
Returns the number of words in the array.
Note
The most significant word might be be used entirely. The most significant bits might be masked away.
- Returns
The number of words used store the number
-
inline constexpr void fill(const word_type &value)
Assigns the specified value to all elements in the container.
- Parameters
value – the value to assign to the elements
-
inline bool constexpr is_zero() const noexcept
Tests if all bits are zero.
- Returns
True iff all bits are zero
Public Static Functions
-
static inline constexpr word_array<Width, WordType> all_ones()
Creates a word array consisting of ones only.
- Returns
<111…..11>
-
static inline constexpr word_array<Width, WordType> msb_one()
Creates a word array with only the most significant bit being one.
- Returns
<10000….00>
-
static inline constexpr word_array<Width, WordType> all_zeroes()
Creates a word array consisting of zeroes only.
- Returns
<000…00>
-
constexpr word_array() = default