xwrust::xwbmp

Struct Bmp

source
pub struct Bmp<const N: XwSz>
where [XwBmp; { _ }]: Sized,
{ /* private fields */ }
Expand description

位图类型

常数 N 表示有多少位。

Implementations§

source§

impl<const N: XwSz> Bmp<N>
where [XwBmp; { _ }]: Sized,

source

pub const fn new() -> Self

新建位图

此方法是编译期方法。

§示例
  • 具有 'static 约束的全局变量全局变量:
use xwrust::xwbmp::*;

static GLOBAL_BMP = Bmp::<8>::new();
  • 在函数中创建:
extern crate alloc;
use alloc::sync::Arc;
use xwrust::xwbmp::*;

pub fn some_function() {
    let msk = Bmp::<8>::new();
}
  • 在heap上创建:
extern crate alloc;
use alloc::sync::Arc;
use xwrust::xwbmp::*;

pub fn some_function() {
    let msk = Arc::new(Bmp::<8>::new());
}
source

pub const fn bits(&self) -> XwSz

获取位图位的数量

source

pub fn weight(&self) -> XwSz

在位图中统计被置 1 的位的个数

source

pub fn s1all(&self)

将位图中所有位置 1

source

pub fn c0all(&self)

将位图中所有位清 0

source

pub fn s1i(&self, n: XwSq)

将位图中单个位置 1

source

pub fn s1m(&self, msk: &Self)

将位图中掩码部分置 1

source

pub fn c0i(&self, n: XwSq)

将位图中单个位清 0

source

pub fn c0m(&self, msk: &Self)

将位图中掩码部分清 0

source

pub fn x1i(&self, n: XwSq)

将位图中单个位翻转

source

pub fn x1m(&self, msk: &Self)

将位图中掩码部分翻转

source

pub fn t1i(&self, n: XwSq) -> bool

测试位图中的单个位是否为 1

source

pub fn t1ma(&self, msk: &Self) -> bool

测试位图中掩码部分是否全部为 1

source

pub fn t1mo(&self, msk: &Self) -> bool

测试位图中掩码部分是否至少有一位为 1

source

pub fn t1ma_then_c0m(&self, msk: &Self) -> bool

测试位图中掩码部分是否全部为 1 ,如果是,就将掩码部分全部清 0

source

pub fn t1mo_then_c0m(&self, msk: &Self) -> bool

测试位图中掩码部分是否至少有一位为 1 ,如果是,就将掩码部分全部清 0

source

pub fn t0ma_then_s1m(&self, msk: &Self) -> bool

测试位图中掩码部分是否全部为 0 ,如果是,就将掩码部分全部置 1

source

pub fn t0mo_then_s1m(&self, msk: &Self) -> bool

测试位图中掩码部分是否至少有一位为 0 ,如果是,就将掩码部分全部置 1

source

pub fn ffs(&self) -> XwSsq

在位图中从最低位起查找第一个被置 1 的位

source

pub fn ffz(&self) -> XwSsq

在位图中从最低位起查找第一个被清 0 的位

source

pub fn fls(&self) -> XwSsq

在位图中从最高位起查找第一个被置 1 的位

source

pub fn flz(&self) -> XwSsq

在位图中从最高位起查找第一个被清 0 的位

Trait Implementations§

source§

impl<const N: XwSz> BitAnd for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

type Output = Bmp<N>

The resulting type after applying the & operator.
source§

fn bitand(self, other: Self) -> Self

Performs the & operation. Read more
source§

impl<const N: XwSz> BitAndAssign for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

fn bitand_assign(&mut self, other: Self)

Performs the &= operation. Read more
source§

impl<const N: XwSz> BitOr for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

type Output = Bmp<N>

The resulting type after applying the | operator.
source§

fn bitor(self, other: Self) -> Self

Performs the | operation. Read more
source§

impl<const N: XwSz> BitOrAssign for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

fn bitor_assign(&mut self, other: Self)

Performs the |= operation. Read more
source§

impl<const N: XwSz> BitXor for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

type Output = Bmp<N>

The resulting type after applying the ^ operator.
source§

fn bitxor(self, other: Self) -> Self

Performs the ^ operation. Read more
source§

impl<const N: XwSz> BitXorAssign for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

fn bitxor_assign(&mut self, other: Self)

Performs the ^= operation. Read more
source§

impl<const N: XwSz> Debug for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

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

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

impl<const N: XwSz> Neg for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

type Output = Bmp<N>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self

Performs the unary - operation. Read more
source§

impl<const N: XwSz> PartialEq for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

fn eq(&self, other: &Self) -> bool

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

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<const N: XwSz> PartialOrd for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

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

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

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

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§

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

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

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<const N: XwSz> Send for Bmp<N>
where [XwBmp; { _ }]: Sized,

source§

impl<const N: XwSz> Sync for Bmp<N>
where [XwBmp; { _ }]: Sized,

Auto Trait Implementations§

§

impl<const N: usize> !Freeze for Bmp<N>

§

impl<const N: usize> !RefUnwindSafe for Bmp<N>

§

impl<const N: usize> Unpin for Bmp<N>
where [usize; { _ }]: Sized,

§

impl<const N: usize> UnwindSafe for Bmp<N>
where [usize; { _ }]: Sized,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.