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 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.insert_index(4, 'i');
grid.insert([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);


A sparse grid that stores elements in a BTreeMap.