[−][src]Trait succinct::storage::BlockType
Types that can be used for IntVector
and BitVector
storage.
This trait is kind of a grab bag of methods right now. It includes:
- methods for computing sizes and offsets relative to the block size,
- methods for getting and setting individual and groups of bits,
- a method for computing rank,
- three arithmetic methods that probably belong elsewhere, and
- block-based, endian-specified I/O.
Required methods
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
R: Read,
T: ByteOrder,
Reads a block with the specified endianness.
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
W: Write,
T: ByteOrder,
Writes a block with the specified endianness.
Provided methods
fn nbits() -> usize
The number of bits in a block.
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.
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
.
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
.
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.
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
.
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
.
fn last_block_bits(len: u64) -> usize
Computes how many bits are in the last block of an array of
len
bits.
This is like Self::mod_nbits
, but it returns Self::nbits()
in
lieu of 0. Note that this means that if you have 0 bits then the
last block is full.
fn lg_nbits() -> usize
Log-base-2 of the number of bits in a block.
fn lg_nbits_mask<Result: BlockType>() -> Result
Mask with the lowest-order lg_nbits()
set.
fn low_mask(element_bits: usize) -> Self
The bit mask consisting of Self::nbits() - element_bits
zeroes
followed by element_bits
ones.
Precondition
element_bits <= Self::nbits()
fn nth_mask(bit_index: usize) -> Self
The bit mask with the bit_index
th bit set.
BitVec are index in little-endian style based at 0.
Precondition
bit_index < Self::nbits()
fn get_bit(self, bit_index: usize) -> bool
fn with_bit(self, bit_index: usize, bit_value: bool) -> Self
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
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.
fn ceil_lg(self) -> usize
Returns the smallest number n
such that 2.pow(n) >= self
.
fn floor_lg(self) -> usize
Returns the largest number n
such that 2.pow(n) <= self
.
fn ceil_div(self, divisor: Self) -> Self
Returns the smallest number n
such that n * divisor >= self
.
Implementations on Foreign Types
impl BlockType for u8
[src]
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
[src]
R: Read,
T: ByteOrder,
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
[src]
W: Write,
T: ByteOrder,
fn low_mask(k: usize) -> u8
[src]
impl BlockType for u16
[src]
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
[src]
R: Read,
T: ByteOrder,
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
[src]
W: Write,
T: ByteOrder,
fn low_mask(k: usize) -> u16
[src]
impl BlockType for u32
[src]
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
[src]
R: Read,
T: ByteOrder,
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
[src]
W: Write,
T: ByteOrder,
fn low_mask(k: usize) -> u32
[src]
impl BlockType for u64
[src]
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
[src]
R: Read,
T: ByteOrder,
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
[src]
W: Write,
T: ByteOrder,
fn low_mask(k: usize) -> u64
[src]
impl BlockType for usize
[src]
fn read_block<R, T>(source: &mut R) -> Result<Self> where
R: Read,
T: ByteOrder,
[src]
R: Read,
T: ByteOrder,
fn write_block<W, T>(&self, sink: &mut W) -> Result<()> where
W: Write,
T: ByteOrder,
[src]
W: Write,
T: ByteOrder,