Struct bv::BitSlice[][src]

pub struct BitSlice<'a, Block> { /* fields omitted */ }

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 );

Methods

impl<'a, Block: BlockType> BitSlice<'a, Block>
[src]

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 );

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.

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 );

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

impl<'a, Block: Copy> Copy for BitSlice<'a, Block>
[src]

impl<'a, Block: Clone> Clone for BitSlice<'a, Block>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

Performs the conversion.

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

Performs the conversion.

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

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

The length of the slice in bits.

Gets the bit at position Read more

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

Gets the block at position, without masking. Read more

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

The length of the slice in blocks.

Copies the bits into a new allocated [BitVec]. Read more

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

The returned type after indexing.

Performs the indexing (container[index]) operation.

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

The type of the slice produced.

Slices or re-slices the given object. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

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

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

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

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