[][src]Struct gf::support::bitvec::BitVec

pub struct BitVec { /* fields omitted */ }

Growable bit vector.

Total order

Bit vectors have total order implemented as shortlex order: if two vectors differ in length, the shorter one is less; otherwise, two vectors of equal length compare lexicographically (or, equivalently, as unsigned integers).

Implementations

impl BitVec[src]

pub fn new() -> Self[src]

Create an empty vector.

pub fn new_all_zeros(bit_len: usize) -> Self[src]

Create an all-zero vector of given length.

pub fn new_concat<I>(parts: I) -> Self where
    I: IntoIterator<Item = BitVec>, 
[src]

Create a vector as a concatenation of some parts.

pub fn with_capacity(bit_capacity: usize) -> Self[src]

Create an empty vector with preallocated capacity.

pub fn from_byte_slice(slice: &[u8], endianness: Endianness) -> Self[src]

Create a vector from bytes with given endianness.

Example

assert_eq!(BitVec::from_byte_slice(&[0x12, 0x34], Endianness::Little), 0x3412u16.into());
assert_eq!(BitVec::from_byte_slice(&[0x12, 0x34], Endianness::Big), 0x1234u16.into());

pub fn from_byte_slice_prefix(
    slice: &[u8],
    endianness: Endianness,
    bit_len: usize
) -> Self
[src]

Create a vector from a bit prefix of bytes with given endianness.

Errors

  • Panics if the slice is shorter than the prefix length.

pub fn from_str(src: &str) -> Self[src]

Convert a string slice to a little endian bit vector of its UTF-8 bytes.

pub fn from_str_radix(src: &str, radix: u32) -> Result<Self, ParseBitVecError>[src]

Convert a string slice in a given base to a bit vector.

The resulting vector will have no leading zero bits, meaning that it can be empty if the input is zero.

Errors

  • Panics if radix is not in the range from 2 to 36.

Example

assert_eq!(BitVec::from_str_radix("C001a1D3", 16), Ok(BitVec::from(0xC001_A1D3u32)));
assert_eq!(BitVec::from_str_radix("011010001", 2), Ok(BitVec::from(0xD1u8)));
assert_eq!(BitVec::from_str_radix("0", 10), Ok(BitVec::new()));

pub fn is_empty(&self) -> bool[src]

Return whether the vector is empty.

pub fn len(&self) -> usize[src]

Return bit length of the vector.

pub fn is_all_zeros(&self) -> bool[src]

Check whether the vector has no set bits, i.e. is either empty or has zero value.

pub fn get(&self, bit_index: usize) -> bool[src]

Return bit value at bit_index.

Errors

  • Panics on out-of-bound indexing.

pub fn get_slice<R: RangeBounds<usize>>(&self, bit_range: R) -> BitSlice<'_>[src]

Return slice for bit_range.

Errors

  • Panics on out-of-bound indexing.

pub fn set(&mut self, bit_index: usize, value: bool)[src]

Set bit value at bit_index.

Errors

  • Panics on out-of-bound indexing.

pub fn push(&mut self, value: bool)[src]

Push a bit at the end of the vector.

pub fn append(&mut self, src: &Self)[src]

Append a vector at the end of this one.

pub fn as_bit_slice(&self) -> BitSlice<'_>[src]

Borrow the vector as an immutable bit slice.

pub fn as_byte_slice(&self) -> &[u8][src]

Borrow the vector as an immutable byte slice in little endian order.

The slice may have extra zero bits at the end, padding it up to a whole byte.

pub fn to_byte_vec(&self, endianness: Endianness) -> Cow<'_, [u8]>[src]

Convert the vector to a byte vector with given endianness.

The vector may have extra zero bits at the end, padding it up to a whole byte.

pub fn as_str(&self) -> Result<&str, Utf8Error>[src]

Borrow the vector as a string slice.

pub fn cast_into<T: CastFromBitVec>(self) -> Result<T, CastFromBitVecError>[src]

Cast the vector into an integer type.

pub fn resize(&mut self, new_bit_len: usize, signedness: Signedness)[src]

Truncate or extend the vector in place using given signedness.

pub fn resized(&self, new_bit_len: usize, signedness: Signedness) -> Self[src]

Return a truncated or extended vector using given signedness.

pub fn truncate(&mut self, min_bit_len: usize, signedness: Signedness)[src]

Remove duplicate leading bits in place using given signedness, stopping when length becomes less than or equal to min_bit_len.

The resulting vector will be empty if the original vector had only zero bits.

pub fn limbs<'a>(&'a self) -> impl Iterator<Item = u128> + 'a[src]

Return an iterator over the 128-bit limbs of the vector in little endian order.

Unused bits in the most significant limb are always zero.

pub fn limbs_rev<'a>(&'a self) -> impl Iterator<Item = u128> + 'a[src]

Return an iterator over the 128-bit limbs of the vector in big endian order.

Unused bits in the most significant limb are always zero.

pub fn from_big_int(src: &BigInt, len: usize) -> Self[src]

Convert from num_bigint::BigInt, resizing to the given number of bits.

pub fn from_big_uint(src: &BigUint, len: usize) -> Self[src]

Convert from num_bigint::BigUint, resizing to the giving number of bits.

pub fn from_big_uint_shortest(src: &BigUint) -> Self[src]

Convert from num_bigint::BigUint, using the minimum possible number of bits.

This method returns an empty vector when src is zero.

pub fn to_big_int(&self) -> BigInt[src]

Convert to num_bigint::BigInt, treating the value as signed.

pub fn to_big_uint(&self) -> BigUint[src]

Convert to num_bigint::BigUint, treating the value as unsigned.

Trait Implementations

impl Binary for BitVec[src]

impl BitSeq for BitVec[src]

impl BitSeqMut for BitVec[src]

impl Clone for BitVec[src]

impl ConstSpaceState<BitVec, FlatLattice<BitVec>> for ConcreteSpaceState[src]

impl ConstSpaceState<BitVec, FlatLattice<Expr>> for SymbolicSpaceState[src]

impl Debug for BitVec[src]

impl Default for BitVec[src]

impl Display for BitVec[src]

impl Eq for BitVec[src]

impl Extend<bool> for BitVec[src]

impl Extend<u128> for BitVec[src]

impl Extend<u16> for BitVec[src]

impl Extend<u32> for BitVec[src]

impl Extend<u64> for BitVec[src]

impl Extend<u8> for BitVec[src]

impl<'a> From<BitSlice<'a>> for BitVec[src]

impl From<bool> for BitVec[src]

impl From<i128> for BitVec[src]

impl From<i16> for BitVec[src]

impl From<i32> for BitVec[src]

impl From<i64> for BitVec[src]

impl From<i8> for BitVec[src]

impl From<u128> for BitVec[src]

impl From<u16> for BitVec[src]

impl From<u32> for BitVec[src]

impl From<u64> for BitVec[src]

impl From<u8> for BitVec[src]

impl FromIterator<bool> for BitVec[src]

impl FromIterator<u128> for BitVec[src]

impl FromIterator<u16> for BitVec[src]

impl FromIterator<u32> for BitVec[src]

impl FromIterator<u64> for BitVec[src]

impl FromIterator<u8> for BitVec[src]

impl Hash for BitVec[src]

impl Index<usize> for BitVec[src]

type Output = bool

The returned type after indexing.

impl LowerHex for BitVec[src]

impl Ord for BitVec[src]

impl PartialEq<BitVec> for BitVec[src]

impl PartialOrd<BitVec> for BitVec[src]

impl SpaceState<BitVec, FlatLattice<BitVec>> for ConcreteSpaceState[src]

impl SpaceState<BitVec, FlatLattice<Expr>> for SymbolicSpaceState[src]

impl ToBigInt for BitVec[src]

impl ToBigUint for BitVec[src]

impl TryFrom<BitVec> for bool[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for i8[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for u128[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for i16[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for i32[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for i64[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for i128[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for u8[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for u16[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for u32[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl TryFrom<BitVec> for u64[src]

type Error = TryFromBitVecError

The type returned in the event of a conversion error.

impl UpperHex for BitVec[src]

Auto Trait Implementations

impl RefUnwindSafe for BitVec

impl Send for BitVec

impl Sync for BitVec

impl Unpin for BitVec

impl UnwindSafe for BitVec

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.