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

A BitSet is a simple set designed to track which indices are placed into it.

Note, a BitSet is limited by design to only usize**4 indices. Adding beyond this limit will cause the BitSet to panic.

Implementations

Creates an empty BitSet.

Creates an empty BitSet, preallocated for up to max indices.

Adds id to the BitSet. Returns true if the value was already in the set.

Removes id from the set, returns true if the value was removed, and false if the value was not set to begin with.

Returns true if id is in the set.

Returns true if all ids in other are contained in this set

Completely wipes out the bit set.

How many bits are in a usize.

This value can be trivially determined. It is provided here as a constant for clarity.

Example
use hibitset::BitSet;
assert_eq!(BitSet::BITS_PER_USIZE, std::mem::size_of::<usize>()*8);

Returns the bottom layer of the bitset as a slice. Each bit in this slice refers to a single Index.

The slice’s length will be at least the length needed to reflect all the 1s in the bitset, but is not otherwise guaranteed. Consider it to be an implementation detail.

Example
use hibitset::BitSet;

let index: u32 = 12345;

let mut bitset = BitSet::new();
bitset.add(index);

// layer 0 is 1:1 with Indexes, so we expect that bit in the slice to be set
let slice = bitset.layer0_as_slice();
let bit_index = index as usize;

// map that bit index to a usize in the slice and a bit within that usize
let slice_index = bit_index / BitSet::BITS_PER_USIZE;
let bit_at_index = bit_index % BitSet::BITS_PER_USIZE;

assert_eq!(slice[slice_index], 1 << bit_at_index);

How many Indexes are described by as single layer 1 bit, intended for use with BitSet::layer1_as_slice().

BitSets are defined in terms of usizes summarizing usizes, so this value can be trivially determined. It is provided here as a constant for clarity.

Example
use hibitset::BitSet;
assert_eq!(BitSet::LAYER1_GRANULARITY, BitSet::BITS_PER_USIZE);

Returns the second layer of the bitset as a slice. Each bit in this slice summarizes a corresponding usize from layer0. (If usize is 64 bits, bit 0 will be set if any Indexes 0-63 are set, bit 1 will be set if any Indexes 64-127 are set, etc.) BitSet::LAYER1_GRANULARITY reflects how many indexes are summarized per layer 1 bit.

The slice’s length is not guaranteed, except that it will be at least the length needed to reflect all the 1s in the bitset.

Example
use hibitset::BitSet;

let index: u32 = 12345;

let mut bitset = BitSet::new();
bitset.add(index);

// layer 1 summarizes multiple indexes per bit, so divide appropriately
let slice = bitset.layer1_as_slice();
let bit_index = index as usize / BitSet::LAYER1_GRANULARITY;

// map that bit index to a usize in the slice and a bit within that usize
let slice_index = bit_index / BitSet::BITS_PER_USIZE;
let bit_at_index = bit_index % BitSet::BITS_PER_USIZE;

assert_eq!(slice[slice_index], 1 << bit_at_index);

How many Indexes are described by as single layer 2 bit, intended for use with BitSet::layer2_as_slice().

BitSets are defined in terms of usizes summarizing usizes, so this value can be trivially determined. It is provided here as a constant for clarity.

Example
use hibitset::BitSet;
assert_eq!(BitSet::LAYER2_GRANULARITY, BitSet::LAYER1_GRANULARITY * BitSet::BITS_PER_USIZE);

Returns the third layer of the bitset as a slice. Each bit in this slice summarizes a corresponding usize from layer1. If usize is 64 bits, bit 0 will be set if any Indexes 0-4095 are set, bit 1 will be set if any Indexes 4096-8191 are set, etc.

The slice’s length is not guaranteed, except that it will be at least the length needed to reflect all the 1s in the bitset.

Example
use hibitset::BitSet;

let index: u32 = 12345;

let mut bitset = BitSet::new();
bitset.add(index);

// layer 2 summarizes multiple indexes per bit, so divide appropriately
let slice = bitset.layer2_as_slice();
let bit_index = index as usize / BitSet::LAYER2_GRANULARITY;

// map that bit index to a usize in the slice and a bit within that usize
let slice_index = bit_index / BitSet::BITS_PER_USIZE;
let bit_at_index = bit_index % BitSet::BITS_PER_USIZE;

assert_eq!(slice[slice_index], 1 << bit_at_index);

Trait Implementations

The resulting type after applying the & operator.

Performs the & operation. Read more

The resulting type after applying the & operator.

Performs the & operation. Read more

Performs the &= operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

The resulting type after applying the | operator.

Performs the | operation. Read more

Performs the |= operation. Read more

Return a usize where each bit represents if any word in layer2 has been set. Read more

Return the usize from the array of usizes that indicates if any bit has been set in layer1 Read more

Return the usize from the array of usizes that indicates if any bit has been set in layer0 Read more

Return a usize that maps to the direct 1:1 association with each index of the set Read more

Allows checking if set bit is contained in the bit set.

Gets the usize corresponding to layer and index. Read more

Returns true if this BitSetLike contains nothing, and false otherwise.

Create an iterator that will scan over the keyspace

Create a parallel iterator that will scan over the keyspace

The resulting type after applying the ^ operator.

Performs the ^ operation. Read more

The resulting type after applying the ^ operator.

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

Removes bit from the bit set. Read more

Create a draining iterator that will scan over the keyspace and clears it while doing so.

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

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

Creates a value from an iterator. Read more

Creates a value from an iterator. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

Type of joined components.

Type of joined storages.

Type of joined bit mask.

Open this join by returning the mask and the storages. Read more

Get a joined component value by a given index. Read more

Create a joined iterator over the contents.

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance. Read more

Type of joined components.

Type of joined storages.

Type of joined bit mask.

Open this join by returning the mask and the storages. Read more

Get a joined component value by a given index. Read more

Create a joined iterator over the contents.

Returns a Join-able structure that yields all indices, returning None for all missing elements and Some(T) for found elements. Read more

If this Join typically returns all indices in the mask, then iterating over only it or combined with other joins that are also dangerous will cause the JoinIter/ParJoin to go through all indices which is usually not what is wanted and will kill performance. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

The resulting type after applying the ! operator.

Performs the unary ! operation. Read more

Create a joined parallel iterator over the contents.

Create a joined parallel iterator over the contents.

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

This method tests for !=.

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 alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

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

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

Tries to create the default.

Calls try_default and panics on an error case.

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.