Skip to main content

BitVec

Struct BitVec 

Source
pub struct BitVec<B = Vec<usize>> { /* private fields */ }
Expand description

A bit vector.

Instances can be created using new, with_value, with the convenience macro bit_vec!, or with a FromIterator implementation.

See the module documentation for more details.

Implementations§

Source§

impl<B> BitVec<B>

Source

pub fn len(&self) -> usize

Returns the number of bits in the bit vector.

This method is equivalent to BitLength::len, but it is provided to reduce ambiguity in method resolution.

Source

pub unsafe fn from_raw_parts(bits: B, len: usize) -> Self

§Safety

len must be between 0 (included) and the number of bits in bits (included).

Source

pub fn into_raw_parts(self) -> (B, usize)

Source

pub unsafe fn map<B2>(self, f: impl FnOnce(B) -> B2) -> BitVec<B2>

Modify the bit vector in place.

§Safety

This is unsafe because it’s the caller’s responsibility to ensure that that the length is compatible with the modified bits.

Source§

impl BitVec<Vec<usize>>

Source

pub fn new(len: usize) -> Self

Creates a new bit vector of length len initialized to false.

Source

pub fn with_value(len: usize, value: bool) -> Self

Creates a new bit vector of length len initialized to value.

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new zero-length bit vector of given capacity.

Note that the capacity will be rounded up to a multiple of the word size.

Source

pub fn capacity(&self) -> usize

Returns the current capacity of this bit vector.

Source

pub fn push(&mut self, b: bool)

Appends a bit to the end of this bit vector.

Source

pub fn pop(&mut self) -> Option<bool>

Removes the last bit from the bit vector and returns it, or None if it is empty.

Source

pub fn resize(&mut self, new_len: usize, value: bool)

Resizes the bit vector in place, extending it with value if it is necessary.

Source§

impl<B: AsRef<[usize]>> BitVec<B>

Source

pub fn to_owned(&self) -> BitVec

Returns an owned copy of the bit vector.

Trait Implementations§

Source§

impl<B> AlignHash for BitVec<B>
where B: SerInner<SerType: AlignHash>, usize: SerInner<SerType: AlignHash>,

Source§

fn align_hash(hasher: &mut impl Hasher, offset_of: &mut usize)

Accumulates alignment information in hasher assuming to be positioned at offset_of.
Source§

fn align_hash_val(&self, hasher: &mut impl Hasher, offset_of: &mut usize)

Calls AlignHash::align_hash on a value.
Source§

impl<W, B: AsMut<[W]>> AsMut<[W]> for BitVec<B>

Source§

fn as_mut(&mut self) -> &mut [W]

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<W, B: AsRef<[W]>> AsRef<[W]> for BitVec<B>

Source§

fn as_ref(&self) -> &[W]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<B: AsRef<[usize]>> BitCount for BitVec<B>

Source§

fn count_ones(&self) -> usize

Returns the number of ones in the underlying bit vector, with a possibly expensive computation; see NumBits::num_ones for constant-time version.
Source§

fn count_zeros(&self) -> usize

Returns the number of zeros in the underlying bit vector, with a possibly expensive computation; see NumBits::num_zeros for constant-time version.
Source§

impl<B> BitLength for BitVec<B>

Source§

fn len(&self) -> usize

Returns a length in bits.
Source§

impl<B: Clone> Clone for BitVec<B>

Source§

fn clone(&self) -> BitVec<B>

Returns a duplicate 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<B> CopyType for BitVec<B>

Source§

impl<B: Debug> Debug for BitVec<B>

Source§

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

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

impl<B> DeserInner for BitVec<B>

Source§

type DeserType<'__epserde_desertype> = BitVec<<B as DeserInner>::DeserType<'__epserde_desertype>>

The deserialization type associated with this type. It can be retrieved conveniently with the alias DeserType.
Source§

fn __check_covariance<'__long: '__short, '__short>( proof: CovariantProof<Self::DeserType<'__long>>, ) -> CovariantProof<Self::DeserType<'__short>>

Internal method for checking the covariance of DeserType. Read more
Source§

unsafe fn _deser_full_inner( backend: &mut impl ReadWithPos, ) -> Result<Self, Error>

Safety Read more
Source§

unsafe fn _deser_eps_inner<'deser_eps_inner_lifetime>( backend: &mut SliceWithPos<'deser_eps_inner_lifetime>, ) -> Result<Self::DeserType<'deser_eps_inner_lifetime>, Error>

Safety Read more
Source§

impl<'de, B> Deserialize<'de> for BitVec<B>
where B: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<B: AsRef<[usize]>> Display for BitVec<B>

Source§

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

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

impl Extend<bool> for BitVec<Vec<usize>>

Source§

fn extend<T>(&mut self, i: T)
where T: IntoIterator<Item = bool>,

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<B> FlatType for BitVec<B>

Source§

impl<'a, W: IntoAtomic> From<AtomicBitVec<&'a [<W as IntoAtomic>::AtomicType]>> for BitVec<&'a [W]>

Source§

fn from(value: AtomicBitVec<&'a [W::AtomicType]>) -> Self

Converts to this type from the input type.
Source§

impl<'a, W: IntoAtomic> From<AtomicBitVec<&'a mut [<W as IntoAtomic>::AtomicType]>> for BitVec<&'a mut [W]>

Source§

fn from(value: AtomicBitVec<&'a mut [W::AtomicType]>) -> Self

Converts to this type from the input type.
Source§

impl<W: IntoAtomic> From<AtomicBitVec<Box<[<W as IntoAtomic>::AtomicType]>>> for BitVec<Box<[W]>>

Source§

fn from(value: AtomicBitVec<Box<[W::AtomicType]>>) -> Self

Converts to this type from the input type.
Source§

impl<W: IntoAtomic> From<AtomicBitVec<Box<[<W as IntoAtomic>::AtomicType]>>> for BitVec<Vec<W>>

Source§

fn from(value: AtomicBitVec<Box<[W::AtomicType]>>) -> Self

Converts to this type from the input type.
Source§

impl<W: IntoAtomic + Copy> From<BitVec<Box<[W]>>> for AtomicBitVec<Box<[W::AtomicType]>>

Source§

fn from(value: BitVec<Box<[W]>>) -> Self

Converts to this type from the input type.
Source§

impl<W> From<BitVec<Box<[W]>>> for BitVec<Vec<W>>

Source§

fn from(value: BitVec<Box<[W]>>) -> Self

Converts to this type from the input type.
Source§

impl<W: IntoAtomic> From<BitVec<Vec<W>>> for AtomicBitVec<Box<[W::AtomicType]>>

Source§

fn from(value: BitVec<Vec<W>>) -> Self

Converts to this type from the input type.
Source§

impl<W> From<BitVec<Vec<W>>> for BitVec<Box<[W]>>

Source§

fn from(value: BitVec<Vec<W>>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<bool> for BitVec<Vec<usize>>

Source§

fn from_iter<T: IntoIterator<Item = bool>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<B: AsRef<[usize]>> Index<usize> for BitVec<B>

Source§

type Output = bool

The returned type after indexing.
Source§

fn index(&self, index: usize) -> &Self::Output

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

impl<'a, B: AsRef<[usize]>> IntoIterator for &'a BitVec<B>

Source§

type IntoIter = BitIter<'a, B>

Which kind of iterator are we turning this into?
Source§

type Item = bool

The type of the elements being iterated over.
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<B> MemDbgImpl for BitVec<B>

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, _memdbg_refs: &mut HashSet<usize>, ) -> Result

Source§

fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ) -> Result<(), Error>

Source§

fn _mem_dbg_depth_on_impl( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ref_display: RefDisplay, ) -> Result<(), Error>

Internal implementation for depth display. Read more
Source§

impl<B> MemSize for BitVec<B>

Source§

fn mem_size_rec( &self, _memsize_flags: SizeFlags, _memsize_refs: &mut HashMap<usize, usize>, ) -> usize

Recursive implementation that tracks visited references for deduplication. Read more
Source§

fn mem_size(&self, flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl<B: AsRef<[usize]>, C: AsRef<[usize]>> PartialEq<BitVec<C>> for BitVec<B>

Source§

fn eq(&self, other: &BitVec<C>) -> 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<B: AsRef<[usize]>> RankHinted<64> for BitVec<B>

Source§

unsafe fn rank_hinted( &self, pos: usize, hint_pos: usize, hint_rank: usize, ) -> usize

Returns the number of ones preceding the specified position, provided a preceding position and its associated rank. Read more
Source§

impl<B: AsRef<[usize]>> SelectHinted for BitVec<B>

Source§

unsafe fn select_hinted( &self, rank: usize, hint_pos: usize, hint_rank: usize, ) -> usize

Selects the one of given rank, provided the position of a preceding one and its rank. Read more
Source§

impl<B: AsRef<[usize]>> SelectZeroHinted for BitVec<B>

Source§

unsafe fn select_zero_hinted( &self, rank: usize, hint_pos: usize, hint_rank: usize, ) -> usize

Selects the zero of given rank, provided the position of a preceding zero and its rank. Read more
Source§

impl<B> SerInner for BitVec<B>
where B: SerInner, usize: SerInner,

Source§

const IS_ZERO_COPY: bool

Inner constant used by the derive macros to keep track recursively of whether the type satisfies the conditions for being zero-copy. It is checked at runtime against the trait implemented by the type, and if a ZeroCopy type has this constant set to false serialization will panic.
Source§

type SerType = BitVec<<B as SerInner>::SerType>

This is the type that will be written in the header of the file, and thus the type that will be deserialized. In most cases it is Self, but in some cases, as for references to slices, it is customized.
Source§

unsafe fn _ser_inner(&self, backend: &mut impl WriteWithNames) -> Result<()>

Serializes this structure using the given backend. Read more
Source§

impl<B> Serialize for BitVec<B>
where B: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'a, W: IntoAtomic> TryFrom<BitVec<&'a [W]>> for AtomicBitVec<&'a [W::AtomicType]>

This conversion may fail if the alignment of W is not the same as that of W::AtomicType.

Source§

type Error = CannotCastToAtomicError<W>

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

fn try_from(value: BitVec<&'a [W]>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a, W: IntoAtomic> TryFrom<BitVec<&'a mut [W]>> for AtomicBitVec<&'a mut [W::AtomicType]>

This conversion may fail if the alignment of W is not the same as that of W::AtomicType.

Source§

type Error = CannotCastToAtomicError<W>

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

fn try_from(value: BitVec<&'a mut [W]>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<B> TypeHash for BitVec<B>
where B: SerInner<SerType: TypeHash>, usize: SerInner<SerType: TypeHash>,

Source§

fn type_hash(hasher: &mut impl Hasher)

Accumulates type information in hasher.
Source§

fn type_hash_val(&self, hasher: &mut impl Hasher)

Calls TypeHash::type_hash on a value.
Source§

impl<B: Copy> Copy for BitVec<B>

Source§

impl<B: AsRef<[usize]>> Eq for BitVec<B>

Auto Trait Implementations§

§

impl<B> Freeze for BitVec<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for BitVec<B>
where B: RefUnwindSafe,

§

impl<B> Send for BitVec<B>
where B: Send,

§

impl<B> Sync for BitVec<B>
where B: Sync,

§

impl<B> Unpin for BitVec<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for BitVec<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for BitVec<B>
where B: UnwindSafe,

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> AtomicBitVecOps for T
where T: AsRef<[Atomic<usize>]> + BitLength + ?Sized,

Source§

fn get(&self, index: usize, ordering: Ordering) -> bool

Returns true if the bit of given index is set. Read more
Source§

fn set(&self, index: usize, value: bool, ordering: Ordering)

Sets the bit of given index to the given value. Read more
Source§

fn swap(&self, index: usize, value: bool, ordering: Ordering) -> bool

Sets the bit of given index to the given value and returns the previous value. Read more
Source§

unsafe fn get_unchecked(&self, index: usize, ordering: Ordering) -> bool

Returns true if the bit of given index is set. Read more
Source§

unsafe fn set_unchecked(&self, index: usize, value: bool, ordering: Ordering)

Sets the bit of given index to the given value. Read more
Source§

unsafe fn swap_unchecked( &self, index: usize, value: bool, ordering: Ordering, ) -> bool

Sets the bit of given index to the given value and returns the previous value, without bound checks. Read more
Source§

fn fill(&mut self, value: bool, ordering: Ordering)

Sets all bits to the given value.
Source§

fn par_fill(&mut self, value: bool, ordering: Ordering)

Available on crate feature rayon only.
Sets all bits to the given value using a parallel implementation.
Source§

fn reset(&mut self, ordering: Ordering)

Sets all bits to zero.
Source§

fn par_reset(&mut self, ordering: Ordering)

Available on crate feature rayon only.
Sets all bits to zero using a parallel implementation.
Source§

fn flip(&mut self, ordering: Ordering)

Flips all bits.
Source§

fn par_flip(&mut self, ordering: Ordering)

Available on crate feature rayon only.
Flips all bits using a parallel implementation.
Source§

fn par_count_ones(&self) -> usize

Available on crate feature rayon only.
A parallel version of BitCount::count_ones.
Source§

fn iter(&self) -> AtomicBitIter<'_, [AtomicUsize]>

Returns an iterator over the bits of this atomic bit vector. Read more
Source§

impl<T> BitVecOps for T
where T: AsRef<[usize]> + BitLength + ?Sized,

Source§

fn get(&self, index: usize) -> bool

Returns true if the bit of given index is set.
Source§

unsafe fn get_unchecked(&self, index: usize) -> bool

Returns true if the bit of given index is set, without bound checks. Read more
Source§

fn iter(&self) -> BitIter<'_, [usize]>

Returns an iterator over the bits of this bit vector as booleans.
Source§

fn iter_ones(&self) -> OnesIter<'_, [usize]>

Returns an iterator over the positions of the ones in this bit vector.
Source§

fn iter_zeros(&self) -> ZerosIter<'_, [usize]>

Returns an iterator over the positions of the zeros in this bit vector.
Source§

fn par_count_ones(&self) -> usize

Available on crate feature rayon only.
A parallel version of BitCount::count_ones.
Source§

impl<T> BitVecOpsMut for T
where T: AsRef<[usize]> + AsMut<[usize]> + BitLength,

Source§

fn set(&mut self, index: usize, value: bool)

Sets the bit of given index to the given value.
Source§

unsafe fn set_unchecked(&mut self, index: usize, value: bool)

Sets the bit of given index to the given value without bound checks. Read more
Source§

fn fill(&mut self, value: bool)

Sets all bits to the given value.
Source§

fn par_fill(&mut self, value: bool)

Available on crate feature rayon only.
Sets all bits to the given value using a parallel implementation.
Source§

fn reset(&mut self)

Sets all bits to zero.
Source§

fn par_reset(&mut self)

Available on crate feature rayon only.
Sets all bits to zero using a parallel implementation.
Source§

fn flip(&mut self)

Flip all bits.
Source§

fn par_flip(&mut self)

Available on crate feature rayon only.
Flips all bits using a parallel implementation.
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> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
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> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

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

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Available on crate feature std only.
Writes to stderr debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>

Available on crate feature std only.
Writes to stderr debug info about the structure memory usage as mem_dbg, but expanding only up to max_depth levels of nested structures.
Source§

fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage as mem_dbg_on, but expanding only up to max_depth levels of nested structures.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,