Struct Gridbool

Source
pub struct Gridbool<P: PosT, const WORDS: usize>(/* private fields */);
Expand description

Space-optimized grid of booleans using bitmaps

Gridbool uses an array of u32 to implement a Pos-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 Pos as a source of these values.

Implementations§

Source§

impl<P: PosT, const WORDS: usize> Gridbool<P, WORDS>

Source

pub const ALL_TRUE: Self

Const Gridbool filled with true values.

Source

pub const ALL_FALSE: Self

Const Gridbool filled with false values.

Source

pub const fn repeat(value: bool) -> Self

Create a Gridbool filled with the provided value.

Source

pub fn set_t(&mut self, posref: &P)

Set the provided Pos position to true.

Source

pub fn set_f(&mut self, posref: &P)

Set the provided Pos position to false.

Source

pub fn set(&mut self, posref: &P, value: bool)

Set the provided Pos position to value.

Source

pub fn get(&self, posref: &P) -> bool

Return the value at position Pos.

Source

pub fn into_inner(self) -> [u32; WORDS]

Consume self and returns the inner bitmap.

Source

pub fn as_inner(&self) -> &[u32; WORDS]

Return a reference to the inner bitmap; useful for testing.

Source

pub fn as_inner_mut(&mut self) -> &mut [u32; WORDS]

Return a mut reference to the inner bitmap; useful for testing.

Source

pub fn iter(&self) -> impl Iterator<Item = bool> + '_

Iterate over all true/false values in the Gridbool.

Source

pub fn iter_pos(&self) -> impl Iterator<Item = (P, bool)> + '_
where P: Copy,

Iterate over all coordinates and corresponding true/false values.

Source

pub fn iter_t(&self) -> impl Iterator<Item = P> + '_

Iterate over all true coordinates the Gridbool.

Source

pub fn iter_f(&self) -> impl Iterator<Item = P> + '_

Iterate over all false coordinates the Gridbool.

Source

pub fn set_iter_t(&mut self, positer: impl Iterator<Item = P>)

Take a Pos iterator and set all corresponding values to true.

Source

pub fn set_iter_f(&mut self, positer: impl Iterator<Item = P>)

Take a Pos iterator and set all corresponding values to false.

Source

pub fn flip_h(&mut self)

Flip all elements horizontally.

Source

pub fn flip_v(&mut self)

Flip all elements vertically.

Source§

impl<const XYMAX: u16, const WORDS: usize> Gridbool<Pos<XYMAX, XYMAX>, WORDS>

Source

pub fn rotate_cw(&mut self)

Rotate all elements 90 degrees clockwise

Source

pub fn rotate_cc(&mut self)

Rotate all elements 90 degrees counterclockwise

Trait Implementations§

Source§

impl<P: Clone + PosT, const WORDS: usize> Clone for Gridbool<P, WORDS>

Source§

fn clone(&self) -> Gridbool<P, WORDS>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: Debug + PosT, const WORDS: usize> Debug for Gridbool<P, WORDS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: PosT, const WORDS: usize> Default for Gridbool<P, WORDS>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<P: PosT, const WORDS: usize> Display for Gridbool<P, WORDS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: PosT, const WORDS: usize> FromIterator<P> for Gridbool<P, WORDS>

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = P>,

Creates a value from an iterator. Read more
Source§

impl<P: PosT, const WORDS: usize> FromIterator<bool> for Gridbool<P, WORDS>

Source§

fn from_iter<I>(iter: I) -> Self
where I: IntoIterator<Item = bool>,

Creates a value from an iterator. Read more
Source§

impl<P: Hash + PosT, const WORDS: usize> Hash for Gridbool<P, WORDS>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<P: PosT, const WORDS: usize> Index<&P> for Gridbool<P, WORDS>

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, pos: &P) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<P: PosT, const WORDS: usize> Index<P> for Gridbool<P, WORDS>

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, pos: P) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<P: Ord + PosT, const WORDS: usize> Ord for Gridbool<P, WORDS>

Source§

fn cmp(&self, other: &Gridbool<P, WORDS>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<P: PartialEq + PosT, const WORDS: usize> PartialEq for Gridbool<P, WORDS>

Source§

fn eq(&self, other: &Gridbool<P, WORDS>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: PartialOrd + PosT, const WORDS: usize> PartialOrd for Gridbool<P, WORDS>

Source§

fn partial_cmp(&self, other: &Gridbool<P, WORDS>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<P: PosT, const WORDS: usize, const SIZE: usize> SetPos<P, WORDS, SIZE> for Gridbool<P, WORDS>

Source§

fn contains(&self, pos: &P) -> bool

Check if the provided super::pos::Pos is in the set
Source§

fn insert(&mut self, pos: P)

Insert the provided super::pos::Pos
Source§

fn remove(&mut self, pos: &P)

Remove the provided super::pos::Pos
Source§

fn set(&mut self, pos: P, add: bool)

Insert or remove the provided super::pos::Pos
Source§

impl<P: Copy + PosT, const WORDS: usize> Copy for Gridbool<P, WORDS>

Source§

impl<P: Eq + PosT, const WORDS: usize> Eq for Gridbool<P, WORDS>

Source§

impl<P: PosT, const WORDS: usize> StructuralPartialEq for Gridbool<P, WORDS>

Auto Trait Implementations§

§

impl<P, const WORDS: usize> Freeze for Gridbool<P, WORDS>

§

impl<P, const WORDS: usize> RefUnwindSafe for Gridbool<P, WORDS>
where P: RefUnwindSafe,

§

impl<P, const WORDS: usize> Send for Gridbool<P, WORDS>
where P: Send,

§

impl<P, const WORDS: usize> Sync for Gridbool<P, WORDS>
where P: Sync,

§

impl<P, const WORDS: usize> Unpin for Gridbool<P, WORDS>
where P: Unpin,

§

impl<P, const WORDS: usize> UnwindSafe for Gridbool<P, WORDS>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.