vecgrid
Vecgrid provides a dynamically sized two-dimensional vector. It is more efficient
and is easier to use than a vector of vectors, i.e. Vec<Vec<T>>.
This is beneficial when using a grid-like structure, which is common in image processing, game development, and other situations. Vecgrid cannot be used when rows or columns might have different lengths—all rows and columns must be the same length.
Vecgrid is a fork of the statically-sized two-dimensional array library Array2D.
Roadmap
This project attemps to extend the upstream project in an opinionated fashion, by adding mutable iterators and dynamic resizing of the inner collection. Here's how that is going:
-
row_iter_mut -
column_iter_mut -
rows_iter_mut -
columns_iter_mut -
elements_row_major_iter_mut -
elements_column_major_iter_mut -
insert_row -
insert_column -
insert_rows -
insert_columns -
remove_row -
remove column -
append_rows -
append_columns -
extend_rows -
extend_columns
Upstream code might be refactored along the way to make use of optimizations or to align approaches across the crate. Code deprecated upstream from before the inital release of this crate is dropped, future deprecated upstream code may or may not be deprecated in this crate in kind. A release of a major version of this crate indicates maturity surpassing active tracking of the upstream repository, but until then changes will be synced as they happen.
How to use Vecgrid
Creating a Vecgrid
A Vecgrid can be created in many different ways. These include:
- Providing the rows or the columns, which must all be the same size (see
from_rowsandfrom_columns). - Providing a "flat" slice of elements in either row major or column
major order along with the dimensions, which must match the number of
elements in the slice (see
from_row_majorandfrom_column_major). - Providing a value to repeatedly put in every location (see
filled_with). - Providing a generator function that is repeatedly called to produce
values to fill the vecgrid (see
filled_by_row_majorandfilled_by_column_major). - Providing an iterator that is used to produce values to fill the vecgrid
(see
from_iter_row_majorandfrom_iter_column_major).
Accessing data from a Vecgrid
Vecgrid supports several forms of indexing:
- Using the indexing syntax (square brackets) with a tuple of
(usize, usize), which panics on out-of-bounds accesses. - Using the
get,get_mut, andsetmethods, which return anOptionor aResulton out-of-bounds accesses. - Using the row major or column major version of these methods,
i.e. [
get_row_major], [get_mut_row_major], [set_row_major], [get_column_major], [get_mut_column_major], [set_column_major]. These perform the same tasks as the non row/column major methods, but take one index instead of two.
Vecgrid also supports several forms of iteration. You can iterate
through:
- All of the elements, in either row major or column major order (see
elements_row_major_iterandelements_column_major_iter). - All of the elements as mutable references, in row major or column major order (see
elements_row_major_iter_mutandelements_column_major_iter_mut). - Individual rows or columns (see
row_iterandcolumn_iter). - Individual rows and columns of mutable entries (see
row_iter_mutandcolumn_iter_mut). - All rows or all columns (see
rows_iterandcolumns_iter). - All rows or all columns of mutable entries (see
rows_iter_mutandcolumns_iter_mut).
Extracting all data from a Vecgrid
A Vecgrid can be converted back into a Vec through several
methods. You can extract the data as:
- A
Vecof rows or columns (seeas_rowsandas_columns). - A "flat"
Vecof elements in either row major or column major order (seeas_row_majorandas_column_major).
Examples
use ;
Acknowledgement
This library is made possible thanks to the excellent groundwork laid down in Array2D by author HarrisonMc555, as well as contributor to the upstream project tylerjw. Array2D has been published under the MIT license.
License: MIT