2D array container.This class is used to store a 2D array of elements of any type as a single continuous block of memory (a plain PIVector). Elements can be accessed using the [][] operators, where the first index is the row and the second is the column. Rows can be manipulated as PIVector objects, allowing modification of individual elements or assignment of entire rows. You cannot directly add or remove elements to change the dimensions of the array after construction (use resize(), addRow(), removeRow(), removeColumn() instead), but you can modify the values of existing elements.
More...
|
| | PIVector2D () |
| | Constructs an empty 2D array. No memory is allocated. After this constructor, rows() and cols() return 0, and isEmpty() returns true. More...
|
| |
| | PIVector2D (size_t rows, size_t cols, const T &f=T()) |
| | Constructs a 2D array with the given dimensions, filled with copies of f. The underlying storage is a single contiguous block of memory of size rows * cols. All elements are initialized with the value f. More...
|
| |
| | PIVector2D (size_t rows, size_t cols, const PIVector< T > &v) |
| | Constructs a 2D array from an existing 1D vector, reshaping it. The constructor copies the data from v into the internal flat vector. If v is larger than rows * cols, the excess elements are ignored (the vector is truncated). If v is smaller, other values filled whith default cunstructor T() More...
|
| |
| | PIVector2D (size_t rows, size_t cols, PIVector< T > &&v) |
| | Move constructs a 2D array from an existing 1D vector, reshaping it. The data is moved from v into the internal flat vector, avoiding a copy. After construction, v is left in a valid but unspecified state. More...
|
| |
|
| PIVector2D (const PIVector< PIVector< T > > &v) |
| | Constructs a 2D array from a vector of vectors (jagged array). Assumes all inner vectors have the same size. If the input is empty, the constructed array is also empty. Otherwise, the number of columns is taken from the size of the first inner vector. All inner vectors are concatenated in the internal flat storage.
|
| |
| size_t | rows () const |
| | Returns the number of rows in the 2D array. The result is always non-negative. If the array is empty, returns 0. More...
|
| |
| size_t | cols () const |
| | Returns the number of columns in the 2D array. The result is always non-negative. If the array is empty, returns 0. More...
|
| |
| size_t | size () const |
| | Returns the total number of elements (rows * cols). This is equivalent to the size of the underlying flat vector. More...
|
| |
| ssize_t | size_s () const |
| | Returns the total number of elements as a signed value. More...
|
| |
| size_t | length () const |
| | Returns the total number of elements (same as size()). More...
|
| |
|
size_t | capacity () const |
| | Returns the number of elements that the underlying container has currently allocated space for. This value may be larger than size(). It indicates how many elements can be added before a reallocation is needed.
|
| |
| bool | isEmpty () const |
| | Checks if the array has no elements. An empty array has both rows and columns equal to 0. More...
|
| |
| bool | isNotEmpty () const |
| | Checks if the array has at least one element. More...
|
| |
| T & | element (size_t row, size_t col) |
| | Returns a reference to the element at the given row and column. No bounds checking is performed. More...
|
| |
|
const T & | element (size_t row, size_t col) const |
| | Returns a const reference to the element at the given row and column.
|
| |
|
const T & | at (size_t row, size_t col) const |
| | Returns a const reference to the element at the given row and column No bounds checking is performed.
|
| |
|
T & | operator[] (const Index &idx) |
| | Returns a reference to the element at the given Index.
|
| |
|
const T & | operator[] (const Index &idx) const |
| | Returns a const reference to the element at the given Index.
|
| |
|
T & | element (const Index &idx) |
| | Returns a reference to the element at the given Index.
|
| |
|
const T & | element (const Index &idx) const |
| | Returns a const reference to the element at the given Index.
|
| |
|
const T & | at (const Index &idx) const |
| | Returns a const reference to the element at the given Index (bounds-checked only in debug).
|
| |
| Row | operator[] (size_t index) |
| | Returns a proxy object for the row at the given index for modification. More...
|
| |
|
RowConst | operator[] (size_t index) const |
| | Returns a proxy object for the row at the given index for read-only access.
|
| |
| T * | data (size_t index=0) |
| | Returns a pointer to the underlying flat data starting at an optional offset. More...
|
| |
|
const T * | data (size_t index=0) const |
| | Returns a const pointer to the underlying flat data starting at an optional offset.
|
| |
| Row | row (size_t index) |
| | Returns a proxy object for the row at the given index for modification. More...
|
| |
|
RowConst | row (size_t index) const |
| | Returns a proxy object for the row at the given index for read-only access.
|
| |
| Col | col (size_t index) |
| | Returns a proxy object for the column at the given index for modification. More...
|
| |
|
ColConst | col (size_t index) const |
| | Returns a proxy object for the column at the given index for read-only access.
|
| |
|
PIVector2D< T > & | setRow (size_t row, const RowConst &other) |
| | Replaces a row with the contents of a read-only RowConst object.
|
| |
|
PIVector2D< T > & | setRow (size_t row, const PIVector< T > &other) |
| | Replaces a row with the contents of a PIVector.
|
| |
| PIVector2D< T > & | addRow (const RowConst &other) |
| | Appends a new row to the bottom of the array from another Row object. If the array was empty, its column count is set to the size of the source row. Otherwise, only min(cols(), other.size()) elements are copied; the rest of the new row is default-initialized. More...
|
| |
|
PIVector2D< T > & | addRow (const PIVector< T > &other) |
| | Appends a new row to the bottom of the array from a PIVector.
|
| |
| PIVector2D< T > & | appendRows (size_t count, const T &f=T()) |
| | Appends count new empty rows to the bottom of the array, filled with value f. If the array was empty (no columns defined), the column count is set to 1. The new rows are filled with the default value f. More...
|
| |
| PIVector2D< T > & | appendColumns (size_t count, const T &f=T()) |
| | Appends count new empty columns to the end of each row of the array. If the array was empty (rows not defined), the array becomes a single row with count columns. If the array already has rows, new elements are inserted at the end of each existing row. More...
|
| |
| PIVector2D< T > & | deleteRows (size_t row_start, size_t count) |
| | Deletes count rows starting from the specified row index. Removes the specified rows from the array and updates the row count. If all elements are deleted (array becomes empty), both rows and columns are set to 0. More...
|
| |
| PIVector2D< T > & | deleteColumns (size_t col_start, size_t count) |
| | Removes the specified columns from the array and updates the column count. Removes count columns starting from col_start. If col_start is out of range or count is 0, the function does nothing. If count extends beyond the last column, only available columns are deleted. More...
|
| |
|
PIVector2D< T > & | addColumn (const ColConst &other) |
| | Appends a new column to the right of the array from a ColConst.
|
| |
|
PIVector2D< T > & | addColumn (const PIVector< T > &other) |
| | Appends a new column to the right of the array from a PIVector.
|
| |
| PIVector2D< T > & | resize (size_t rows, size_t cols, const T &f=T()) |
| | Resizes the 2D array to new dimensions. If the new dimensions are larger, new elements are appended and filled with copies of f. If they are smaller, the array is truncated (excess elements are destroyed). The underlying memory may be reallocated. More...
|
| |
| bool | operator== (const PIVector2D< T > &t) const |
| | Equality operator. More...
|
| |
|
bool | operator!= (const PIVector2D< T > &t) const |
| | Inequality operator.
|
| |
| PIVector< PIVector< T > > | toVectors () const |
| | Converts the 2D array to a vector of vectors (PIVector<PIVector<T>>). Each row vector is a copy of the corresponding row. More...
|
| |
|
const PIVector< T > & | asPlainVector () const |
| | Returns a const reference to the underlying flat PIVector.
|
| |
|
PIVector< T > & | asPlainVector () |
| | Returns a reference to the underlying flat PIVector.
|
| |
|
PIVector< T > | toPlainVector () const |
| | Returns a copy of the underlying flat PIVector.
|
| |
| void | swap (PIVector2D< T > &other) |
| | Swaps this 2D array with another. Swaps the flat vectors and the dimension members. Very fast, no memory allocation. More...
|
| |
| void | clear () |
| | Clears the array, removing all elements and setting dimensions to 0. The capacity of the underlying flat vector may remain unchanged. More...
|
| |
| bool | contains (const T &e) const |
| | Checks if the underlying flat vector contains the element e. More...
|
| |
| int | entries (const T &e) const |
| | Counts occurrences of e in the underlying flat vector. More...
|
| |
| int | entries (std::function< bool(const T &e)> test) const |
| | Counts elements in the flat vector that pass the test. More...
|
| |
| Index | indexOf (const T &e) const |
| | Returns the first index (row, col) of e in the 2D array. More...
|
| |
| Index | indexWhere (std::function< bool(const T &e)> test, ssize_t start=0) const |
| | Returns the first index (row, col) in the 2D array that passes the test. More...
|
| |
| Index | lastIndexOf (const T &e, ssize_t start=-1) const |
| | Returns the last index (row, col) of e in the 2D array. More...
|
| |
| Index | lastIndexWhere (std::function< bool(const T &e)> test, ssize_t start=-1) const |
| | Returns the last index (row, col) in the 2D array that passes the test. More...
|
| |
| bool | any (std::function< bool(const T &e)> test) const |
| | Tests if any element in the flat vector passes the test. More...
|
| |
| bool | every (std::function< bool(const T &e)> test) const |
| | Tests if all elements in the flat vector pass the test. More...
|
| |
| PIVector2D< T > & | fill (const T &e=T()) |
| | Fills the entire 2D array with copies of e. More...
|
| |
| PIVector2D< T > & | fill (std::function< T(size_t i)> f) |
| | Fills the entire 2D array using a generator function f based on flat index. More...
|
| |
|
PIVector2D< T > & | assign (const T &e=T()) |
| | Same as fill().
|
| |
| PIVector2D< T > & | assign (size_t rows, size_t cols, const T &f=T()) |
| | Assigns new size and fills with value. More...
|
| |
|
PIVector2D< T > | transposed () const |
| | Returns a transposed 2D array (rows become columns and vice versa). The element at (r, c) in the original becomes at (c, r) in the result.
|
| |
| PIVector2D< T > & | reverseRows () |
| | Reverses the order of rows in place. More...
|
| |
| PIVector2D< T > & | reverseColumns () |
| | Reverses the order of columns in each row in place. More...
|
| |
| PIVector2D< T > | getRange (size_t rowStart, size_t rowCount, size_t colStart, size_t colCount) const |
| | Returns a sub-2D array (a range of rows and columns). If the range exceeds the array boundaries, it is clipped. If rowCount or colCount is 0, an empty array is returned. More...
|
| |
| template<typename ST > |
| PIVector2D< ST > | map (std::function< ST(const T &e)> f) const |
| | Applies a function to each element and returns a new 2D array of a different type. The original array is not modified. More...
|
| |
| template<typename ST > |
| PIVector2D< ST > | mapIndexed (std::function< ST(size_t row, size_t col, const T &e)> f) const |
| | Applies a function (with row and col indices) to each element and returns a new 2D array. More...
|
| |
| PIVector2D< T > & | forEachRow (std::function< void(Row)> f) |
| | Applies a function to each row (modifiable). More...
|
| |
|
void | forEachRow (std::function< void(RowConst)> f) const |
| | Applies a function to each row (read-only).
|
| |
|
PIVector2D< T > & | forEachColumn (std::function< void(Col)> f) |
| | Applies a function to each column (modifiable).
|
| |
|
void | forEachColumn (std::function< void(ColConst)> f) const |
| | Applies a function to each column (read-only).
|
| |
| template<typename ST > |
| ST | reduce (std::function< ST(const T &e, const ST &acc)> f, const ST &initial=ST()) const |
| | Accumulates a value across all elements. More...
|
| |
| template<typename ST > |
| ST | reduceIndexed (std::function< ST(size_t row, size_t col, const T &e, const ST &acc)> f, const ST &initial=ST()) const |
| | Accumulates a value across all elements with indices. More...
|
| |
| PIVector2D< T > & | removeRow (size_t row) |
| | Removes a row from the 2D array. If the last row is removed and the array becomes empty, cols() is set to 0. More...
|
| |
| PIVector2D< T > & | removeColumn (size_t col) |
| | Removes a column from the 2D array. This operation is more expensive than removing a row because elements must be moved. More...
|
| |
| PIVector2D< T > & | removeRowsWhere (std::function< bool(const RowConst &)> test) |
| | Removes all rows that satisfy a condition. Rows are removed from the bottom to avoid index shifting issues. More...
|
| |
| PIVector2D< T > & | removeColumnsWhere (std::function< bool(const ColConst &)> test) |
| | Removes all columns that satisfy a condition. More...
|
| |
| PIVector2D< T > | filterRows (std::function< bool(const RowConst &)> test) const |
| | Returns a new 2D array containing only the rows that pass the test. More...
|
| |
| PIVector2D< T > | filterColumns (std::function< bool(const ColConst &)> test) const |
| | Returns a new 2D array containing only the columns that pass the test. More...
|
| |
template<typename T>
class PIVector2D< T >
2D array container.
This class is used to store a 2D array of elements of any type as a single continuous block of memory (a plain PIVector). Elements can be accessed using the [][] operators, where the first index is the row and the second is the column. Rows can be manipulated as PIVector objects, allowing modification of individual elements or assignment of entire rows. You cannot directly add or remove elements to change the dimensions of the array after construction (use resize(), addRow(), removeRow(), removeColumn() instead), but you can modify the values of existing elements.