pub struct Gridbool<const WIDTH: u16, const HEIGHT: u16, const WORDS: usize>(/* private fields */);Expand description
Space-optimized grid of booleans using bitmaps
Gridbool uses an array of u32 to implement a Qa-indexable
grid of booleans, balancing space and performance.
At the moment we need to provide the number of u32 WORDS to use due to rust generic const limitations. We are able to check that the value is appropriate, though.
We can use the gridbool_create macro to use a Qa as a
source of these values.
Implementations§
source§impl<const W: u16, const H: u16, const WORDS: usize> Gridbool<W, H, WORDS>
impl<const W: u16, const H: u16, const WORDS: usize> Gridbool<W, H, WORDS>
sourcepub fn set(&mut self, qaref: impl Borrow<Qa<W, H>>, value: bool)
pub fn set(&mut self, qaref: impl Borrow<Qa<W, H>>, value: bool)
Set the provided Qa position to value.
sourcepub fn into_inner(self) -> [u32; WORDS]
pub fn into_inner(self) -> [u32; WORDS]
Consume self and returns the inner bitmap.
sourcepub fn as_inner(&self) -> &[u32; WORDS]
pub fn as_inner(&self) -> &[u32; WORDS]
Return a reference to the inner bitmap; useful for testing.
sourcepub fn as_inner_mut(&mut self) -> &mut [u32; WORDS]
pub fn as_inner_mut(&mut self) -> &mut [u32; WORDS]
Return a mut reference to the inner bitmap; useful for testing.
sourcepub fn iter(&self) -> impl Iterator<Item = bool> + '_
pub fn iter(&self) -> impl Iterator<Item = bool> + '_
Iterate over all true/false values in the Gridbool.
sourcepub fn iter_qa(&self) -> impl Iterator<Item = (Qa<W, H>, bool)> + '_
pub fn iter_qa(&self) -> impl Iterator<Item = (Qa<W, H>, bool)> + '_
Iterate over all coordinates and corresponding true/false values.
sourcepub fn iter_t(&self) -> impl Iterator<Item = Qa<W, H>> + '_
pub fn iter_t(&self) -> impl Iterator<Item = Qa<W, H>> + '_
Iterate over all true coordinates the Gridbool.
sourcepub fn iter_f(&self) -> impl Iterator<Item = Qa<W, H>> + '_
pub fn iter_f(&self) -> impl Iterator<Item = Qa<W, H>> + '_
Iterate over all false coordinates the Gridbool.
sourcepub fn set_iter_t<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
pub fn set_iter_t<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
Take a Qa iterator and set all corresponding values to true.
sourcepub fn set_iter_f<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
pub fn set_iter_f<AQA>(&mut self, qaiter: impl Iterator<Item = AQA>)
Take a Qa iterator and set all corresponding values to false.