|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Tuple of small integers packed into the fewest whole words. More...
#include <tpl_packed_matrix.H>
Classes | |
| class | Proxy |
| Proxy of a column of a row that is not const. More... | |
Public Types | |
| using | Fast_Cell = Proxy< false > |
What r(j) returns on a row that is not const: writing does not check. | |
| using | Cell = Proxy< true > |
What r[j] returns on a row that is not const: writing validates the value. | |
Public Member Functions | |
| constexpr std::int64_t | fast_read (const size_t j) const noexcept |
| Read a column without checking. | |
| constexpr void | fast_write (const size_t j, const std::int64_t v) noexcept |
| Write a column without checking. | |
| constexpr std::int64_t | read (const size_t j) const |
| Read a column. | |
| constexpr void | write (const size_t j, const std::int64_t v) |
| Write a column. | |
| constexpr std::int64_t | operator() (const size_t j) const &noexcept |
| Read a column without checking. | |
| constexpr Fast_Cell | operator() (const size_t j) &noexcept |
| Access a column without checking. | |
| constexpr std::int64_t | operator[] (const size_t j) const & |
| Read a column. | |
| constexpr Cell | operator[] (const size_t j) & |
| Access a column. | |
Static Public Member Functions | |
| static constexpr std::int64_t | column_min (const size_t j) noexcept |
| Lowest value of a column. | |
| static constexpr std::int64_t | column_max (const size_t j) noexcept |
| Highest value of a column. | |
| static constexpr unsigned | column_bits (const size_t j) noexcept |
| Bits that a column takes. | |
| static constexpr bool | valid (const size_t j, const std::int64_t v) noexcept |
| Test whether a column can hold a value. | |
| static constexpr Packed_Row | lowest () noexcept |
| The row whose columns are all at their lowest value. | |
| template<class... Vs> requires (sizeof...(Vs) == sizeof...(Cols) and packed_matrix_detail::all_column_integers<Vs...>) | |
| static constexpr Packed_Row | fast_make (const Vs... vs) noexcept |
| Build a row from the values of its columns, without checking. | |
| template<class... Vs> requires (sizeof...(Vs) == sizeof...(Cols) and packed_matrix_detail::all_column_integers<Vs...>) | |
| static constexpr Packed_Row | make (const Vs... vs) |
| Build a row from the values of its columns. | |
Static Public Attributes | |
| static constexpr size_t | num_cols = sizeof...(Cols) |
| Number of columns. | |
| static constexpr size_t | num_bits = layout.bits |
Sum of the bits of the columns; 8*sizeof(Packed_Row) rounds it up. | |
Private Types | |
| using | Word = packed_matrix_detail::Word_Of< layout.word_bits > |
| Unsigned type of a word of the row. | |
Static Private Member Functions | |
| static constexpr void | check_value (const size_t j, const std::int64_t v) |
| Validate a value for a column. | |
| template<packed_matrix_detail::Column_Integer V> | |
| static constexpr void | check_argument (const size_t j, const V v) |
| Validate an argument of make() for a column. | |
| static constexpr void | check_column (const size_t j) |
| Validate a column index. | |
| static constexpr std::uint64_t | field (const size_t j, const std::int64_t v) noexcept |
| The bits of a column that stand for a value, in their place. | |
Private Attributes | |
| Word | words [layout.words] |
| The packed columns; the bits of no column are always zero. | |
Static Private Attributes | |
| static constexpr auto | layout |
| Where every column lives: widths, shifts and masks. | |
Friends | |
| constexpr bool | operator== (const Packed_Row &a, const Packed_Row &b) noexcept |
| Test whether two rows hold the same values. | |
| constexpr std::strong_ordering | operator<=> (const Packed_Row &a, const Packed_Row &b) noexcept |
| Compare two rows as their tuples of values, column 0 first. | |
Tuple of small integers packed into the fewest whole words.
It is the struct of bit fields that one would write by hand for a row, with the shifts and masks made explicit and worked out by the compiler from the ranges of the columns. Column j holds an integer of [Cols[j].lo, Cols[j].hi] in std::bit_width(hi - lo) bits.
A row is a value: it can be copied, compared and sorted. Rows compare as their tuples of values do, column 0 first, at the cost of comparing their words.
As in Aleph::Array, operator() does not check and operator[] does:
| Access | Checks |
|---|---|
r(j), fast_read(), fast_write(), fast_make() | nothing; asserted in Debug builds |
r[j], read(), write(), make() | the column, and the value on writing |
| Cols | Ranges of the columns, in order: values of Bit_Column built with between(), bits() or signed_bits(). |
int, a row declared without an initializer has indeterminate bits: write Row r{}; or use lowest() to get every column at its lowest value. r(j) and r[j] return a proxy: auto x = r(j); deduces the proxy, not an integer. Use fast_read() and read(), or name the type: std::int64_t x = r(j);. On a temporary row they return the value, which outlives it. std::int64_t are not. -fconstexpr-steps=). make() and fast_make() take one argument per column, and with thousands of them a call compiles slowly (15 to 20 s with 2048 columns at -O2): write such a row column by column.Definition at line 390 of file tpl_packed_matrix.H.
| using Aleph::Packed_Row< Cols >::Cell = Proxy<true> |
What r[j] returns on a row that is not const: writing validates the value.
Definition at line 573 of file tpl_packed_matrix.H.
| using Aleph::Packed_Row< Cols >::Fast_Cell = Proxy<false> |
What r(j) returns on a row that is not const: writing does not check.
Definition at line 570 of file tpl_packed_matrix.H.
|
private |
Unsigned type of a word of the row.
Definition at line 403 of file tpl_packed_matrix.H.
|
inlinestaticconstexprprivate |
Validate an argument of make() for a column.
| V | Its type. |
| [in] | j | The column, less than num_cols. |
| [in] | v | The argument. |
| std::domain_error | if v is outside the range of column j, also if it is an unsigned integer above the highest std::int64_t, which it would wrap to. |
Definition at line 532 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::check_value(), Aleph::packed_matrix_detail::fits_in_int64(), Aleph::Packed_Row< Cols >::layout, and Aleph::packed_matrix_detail::throw_bad_value().
Referenced by Aleph::Packed_Row< Cols >::make().
|
inlinestaticconstexprprivate |
Validate a column index.
| [in] | j | The index. |
| std::out_of_range | if j >= num_cols. |
Definition at line 544 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::num_cols, and Aleph::packed_matrix_detail::throw_bad_column().
Referenced by Aleph::Packed_Row< Cols >::operator[](), Aleph::Packed_Row< Cols >::read(), and Aleph::Packed_Row< Cols >::write().
|
inlinestaticconstexprprivate |
Validate a value for a column.
| [in] | j | The column, less than num_cols. |
| [in] | v | The value. |
| std::domain_error | if v is outside the range of column j. |
Definition at line 517 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, Aleph::packed_matrix_detail::throw_bad_value(), and Aleph::Packed_Row< Cols >::valid().
Referenced by Aleph::Packed_Row< Cols >::check_argument(), Aleph::Packed_Row< Cols >::Proxy< Checked >::operator=(), and Aleph::Packed_Row< Cols >::write().
|
inlinestaticconstexprnoexcept |
Bits that a column takes.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
std::bit_width(column_max(j) - column_min(j)), from 0 to 64. Definition at line 602 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, and Aleph::Packed_Row< Cols >::num_cols.
|
inlinestaticconstexprnoexcept |
Highest value of a column.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
j holds. Definition at line 591 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, and Aleph::Packed_Row< Cols >::num_cols.
|
inlinestaticconstexprnoexcept |
Lowest value of a column.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
j holds. Definition at line 580 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, and Aleph::Packed_Row< Cols >::num_cols.
|
inlinestaticconstexprnoexcept |
Build a row from the values of its columns, without checking.
The fastest way of writing a whole row: the columns are packed in registers and the row is stored once.
| Vs | Types of the values, one per column: integer types of at most 64 bits. |
| [in] | vs | Values of the columns, in order. Each must be in the range of its column (asserted in Debug builds). |
Definition at line 644 of file tpl_packed_matrix.H.
References Aleph::and, Aleph::Packed_Row< Cols >::field(), Aleph::packed_matrix_detail::fits_in_int64(), Aleph::Packed_Row< Cols >::layout, r, and Aleph::Packed_Row< Cols >::valid().
Referenced by Aleph::Packed_Row< Cols >::make().
|
inlineconstexprnoexcept |
Read a column without checking.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
j. Definition at line 682 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, Aleph::Packed_Row< Cols >::num_cols, and Aleph::Packed_Row< Cols >::words.
Referenced by Aleph::Packed_Row< Cols >::Proxy< Checked >::operator std::int64_t(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Row< Cols >::operator()(), Aleph::Packed_Row< Cols >::Proxy< Checked >::operator+=(), Aleph::Packed_Row< Cols >::Proxy< Checked >::operator-=(), and Aleph::Packed_Row< Cols >::read().
|
inlineconstexprnoexcept |
Write a column without checking.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
| [in] | v | The value; must be in the range of column j (asserted in Debug builds). |
j and does not touch the others. Definition at line 700 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::field(), Aleph::Packed_Row< Cols >::layout, m, Aleph::Packed_Row< Cols >::num_cols, Aleph::Packed_Row< Cols >::valid(), w, and Aleph::Packed_Row< Cols >::words.
Referenced by Aleph::Packed_Row< Cols >::Proxy< Checked >::operator=(), and Aleph::Packed_Row< Cols >::write().
|
inlinestaticconstexprprivatenoexcept |
The bits of a column that stand for a value, in their place.
| [in] | j | The column, less than num_cols. |
| [in] | v | The value. |
Definition at line 555 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::layout, and offset.
Referenced by Aleph::Packed_Row< Cols >::fast_make(), and Aleph::Packed_Row< Cols >::fast_write().
|
inlinestaticconstexprnoexcept |
The row whose columns are all at their lowest value.
Packed_Row{}. Definition at line 624 of file tpl_packed_matrix.H.
|
inlinestaticconstexpr |
Build a row from the values of its columns.
| Vs | Types of the values, one per column: integer types of at most 64 bits. |
| [in] | vs | Values of the columns, in order. |
| std::domain_error | if a value is outside the range of its column, also an unsigned one above the highest std::int64_t. |
Definition at line 670 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::check_argument(), and Aleph::Packed_Row< Cols >::fast_make().
|
inlineconstexprnoexcept |
Access a column without checking.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
Definition at line 753 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::num_cols.
|
inlineconstexprnoexcept |
Read a column without checking.
| [in] | j | The column; must be less than num_cols (asserted in Debug builds). |
j. Definition at line 743 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::fast_read().
|
inlineconstexpr |
Access a column.
| [in] | j | The column. |
| std::out_of_range | if j >= num_cols. |
Definition at line 776 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::check_column().
|
inlineconstexpr |
Read a column.
| [in] | j | The column. |
j. | std::out_of_range | if j >= num_cols. |
Definition at line 766 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::read().
|
inlineconstexpr |
Read a column.
| [in] | j | The column. |
j. | std::out_of_range | if j >= num_cols. |
Definition at line 716 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::check_column(), and Aleph::Packed_Row< Cols >::fast_read().
Referenced by Aleph::Packed_Row< Cols >::operator[]().
|
inlinestaticconstexprnoexcept |
Test whether a column can hold a value.
| [in] | j | The column. |
| [in] | v | The value. |
j < num_cols and v is in the range of column j. Definition at line 613 of file tpl_packed_matrix.H.
References Aleph::and, Aleph::Packed_Row< Cols >::layout, and Aleph::Packed_Row< Cols >::num_cols.
Referenced by Aleph::Packed_Row< Cols >::check_value(), Aleph::Packed_Row< Cols >::fast_make(), and Aleph::Packed_Row< Cols >::fast_write().
|
inlineconstexpr |
Write a column.
| [in] | j | The column. |
| [in] | v | The value. |
| std::out_of_range | if j >= num_cols. |
| std::domain_error | if v is outside the range of column j. |
Definition at line 729 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::check_column(), Aleph::Packed_Row< Cols >::check_value(), and Aleph::Packed_Row< Cols >::fast_write().
|
friend |
Compare two rows as their tuples of values, column 0 first.
| [in] | a | A row. |
| [in] | b | Another row. |
Definition at line 800 of file tpl_packed_matrix.H.
|
friend |
Test whether two rows hold the same values.
| [in] | a | A row. |
| [in] | b | Another row. |
a equals that of b. Definition at line 787 of file tpl_packed_matrix.H.
|
staticconstexprprivate |
Where every column lives: widths, shifts and masks.
Definition at line 399 of file tpl_packed_matrix.H.
Referenced by Aleph::Packed_Row< Cols >::check_argument(), Aleph::Packed_Row< Cols >::check_value(), Aleph::Packed_Row< Cols >::column_bits(), Aleph::Packed_Row< Cols >::column_max(), Aleph::Packed_Row< Cols >::column_min(), Aleph::Packed_Row< Cols >::fast_make(), Aleph::Packed_Row< Cols >::fast_read(), Aleph::Packed_Row< Cols >::fast_write(), Aleph::Packed_Row< Cols >::field(), and Aleph::Packed_Row< Cols >::valid().
|
staticconstexpr |
Sum of the bits of the columns; 8*sizeof(Packed_Row) rounds it up.
Definition at line 567 of file tpl_packed_matrix.H.
|
staticconstexpr |
Number of columns.
Definition at line 564 of file tpl_packed_matrix.H.
Referenced by Aleph::Packed_Row< Cols >::check_column(), Aleph::Packed_Matrix< Cols >::cols(), Aleph::Packed_Row< Cols >::column_bits(), Aleph::Packed_Row< Cols >::column_max(), Aleph::Packed_Row< Cols >::column_min(), Aleph::Packed_Row< Cols >::fast_read(), Aleph::Packed_Row< Cols >::fast_write(), Aleph::Packed_Row< Cols >::operator()(), and Aleph::Packed_Row< Cols >::valid().
|
private |
The packed columns; the bits of no column are always zero.
Definition at line 405 of file tpl_packed_matrix.H.
Referenced by Aleph::Packed_Row< Cols >::fast_read(), and Aleph::Packed_Row< Cols >::fast_write().