OpenTTD
|
Simple matrix template class. More...
#include <smallmatrix_type.hpp>
Public Member Functions | |
SmallMatrix (const SmallMatrix &other) | |
Copy constructor. | |
SmallMatrix & | operator= (const SmallMatrix &other) |
Assignment. | |
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. | |
void | EraseColumnPreservingOrder (uint x, uint count=1) |
Remove columns from the matrix while preserving the order of other columns. | |
void | EraseRow (uint y) |
Erase a row, replacing it with the last one. | |
void | EraseRowPreservingOrder (uint y, uint count=1) |
Remove columns from the matrix while preserving the order of other columns. | |
void | AppendRow (uint to_add=1) |
Append rows. | |
void | AppendColumn (uint to_add=1) |
Append rows. | |
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. | |
uint | Height () const |
uint | Width () const |
const T & | Get (uint x, uint y) const |
Get item x/y (const). | |
T & | Get (uint x, uint y) |
Get item x/y. | |
const T * | operator[] (uint x) const |
Get column "number" (const) | |
T * | operator[] (uint x) |
Get column "number" (const) |
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 40 of file smallmatrix_type.hpp.
|
inline |
Copy constructor.
other | The other matrix to copy. |
Definition at line 55 of file smallmatrix_type.hpp.
|
inline |
Append rows.
to_add | Number of rows to append. |
Definition at line 205 of file smallmatrix_type.hpp.
|
inline |
Append rows.
to_add | Number of rows to append. |
Definition at line 196 of file smallmatrix_type.hpp.
|
inline |
Erase a column, replacing it with the last one.
x | Position of the column. |
Definition at line 133 of file smallmatrix_type.hpp.
Referenced by LinkGraph::RemoveNode().
|
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 147 of file smallmatrix_type.hpp.
|
inline |
Erase a row, replacing it with the last one.
x | Position of the row. |
Definition at line 164 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 180 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 278 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 291 of file smallmatrix_type.hpp.
|
inline |
Assignment.
other | The other matrix to assign. |
Definition at line 69 of file smallmatrix_type.hpp.
|
inline |
Get column "number" (const)
X | Position of the column. |
Definition at line 303 of file smallmatrix_type.hpp.
|
inline |
Get column "number" (const)
X | Position of the column. |
Definition at line 315 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.
width | Target width. |
height | Target height. |
Definition at line 216 of file smallmatrix_type.hpp.
Referenced by LinkGraph::AddNode(), SmallMatrix< BaseEdge >::AppendColumn(), SmallMatrix< BaseEdge >::AppendRow(), SmallMatrix< BaseEdge >::EraseRow(), SmallMatrix< BaseEdge >::EraseRowPreservingOrder(), LinkGraphJob::Init(), and LinkGraph::Init().