Trait bitmap32::BitBlock

source ·
pub unsafe trait BitBlock: Copy + Not<Output = Self> + BitOr<Output = Self> + BitOrAssign + BitAndAssign + BitAnd<Output = Self> + Ord {
    const BITS: usize;
    const ZERO: Self;
    const UPSTREAM_ONE: Self;

    // Required methods
    fn wrapping_shift_downstream(self, n: usize) -> Self;
    fn wrapping_shift_upstream(self, n: usize) -> Self;
    fn leading_zeros(self) -> usize;
    fn leading_ones(self) -> usize;

    // Provided methods
    fn get_block_index(idx: usize) -> usize { ... }
    fn bit_index_from_block_index(idx: usize) -> usize { ... }
    fn wrapping_test_bit(self, idx: usize) -> bool { ... }
    fn wrapping_with_bit(self, idx: usize) -> Self { ... }
    fn wrapping_without_bit(self, idx: usize) -> Self { ... }
    fn ones_mask(position: usize, length: NonZeroUsize) -> Self { ... }
}
Expand description

Represents a copyable container of bits (usually an unsigned integer).

Safety

  • Self::ZERO must be core::mem::zeroed().
  • 2^BITS_LOG2 must be equal to BITS.
  • The provided methods can only be overridden with equivalent methods.

Required Associated Constants§

source

const BITS: usize

Represents the number of bits in a block. It is generally a good idea for this number to be a power of two.

source

const ZERO: Self

source

const UPSTREAM_ONE: Self

As of now, this value is not 1 for unsigned integers UPSTREAM_ONE.wrapping_shift_upstream(1) should be 0. For example, for u8, this value is 0x80 (0b10000000).

Required Methods§

source

fn wrapping_shift_downstream(self, n: usize) -> Self

Shifts self n bits in the indexing direction.

source

fn wrapping_shift_upstream(self, n: usize) -> Self

Shifts self n bits against the indexing direction.

source

fn leading_zeros(self) -> usize

Gets the leading zeros in the indexing direction.

source

fn leading_ones(self) -> usize

Gets the leading ones in the indexing direction.

Provided Methods§

source

fn get_block_index(idx: usize) -> usize

Returns the index of the block holding the bit at the specified location in a collection (eg. for a u8, get_block_index(9) == 2).

source

fn bit_index_from_block_index(idx: usize) -> usize

Returns the index of the first bit in the block at idx..

source

fn wrapping_test_bit(self, idx: usize) -> bool

Returns true if the bit at idx is 1.

source

fn wrapping_with_bit(self, idx: usize) -> Self

Returns self with the bit at idx set to 1.

source

fn wrapping_without_bit(self, idx: usize) -> Self

Returns self with the bit at idx set to 0.

source

fn ones_mask(position: usize, length: NonZeroUsize) -> Self

Returns a bit mask of ones at position (wrapped) with a length of length (saturated).

Example
assert_eq!(u8::ones_mask(2, NonZeroUsize::new(3).unwrap()), 0b00111000);
assert_eq!(u8::ones_mask(6, NonZeroUsize::new(10).unwrap()), 0b00000011);
assert_eq!(u8::ones_mask(12, NonZeroUsize::new(2).unwrap()), 0b00001100);

Implementations on Foreign Types§

source§

impl BitBlock for u16

source§

const ZERO: Self = 0u16

source§

const BITS: usize = 16usize

source§

const UPSTREAM_ONE: Self = 32_768u16

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

source§

impl BitBlock for u64

source§

const ZERO: Self = 0u64

source§

const BITS: usize = 64usize

source§

const UPSTREAM_ONE: Self = 9_223_372_036_854_775_808u64

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

source§

impl BitBlock for u8

source§

const ZERO: Self = 0u8

source§

const BITS: usize = 8usize

source§

const UPSTREAM_ONE: Self = 128u8

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

source§

impl BitBlock for usize

source§

const ZERO: Self = 0usize

source§

const BITS: usize = 64usize

source§

const UPSTREAM_ONE: Self = 9_223_372_036_854_775_808usize

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

source§

impl BitBlock for u128

source§

const ZERO: Self = 0u128

source§

const BITS: usize = 128usize

source§

const UPSTREAM_ONE: Self = 170_141_183_460_469_231_731_687_303_715_884_105_728u128

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

source§

impl BitBlock for u32

source§

const ZERO: Self = 0u32

source§

const BITS: usize = 32usize

source§

const UPSTREAM_ONE: Self = 2_147_483_648u32

source§

fn wrapping_shift_downstream(self, n: usize) -> Self

source§

fn wrapping_shift_upstream(self, n: usize) -> Self

source§

fn leading_zeros(self) -> usize

source§

fn leading_ones(self) -> usize

Implementors§

source§

impl BitBlock for LE<u8>

source§

const ZERO: Self = _

source§

const UPSTREAM_ONE: Self = _

source§

const BITS: usize = 8usize

source§

impl BitBlock for LE<u16>

source§

const ZERO: Self = _

source§

const UPSTREAM_ONE: Self = _

source§

const BITS: usize = 16usize

source§

impl BitBlock for LE<u32>

source§

const ZERO: Self = _

source§

const UPSTREAM_ONE: Self = _

source§

const BITS: usize = 32usize

source§

impl BitBlock for LE<u64>

source§

const ZERO: Self = _

source§

const UPSTREAM_ONE: Self = _

source§

const BITS: usize = 64usize

source§

impl BitBlock for LE<u128>

source§

const ZERO: Self = _

source§

const UPSTREAM_ONE: Self = _

source§

const BITS: usize = 128usize