Module sark_grids::sparse_grid

source ·
Expand description

A grid that stores it’s internal data in a BTreeMap. Elements don’t take up any memory until they’re inserted, and can be removed as needed, but iteration and access speed will be slower than a crate::grid::Grid for large full grids.

Elements can be inserted and accessed via their 1d index or 2d index, or read/modified via iterators.


use sark_grids::sparse_grid::SparseGrid;

let mut grid = SparseGrid::new([10,10]);

grid[4] = 'i';
grid[[3,0]]= 'h';

assert_eq!(2, grid.len());

let hi: String = grid.iter_values().collect();
assert_eq!("hi", hi);

grid.insert_row_at([3,0], "ih".chars());
let ih: String = grid.iter_values().collect();

assert_eq!("ih", ih);