Trait BlockType

Source
pub trait BlockType:
    Copy
    + PartialEq
    + Ord
    + BitAnd<Output = Self>
    + BitOr<Output = Self>
    + BitXor<Output = Self>
    + Not<Output = Self>
    + Shl<usize, Output = Self>
    + Shr<usize, Output = Self>
    + Sub<Output = Self> {
Show 24 methods // Required methods fn wrapping_shl(self, shift: u32) -> Self; fn wrapping_sub(self, other: Self) -> Self; fn leading_zeros(self) -> usize; fn to_usize(self) -> Option<usize>; fn zero() -> Self; fn one() -> Self; // Provided methods fn nbits() -> usize { ... } fn div_nbits(index: u64) -> usize { ... } fn checked_div_nbits(index: u64) -> Option<usize> { ... } fn ceil_div_nbits(index: u64) -> usize { ... } fn checked_ceil_div_nbits(index: u64) -> Option<usize> { ... } fn mod_nbits(index: u64) -> usize { ... } fn mul_nbits(index: usize) -> u64 { ... } fn block_bits(len: u64, position: usize) -> usize { ... } fn lg_nbits() -> usize { ... } fn lg_nbits_mask<Result: BlockType>() -> Result { ... } fn low_mask(element_bits: usize) -> Self { ... } fn nth_mask(bit_index: usize) -> Self { ... } fn get_bit(self, bit_index: usize) -> bool { ... } fn with_bit(self, bit_index: usize, bit_value: bool) -> Self { ... } fn get_bits(self, start: usize, len: usize) -> Self { ... } fn with_bits(self, start: usize, len: usize, value: Self) -> Self { ... } fn ceil_lg(self) -> usize { ... } fn floor_lg(self) -> usize { ... }
}
Expand description

Interface to primitive bit storage.

Types implementing this trait can be used as the blocks of a bit-vector.

Required Methods§

Source

fn wrapping_shl(self, shift: u32) -> Self

A shift-left operation that does not overflow.

Source

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

A subtraction operation that does not overflow.

Source

fn leading_zeros(self) -> usize

Returns the number of leading zero bits in the given number.

Source

fn to_usize(self) -> Option<usize>

Converts the number to a usize, if it fits.

Source

fn zero() -> Self

Returns 0.

Source

fn one() -> Self

Returns 1.

Provided Methods§

Source

fn nbits() -> usize

The number of bits in a block.

Source

fn div_nbits(index: u64) -> usize

Returns index / Self::nbits(), computed by shifting.

This is intended for converting a bit address into a block address, which is why it takes u64 and returns usize. There is no check that the result actually fits in a usize, so this should only be used when index is already known to be small enough.

Source

fn checked_div_nbits(index: u64) -> Option<usize>

Returns index / Self::nbits(), computed by shifting.

This is intended for converting a bit address into a block address, which is why it takes u64 and returns usize. It can only fail (returning None) if usize is 32 bits.

Source

fn ceil_div_nbits(index: u64) -> usize

Returns index / Self::nbits() rounded up, computed by shifting.

This is intended for converting a bit size into a block size, which is why it takes u64 and returns usize.

Source

fn checked_ceil_div_nbits(index: u64) -> Option<usize>

Returns index / Self::nbits() rounded up, computed by shifting.

This is intended for converting a bit size into a block size, which is why it takes u64 and returns usize. There is no check that the result actually fits in a usize, so this should only be used when index is already known to be small enough.

Source

fn mod_nbits(index: u64) -> usize

Returns index % Self::nbits(), computed by masking.

This is intended for converting a bit address into a bit offset within a block, which is why it takes u64 and returns usize.

Source

fn mul_nbits(index: usize) -> u64

Returns index * Self::nbits(), computed by shifting.

This is intended for converting a block address into a bit address, which is why it takes a usize and returns a u64.

Source

fn block_bits(len: u64, position: usize) -> usize

The number of bits in the block at position, given a total bit length of len.

This will be Self::nbits() for all but the last block, for which it may be less.

§Precondition

position * Self::nbits() <= len, or the block doesn’t exist and the result is undefined.

Source

fn lg_nbits() -> usize

Log-base-2 of the number of bits in a block.

Source

fn lg_nbits_mask<Result: BlockType>() -> Result

Mask with the lowest-order lg_nbits() set.

Source

fn low_mask(element_bits: usize) -> Self

The bit mask consisting of Self::nbits() - element_bits zeroes followed by element_bits ones.

The default implementation has a branch, but should be overrided with a branchless algorithm if possible.

§Precondition

element_bits <= Self::nbits()

Source

fn nth_mask(bit_index: usize) -> Self

The bit mask with the bit_indexth bit set.

Bits are indexed in little-endian style based at 0.

§Precondition

bit_index < Self::nbits()

Source

fn get_bit(self, bit_index: usize) -> bool

Extracts the value of the bit_indexth bit.

§Panics

Panics if bit_index is out of bounds.

Source

fn with_bit(self, bit_index: usize, bit_value: bool) -> Self

Functionally updates the value of the bit_indexth bit to bit_value.

§Panics

Panics if bit_index is out of bounds.

Source

fn get_bits(self, start: usize, len: usize) -> Self

Extracts len bits starting at bit offset start.

§Panics

Panics of the bit span is out of bounds.

Source

fn with_bits(self, start: usize, len: usize, value: Self) -> Self

Functionally updates len bits to value starting at offset start.

§Panics

Panics of the bit span is out of bounds.

Source

fn ceil_lg(self) -> usize

Returns the smallest number n such that 2.pow(n) >= self.

Source

fn floor_lg(self) -> usize

Returns the largest number n such that 2.pow(n) <= self.

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.

Implementations on Foreign Types§

Source§

impl BlockType for u8

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

impl BlockType for u16

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

impl BlockType for u32

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

impl BlockType for u64

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

impl BlockType for u128

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Source§

impl BlockType for usize

Source§

fn low_mask(k: usize) -> Self

Source§

fn wrapping_shl(self, shift: u32) -> Self

Source§

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

Source§

fn leading_zeros(self) -> usize

Source§

fn to_usize(self) -> Option<usize>

Source§

fn zero() -> Self

Source§

fn one() -> Self

Implementors§