|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Matrix whose columns are bit fields: an Aleph::Array of Packed_Row. More...
#include <tpl_packed_matrix.H>
Public Types | |
| using | Row = Packed_Row< Cols... > |
| Type of a row. | |
Public Member Functions | |
| Packed_Matrix (const size_t num_rows=0) | |
| Build a matrix whose columns are all at their lowest value. | |
| Packed_Matrix (const size_t num_rows, const Row &row) | |
| Build a matrix whose rows are all equal to a given one. | |
| size_t | rows () const noexcept |
| Number of rows. | |
| Row & | operator() (const size_t i) &noexcept |
| Access a row without checking. | |
| const Row & | operator() (const size_t i) const &noexcept |
| Read a row without checking. | |
| Row | operator() (const size_t i) &&noexcept |
| Copy a row of a temporary matrix, without checking. | |
| Row::Fast_Cell | operator() (const size_t i, const size_t j) &noexcept |
| Access an entry without checking. | |
| std::int64_t | operator() (const size_t i, const size_t j) const &noexcept |
| Read an entry without checking. | |
| std::int64_t | fast_read (const size_t i, const size_t j) const noexcept |
| Read an entry without checking. | |
| void | fast_write (const size_t i, const size_t j, const std::int64_t v) noexcept |
| Write an entry without checking. | |
| Row & | operator[] (const size_t i) & |
| Access a row. | |
| const Row & | operator[] (const size_t i) const & |
| Read a row. | |
| Row | operator[] (const size_t i) && |
| Copy a row of a temporary matrix. | |
| std::int64_t | read (const size_t i, const size_t j) const |
| Read an entry. | |
| void | write (const size_t i, const size_t j, const std::int64_t v) |
| Write an entry. | |
| void | fill (const Row &row) noexcept |
| Set every row to a given one. | |
| void | swap (Packed_Matrix &m) noexcept |
| Exchange the rows of two matrices in constant time. | |
| void | prefetch (const size_t i) const noexcept |
| Hint the processor to bring a row into the cache. | |
| Row * | data () noexcept |
| The rows as a contiguous array. | |
| const Row * | data () const noexcept |
| The rows as a contiguous array. | |
| Row * | begin () noexcept |
Start of the rows, for a range-based for. | |
| const Row * | begin () const noexcept |
Start of the rows, for a range-based for. | |
| Row * | end () noexcept |
| End of the rows. | |
| const Row * | end () const noexcept |
| End of the rows. | |
Static Public Member Functions | |
| static constexpr size_t | cols () noexcept |
| Number of columns. | |
Private Member Functions | |
| void | check_row (const size_t i) const |
| Validate a row index. | |
Private Attributes | |
| Array< Row > | rows_ |
| The rows. | |
Friends | |
| bool | operator== (const Packed_Matrix &a, const Packed_Matrix &b) noexcept |
| Test whether two matrices hold the same rows. | |
Matrix whose columns are bit fields: an Aleph::Array of Packed_Row.
The number of rows is given at construction; the columns and the integers that each one holds are part of the type. A row takes sizeof(Row) bytes: one word of 1, 2, 4 or 8 bytes when its columns fit in 64 bits, and words of 8 bytes otherwise. A column that does not fit in what is left of a word starts the next one, and leaves the rest of that word unused: Packed_Row<bits(3), bits(62), bits(3)> takes 24 bytes, not 16.
As in Aleph::Array, operator() does not check and operator[] does:
| Access | Checks |
|---|---|
m(i, j), m(i), fast_read(), fast_write() | nothing; asserted in Debug builds |
m[i][j], m[i], read(), write() | the indexes, and the value on writing |
Row r = m(i); ...; m(i) = r;). Writing the columns one by one through the matrix loads and stores the row once per column.| Cols | Ranges of the columns, in order: values of Bit_Column built with between(), bits() or signed_bits(). |
Definition at line 864 of file tpl_packed_matrix.H.
| using Aleph::Packed_Matrix< Cols >::Row = Packed_Row<Cols...> |
Type of a row.
Definition at line 868 of file tpl_packed_matrix.H.
|
inlineexplicit |
Build a matrix whose columns are all at their lowest value.
| [in] | num_rows | Number of rows. |
| std::bad_alloc | if there is not enough memory. |
| std::overflow_error | if the size of the rows does not fit in size_t. |
Definition at line 894 of file tpl_packed_matrix.H.
|
inline |
Build a matrix whose rows are all equal to a given one.
| [in] | num_rows | Number of rows. |
| [in] | row | The row to copy. |
| std::bad_alloc | if there is not enough memory. |
| std::overflow_error | if the size of the rows does not fit in size_t. |
Definition at line 906 of file tpl_packed_matrix.H.
|
inlinenoexcept |
Start of the rows, for a range-based for.
Definition at line 1153 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::data().
|
inlinenoexcept |
Start of the rows, for a range-based for.
Definition at line 1145 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::data().
|
inlineprivate |
Validate a row index.
| [in] | i | The index. |
| std::out_of_range | if i >= rows(). |
Definition at line 880 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_, and Aleph::packed_matrix_detail::throw_bad_row().
Referenced by Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::read(), and Aleph::Packed_Matrix< Cols >::write().
|
inlinestaticconstexprnoexcept |
Number of columns.
Row::num_cols. Definition at line 921 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::num_cols.
|
inlinenoexcept |
The rows as a contiguous array.
Definition at line 1137 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
The rows as a contiguous array.
rows()*sizeof(Row) bytes from here hold the whole matrix, in the byte order of the machine. Definition at line 1129 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
Referenced by Aleph::Packed_Matrix< Cols >::begin(), Aleph::Packed_Matrix< Cols >::begin(), Aleph::Packed_Matrix< Cols >::end(), and Aleph::Packed_Matrix< Cols >::end().
|
inlinenoexcept |
End of the rows.
Definition at line 1169 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::data(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
End of the rows.
Definition at line 1161 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::data(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Read an entry without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
| [in] | j | The column; must be less than cols() (asserted in Debug builds). |
Definition at line 989 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Write an entry without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
| [in] | j | The column; must be less than cols() (asserted in Debug builds). |
| [in] | v | The value; must be in the range of column j (asserted in Debug builds). |
Definition at line 1004 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Set every row to a given one.
| [in] | row | The row to copy. |
Definition at line 1074 of file tpl_packed_matrix.H.
|
inlinenoexcept |
Copy a row of a temporary matrix, without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
Definition at line 951 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Access a row without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
Definition at line 931 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Read a row without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
Definition at line 941 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Access an entry without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
| [in] | j | The column; must be less than cols() (asserted in Debug builds). |
Definition at line 963 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Read an entry without checking.
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
| [in] | j | The column; must be less than cols() (asserted in Debug builds). |
Definition at line 977 of file tpl_packed_matrix.H.
References Aleph::Packed_Row< Cols >::fast_read(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inline |
Access a row.
| [in] | i | The row. |
operator[] checks the column, and the value on writing. | std::out_of_range | if i >= rows(). |
Definition at line 1015 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::check_row(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inline |
Copy a row of a temporary matrix.
| [in] | i | The row. |
operator[] checks the column. | std::out_of_range | if i >= rows(). |
Definition at line 1038 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::check_row(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inline |
Read a row.
| [in] | i | The row. |
operator[] checks the column. | std::out_of_range | if i >= rows(). |
Definition at line 1026 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::check_row(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Hint the processor to bring a row into the cache.
On a matrix that does not fit in the cache, the first access to a row waits for main memory. When the rows of a pass are known some steps before they are used, hinting each one that many steps ahead lets its wait overlap the work on the rows before it:
| [in] | i | The row; must be less than rows() (asserted in Debug builds). |
Definition at line 1109 of file tpl_packed_matrix.H.
References offset, row, and Aleph::Packed_Matrix< Cols >::rows_.
|
inline |
Read an entry.
| [in] | i | The row. |
| [in] | j | The column. |
Definition at line 1050 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::check_row(), and Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Number of rows.
Definition at line 913 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::rows_.
|
inlinenoexcept |
Exchange the rows of two matrices in constant time.
| [in,out] | m | The other matrix. |
Definition at line 1083 of file tpl_packed_matrix.H.
References m, and Aleph::Packed_Matrix< Cols >::rows_.
|
inline |
Write an entry.
| [in] | i | The row. |
| [in] | j | The column. |
| [in] | v | The value. |
| std::out_of_range | if i >= rows() or j >= cols(). |
| std::domain_error | if v is outside the range of column j. |
Definition at line 1064 of file tpl_packed_matrix.H.
References Aleph::Packed_Matrix< Cols >::check_row(), and Aleph::Packed_Matrix< Cols >::rows_.
|
friend |
Test whether two matrices hold the same rows.
| [in] | a | A matrix. |
| [in] | b | Another matrix. |
a equals that of b. Definition at line 1181 of file tpl_packed_matrix.H.
|
private |
The rows.
Definition at line 874 of file tpl_packed_matrix.H.
Referenced by Aleph::Packed_Matrix< Cols >::check_row(), Aleph::Packed_Matrix< Cols >::data(), Aleph::Packed_Matrix< Cols >::data(), Aleph::Packed_Matrix< Cols >::end(), Aleph::Packed_Matrix< Cols >::end(), Aleph::Packed_Matrix< Cols >::fast_read(), Aleph::Packed_Matrix< Cols >::fast_write(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Matrix< Cols >::operator()(), Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::operator[](), Aleph::Packed_Matrix< Cols >::prefetch(), Aleph::Packed_Matrix< Cols >::read(), Aleph::Packed_Matrix< Cols >::rows(), Aleph::Packed_Matrix< Cols >::swap(), and Aleph::Packed_Matrix< Cols >::write().