OpenTTD Source
12.0-beta2
|
Simple matrix template class. More...
#include <smallmatrix_type.hpp>
Public Member Functions | |
SmallMatrix (const SmallMatrix &other) | |
Copy constructor. More... | |
SmallMatrix & | operator= (const SmallMatrix &other) |
Assignment. More... | |
void | Assign (const SmallMatrix &other) |
Assign items from other vector. | |
void | Clear () |
Remove all rows from the matrix. | |
void | Reset () |
Remove all items from the list and free allocated memory. | |
void | Compact () |
Compact the matrix down to the smallest possible size. | |
void | EraseColumn (uint x) |
Erase a column, replacing it with the last one. More... | |
void | EraseColumnPreservingOrder (uint x, uint count=1) |
Remove columns from the matrix while preserving the order of other columns. More... | |
void | EraseRow (uint y) |
Erase a row, replacing it with the last one. More... | |
void | EraseRowPreservingOrder (uint y, uint count=1) |
Remove columns from the matrix while preserving the order of other columns. More... | |
void | AppendRow (uint to_add=1) |
Append rows. More... | |
void | AppendColumn (uint to_add=1) |
Append rows. More... | |
void | Resize (uint new_width, uint new_height) |
Set the size to a specific width and height, preserving item positions as far as possible in the process. More... | |
uint | Height () const |
uint | Width () const |
const T & | Get (uint x, uint y) const |
Get item x/y (const). More... | |
T & | Get (uint x, uint y) |
Get item x/y. More... | |
const T * | operator[] (uint x) const |
Get column "number" (const) More... | |
T * | operator[] (uint x) |
Get column "number" (const) More... | |
Protected Attributes | |
T * | data |
The pointer to the first item. | |
uint | width |
Number of items over first axis. | |
uint | height |
Number of items over second axis. | |
uint | capacity |
The available space for storing items. | |
Simple matrix template class.
Allocating a matrix in one piece reduces overhead in allocations compared with allocating a vector of vectors and saves some pointer dereferencing. However, you can only get rectangular matrixes like this and if you're changing their height very often performance will probably be worse than with a vector of vectors, due to more frequent copying of memory blocks.
No iterators are provided as iterating the columns would require persistent column objects. Those do not exist. Providing iterators with transient column objects would tie each iterator to a column object, thus replacing previously retrieved columns when iterating and defeating the point of iteration.
It's expected that the items don't need to be constructed or deleted by the container. Only memory allocation and deallocation is performed. This is the same for all openttd "SmallContainer" classes.
T | The type of the items stored |
Definition at line 38 of file smallmatrix_type.hpp.
|
inline |
Copy constructor.
other | The other matrix to copy. |
Definition at line 53 of file smallmatrix_type.hpp.
|
inline |
Append rows.
to_add | Number of rows to append. |
Definition at line 203 of file smallmatrix_type.hpp.
|
inline |
Append rows.
to_add | Number of rows to append. |
Definition at line 194 of file smallmatrix_type.hpp.
|
inline |
Erase a column, replacing it with the last one.
x | Position of the column. |
Definition at line 131 of file smallmatrix_type.hpp.
|
inline |
Remove columns from the matrix while preserving the order of other columns.
x | First column to remove. |
count | Number of consecutive columns to remove. |
Definition at line 145 of file smallmatrix_type.hpp.
|
inline |
Erase a row, replacing it with the last one.
y | Position of the row. |
Definition at line 162 of file smallmatrix_type.hpp.
|
inline |
Remove columns from the matrix while preserving the order of other columns.
y | First column to remove. |
count | Number of consecutive columns to remove. |
Definition at line 178 of file smallmatrix_type.hpp.
|
inline |
Get item x/y.
x | X-position of the item. |
y | Y-position of the item. |
Definition at line 289 of file smallmatrix_type.hpp.
|
inline |
Get item x/y (const).
x | X-position of the item. |
y | Y-position of the item. |
Definition at line 276 of file smallmatrix_type.hpp.
|
inline |
Assignment.
other | The other matrix to assign. |
Definition at line 67 of file smallmatrix_type.hpp.
|
inline |
Get column "number" (const)
x | Position of the column. |
Definition at line 313 of file smallmatrix_type.hpp.
|
inline |
Get column "number" (const)
x | Position of the column. |
Definition at line 301 of file smallmatrix_type.hpp.
|
inline |
Set the size to a specific width and height, preserving item positions as far as possible in the process.
new_width | Target width. |
new_height | Target height. |
Definition at line 214 of file smallmatrix_type.hpp.
Referenced by LinkGraph::AddNode(), SmallMatrix< BaseEdge >::AppendColumn(), SmallMatrix< BaseEdge >::AppendRow(), LinkGraphJob::Init(), and LinkGraph::Init().