Struct BitSlice

Source
pub struct BitSlice<'a, Block> { /* private fields */ }
Expand description

A slice of a bit-vector; akin to &'a [bool] but packed.

§Examples

use bv::*;

let array = [0b00110101u16];
let mut slice = array.bit_slice(..8);
assert_eq!( slice[0], true );
assert_eq!( slice[1], false );

slice = slice.bit_slice(1..8);
assert_eq!( slice[0], false );
assert_eq!( slice[1], true );

Implementations§

Source§

impl<'a, Block: BlockType> BitSlice<'a, Block>

Source

pub fn from_slice(blocks: &'a [Block]) -> Self

Creates a BitSlice from an array slice of blocks.

The size is always a multiple of Block::nbits(). If you want a different size, slice.

§Examples
use bv::{BitSlice, BitSliceable};

let v = vec![0b01010011u16, 0u16];
let slice = BitSlice::from_slice(&v).bit_slice(..7);
assert_eq!( slice.len(), 7 );
assert_eq!( slice[0], true );
assert_eq!( slice[1], true );
assert_eq!( slice[2], false );
Source

pub unsafe fn from_raw_parts(bits: *const Block, offset: u64, len: u64) -> Self

Creates a BitSlice from a pointer to its data, an offset where the bits start, and the number of available bits.

This is unsafe because the size of the passed-in buffer is not checked. It must hold at least offset + len bits or the resulting behavior is undefined.

§Precondition
  • the first Block::ceil_div_nbits(len + offset) words of bits safe to read.
Source

pub fn len(&self) -> u64

The number of bits in the slice.

§Examples
use bv::*;

let bv: BitVec = bit_vec![ true, true, false, true ];
let slice = bv.bit_slice(..3);

assert_eq!( bv.len(), 4 );
assert_eq!( slice.len(), 3 );
Source

pub fn is_empty(&self) -> bool

Returns whether there are no bits in the slice.

§Examples
use bv::*;

let bv: BitVec = bit_vec![ true, true, false, true ];
let slice0 = bv.bit_slice(3..3);
let slice1 = bv.bit_slice(3..4);

assert!(  slice0.is_empty() );
assert!( !slice1.is_empty() );

Trait Implementations§

Source§

impl<'a, Block: BlockType> BitSliceable<Range<u64>> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, range: Range<u64>) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> BitSliceable<RangeFrom<u64>> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, range: RangeFrom<u64>) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> BitSliceable<RangeFull> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, _: RangeFull) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> BitSliceable<RangeInclusive<u64>> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, range: RangeInclusive<u64>) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> BitSliceable<RangeTo<u64>> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, range: RangeTo<u64>) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> BitSliceable<RangeToInclusive<u64>> for BitSlice<'a, Block>

Source§

type Slice = BitSlice<'a, Block>

The type of the slice produced.
Source§

fn bit_slice(self, range: RangeToInclusive<u64>) -> Self

Slices or re-slices the given object. Read more
Source§

impl<'a, Block: BlockType> Bits for BitSlice<'a, Block>

Source§

type Block = Block

The underlying block type used to store the bits of the vector.
Source§

fn bit_len(&self) -> u64

The length of the slice in bits.
Source§

fn get_bit(&self, position: u64) -> bool

Gets the bit at position Read more
Source§

fn get_block(&self, position: usize) -> Block

Gets the block at position, masked as necessary. Read more
Source§

fn get_raw_block(&self, position: usize) -> Block

Gets the block at position, without masking. Read more
Source§

fn get_bits(&self, start: u64, count: usize) -> Self::Block

Gets count bits starting at bit index start, interpreted as a little-endian integer. Read more
Source§

fn block_len(&self) -> usize

The length of the slice in blocks.
Source§

fn to_bit_vec(&self) -> BitVec<Self::Block>

Copies the bits into a new allocated BitVec.
Source§

impl<'a, Block: Clone> Clone for BitSlice<'a, Block>

Source§

fn clone(&self) -> BitSlice<'a, Block>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, Block: BlockType> Debug for BitSlice<'a, Block>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, Block: BlockType> From<&'a [Block]> for BitSlice<'a, Block>

Source§

fn from(slice: &'a [Block]) -> Self

Converts to this type from the input type.
Source§

impl<'a, 'b, Block: BlockType> From<&'b BitSliceMut<'a, Block>> for BitSlice<'a, Block>

Source§

fn from(slice: &'b BitSliceMut<'a, Block>) -> Self

Converts to this type from the input type.
Source§

impl<'a, Block: BlockType + Hash> Hash for BitSlice<'a, Block>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, Block: BlockType> Index<u64> for BitSlice<'a, Block>

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, index: u64) -> &bool

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a, Block: BlockType> Ord for BitSlice<'a, Block>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'a, Other: Bits> PartialEq<Other> for BitSlice<'a, Other::Block>

Source§

fn eq(&self, other: &Other) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, Block: BlockType> PartialOrd for BitSlice<'a, Block>

Source§

fn partial_cmp(&self, other: &BitSlice<'_, Block>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'a, Block: Copy> Copy for BitSlice<'a, Block>

Source§

impl<'a, Block: BlockType> Eq for BitSlice<'a, Block>

Auto Trait Implementations§

§

impl<'a, Block> Freeze for BitSlice<'a, Block>

§

impl<'a, Block> RefUnwindSafe for BitSlice<'a, Block>
where Block: RefUnwindSafe,

§

impl<'a, Block> !Send for BitSlice<'a, Block>

§

impl<'a, Block> !Sync for BitSlice<'a, Block>

§

impl<'a, Block> Unpin for BitSlice<'a, Block>

§

impl<'a, Block> UnwindSafe for BitSlice<'a, Block>
where Block: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> BitsExt for T
where T: Bits,

Source§

fn bit_concat<Other>(&self, other: Other) -> BitConcat<&Self, Other>
where Other: Bits<Block = Self::Block>,

Concatenates two bit vectors, with the bits of self followed by the bits of other.
Source§

fn into_bit_concat<Other>(self, other: Other) -> BitConcat<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Concatenates two bit vectors, with the bits of self followed by the bits of other. Read more
Source§

fn bit_pad(&self, len: u64) -> BitConcat<&Self, BitFill<Self::Block>>

Pads self with 0s on the right to reach at least len bits in length. Read more
Source§

fn into_bit_pad(self, len: u64) -> BitConcat<Self, BitFill<Self::Block>>
where Self: Sized,

Pads self with 0s on the right to reach at least len bits in length. Read more
Source§

fn bit_not(&self) -> BitNot<&Self>

Returns an object that inverts the values of all the bits in self.
Source§

fn into_bit_not(self) -> BitNot<Self>
where Self: Sized,

Returns an object that inverts the values of all the bits in self. Read more
Source§

fn bit_and<Other>(&self, other: Other) -> BitAnd<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise conjunction of two bit-vector-likes. Read more
Source§

fn into_bit_and<Other>(self, other: Other) -> BitAnd<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise conjunction of two bit-vector-likes. Read more
Source§

fn bit_or<Other>(&self, other: Other) -> BitOr<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise disjunction of two bit-vector-likes. Read more
Source§

fn into_bit_or<Other>(self, other: Other) -> BitOr<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise disjunction of two bit-vector-likes. Read more
Source§

fn bit_xor<Other>(&self, other: Other) -> BitXor<&Self, Other>
where Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise xor of two bit-vector-likes. Read more
Source§

fn into_bit_xor<Other>(self, other: Other) -> BitXor<Self, Other>
where Self: Sized, Other: Bits<Block = Self::Block>,

Returns an object that lazily computes the bit-wise xor of two bit-vector-likes. Read more
Source§

fn bit_zip<Other, F>(&self, other: Other, fun: F) -> BitZip<&Self, Other, F>
where Other: Bits<Block = Self::Block>, F: Fn(Self::Block, Self::Block, usize) -> Self::Block,

Returns an object that lazily zips a function over the blocks of two bit-vector-like. Read more
Source§

fn into_bit_zip<Other, F>(self, other: Other, fun: F) -> BitZip<Self, Other, F>
where Self: Sized, Other: Bits<Block = Self::Block>, F: Fn(Self::Block, Self::Block, usize) -> Self::Block,

Returns an object that lazily zips a function over the blocks of two bit-vector-like. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.