pub trait Chunk:
Copy
+ Eq
+ Not<Output = Self>
+ BitAnd<Output = Self>
+ BitOr<Output = Self>
+ BitXor<Output = Self>
+ 'static {
const BITS: u32;
const ZERO: Self;
// Required methods
fn mask(bit: u32) -> Self;
fn count_ones(self) -> u32;
fn highest_bit(self) -> u32;
fn lowest_bit(self) -> u32;
fn remove_lowest_bit(&mut self);
}Expand description
块
用于按位压缩存储一些布尔值。
Required Associated Constants§
Required Methods§
Sourcefn mask(bit: u32) -> Self
fn mask(bit: u32) -> Self
单个位
要求输入 bit 小于 Chunk::BITS;输出仅有一位且尾随 bit 个零。
let bit = 5;
let mask = u64::mask(bit);
assert_eq!(mask.count_ones(), 1);
assert_eq!(mask.highest_bit(), bit);
assert_eq!(mask.lowest_bit(), bit);Sourcefn count_ones(self) -> u32
fn count_ones(self) -> u32
计算位的数量
Sourcefn highest_bit(self) -> u32
fn highest_bit(self) -> u32
最前一个 bit
Sourcefn lowest_bit(self) -> u32
fn lowest_bit(self) -> u32
最后一个 bit
Sourcefn remove_lowest_bit(&mut self)
fn remove_lowest_bit(&mut self)
删除最后一位
let c = 15532u64;
let mut c2 = c;
c2.remove_lowest_bit();
assert_eq!(c2, c ^ u64::mask(c.trailing_zeros()));
assert_eq!(c2.count_ones(), c.count_ones() - 1);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.