Trait bv::BlockType [−][src]
Interface to primitive bit storage.
Types implementing this trait can be used as the blocks of a bit-vector.
Required methods
fn wrapping_shl(self, shift: u32) -> Self
[src]
A shift-left operation that does not overflow.
fn wrapping_sub(self, other: Self) -> Self
[src]
A subtraction operation that does not overflow.
fn leading_zeros(self) -> usize
[src]
Returns the number of leading zero bits in the given number.
fn to_usize(self) -> Option<usize>
[src]
Converts the number to a usize
, if it fits.
fn zero() -> Self
[src]
Returns 0.
fn one() -> Self
[src]
Returns 1.
Provided methods
fn nbits() -> usize
[src]
The number of bits in a block.
fn div_nbits(index: u64) -> usize
[src]
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.
fn checked_div_nbits(index: u64) -> Option<usize>
[src]
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.
fn ceil_div_nbits(index: u64) -> usize
[src]
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
.
fn checked_ceil_div_nbits(index: u64) -> Option<usize>
[src]
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.
fn mod_nbits(index: u64) -> usize
[src]
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
.
fn mul_nbits(index: usize) -> u64
[src]
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
.
fn block_bits(len: u64, position: usize) -> usize
[src]
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.
fn lg_nbits() -> usize
[src]
Log-base-2 of the number of bits in a block.
fn lg_nbits_mask<Result: BlockType>() -> Result
[src]
Mask with the lowest-order lg_nbits()
set.
fn low_mask(element_bits: usize) -> Self
[src]
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()
fn nth_mask(bit_index: usize) -> Self
[src]
The bit mask with the bit_index
th bit set.
Bits are indexed in little-endian style based at 0.
Precondition
bit_index < Self::nbits()
fn get_bit(self, bit_index: usize) -> bool
[src]
fn with_bit(self, bit_index: usize, bit_value: bool) -> Self
[src]
Functionally updates the value of the bit_index
th bit to bit_value
.
Panics
Panics if bit_index
is out of bounds.
fn get_bits(self, start: usize, len: usize) -> Self
[src]
fn with_bits(self, start: usize, len: usize, value: Self) -> Self
[src]
Functionally updates len
bits to value
starting at offset start
.
Panics
Panics of the bit span is out of bounds.
fn ceil_lg(self) -> usize
[src]
Returns the smallest number n
such that 2.pow(n) >= self
.
fn floor_lg(self) -> usize
[src]
Returns the largest number n
such that 2.pow(n) <= self
.