pub struct FixedBitSet { /* private fields */ }
Expand description

FixedBitSet is a simple fixed size set of bits that each can be enabled (1 / true) or disabled (0 / false).

The bit set has a fixed capacity in terms of enabling bits (and the capacity can grow using the grow method).

Derived traits depend on both the zeros and ones, so [0,1] is not equal to [0,1,0].

Implementations

Create a new empty FixedBitSet.

Create a new FixedBitSet with a specific number of bits, all initially clear.

Create a new FixedBitSet with a specific number of bits, initialized from provided blocks.

If the blocks are not the exact size needed for the capacity they will be padded with zeros (if shorter) or truncated to the capacity (if longer).

For example:

let data = vec![4];
let bs = fixedbitset::FixedBitSet::with_capacity_and_blocks(4, data);
assert_eq!(format!("{:b}", bs), "0010");

Grow capacity to bits, all new bits initialized to zero

The length of the FixedBitSet in bits.

Note: len includes both set and unset bits.

let bitset = FixedBitSet::with_capacity(10);
// there are 0 set bits, but 10 unset bits
assert_eq!(bitset.len(), 10);

len does not return the count of set bits. For that, use bitset.count_ones(..) instead.

true if the FixedBitSet is empty.

Note that an “empty” FixedBitSet is a FixedBitSet with no bits (meaning: it’s length is zero). If you want to check if all bits are unset, use FixedBitSet::is_clear.

let bitset = FixedBitSet::with_capacity(10);
assert!(!bitset.is_empty());

let bitset = FixedBitSet::with_capacity(0);
assert!(bitset.is_empty());

true if all bits in the FixedBitSet are unset.

As opposed to FixedBitSet::is_empty, which is true only for sets without any bits, set or unset.

let mut bitset = FixedBitSet::with_capacity(10);
assert!(bitset.is_clear());

bitset.insert(2);
assert!(!bitset.is_clear());

This is equivalent to bitset.count_ones(..) == 0.

Return true if the bit is enabled in the FixedBitSet, false otherwise.

Note: bits outside the capacity are always disabled.

Note: Also available with index syntax: bitset[bit].

Clear all bits.

Enable bit.

Panics if bit is out of bounds.

Enable bit, and return its previous value.

Panics if bit is out of bounds.

Toggle bit (inverting its state).

Panics if bit is out of bounds

Panics if bit is out of bounds.

Copies boolean value from specified bit to the specified bit.

Panics if to is out of bounds.

Count the number of set bits in the given bit range.

Use .. to count the whole content of the bitset.

Panics if the range extends past the end of the bitset.

Sets every bit in the given range to the given state (enabled)

Use .. to set the whole bitset.

Panics if the range extends past the end of the bitset.

Enables every bit in the given range.

Use .. to make the whole bitset ones.

Panics if the range extends past the end of the bitset.

Toggles (inverts) every bit in the given range.

Use .. to toggle the whole bitset.

Panics if the range extends past the end of the bitset.

View the bitset as a slice of u32 blocks

View the bitset as a mutable slice of u32 blocks. Writing past the bitlength in the last will cause contains to return potentially incorrect results for bits past the bitlength.

Iterates over all enabled bits.

Iterator element is the index of the 1 bit, type usize.

Returns a lazy iterator over the intersection of two FixedBitSets

Returns a lazy iterator over the union of two FixedBitSets.

Returns a lazy iterator over the difference of two FixedBitSets. The difference of a and b is the elements of a which are not in b.

Returns a lazy iterator over the symmetric difference of two FixedBitSets. The symmetric difference of a and b is the elements of one, but not both, sets.

In-place union of two FixedBitSets.

On calling this method, self’s capacity may be increased to match other’s.

In-place intersection of two FixedBitSets.

On calling this method, self’s capacity will remain the same as before.

In-place difference of two FixedBitSets.

On calling this method, self’s capacity will remain the same as before.

In-place symmetric difference of two FixedBitSets.

On calling this method, self’s capacity may be increased to match other’s.

Returns true if self has no elements in common with other. This is equivalent to checking for an empty intersection.

Returns true if the set is a subset of another, i.e. other contains at least all the values in self.

Returns true if the set is a superset of another, i.e. self contains at least all the values in other.

Trait Implementations

Formats the value using the given formatter.

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

Performs the |= operation. Read more

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

Performs the ^= operation. Read more

Performs the ^= operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Sets the bit at index i to true for each item i in the input src.

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

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Return a FixedBitSet containing bits set to true for every bit index in the iterator, other bits are set to false.

Creates a value from an iterator. Read more

Feeds this value into the given Hasher. Read more

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

Return true if the bit is enabled in the bitset, or false otherwise.

Note: bits outside the capacity are always disabled, and thus indexing a FixedBitSet will not panic.

The returned type after indexing.

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

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

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.