block-grid
A quick, cache-conscious, blocked 2D array
block-grid gives you a fixed size, two-dimensional array, with a blocked memory representation. This has the sweet benefit of being much more cache-friendly if you're often accessing nearby coordinates.
This library works and is stable, and will not be worked on actively. I am more than happy to review PRs if there's a need :)
Features
- Can store any type
- Generic compile-time block sizes
- Indexing with
(row, col): (usize, usize) - Block level access with
BlockandBlockMut - Constructors from row-major and column-major order arrays
- Iterators for in-memory and row-major order, and by block
no_stdandserdesupport- Also supports no blocks (i.e. classic row-major)
Example
use ;
Why
TODO: Stuff about caches
Trade-offs
- Non-resizable, and grid dimensions have to be a multiple of the block size.
- Currently, only square blocks, and power-of-two block sizes are supported.
- Computing the modified index takes just a bit more time.
- There are still cache misses when you cross tile boundaries.
- No support for strides or general subsets.
Changelog
See CHANGELOG.md.
License
block-grid is licensed under the MIT license.
Alternatives
If your access patterns suit a typical row-major memory representation, you can still use block-grid! If you truly desire alternatives, however, check out array2d, imgref, grid, or toodee. The last two support dynamic resizing. For matrices and linear algebra, there's also nalgebra.