Struct DenseBitSetExtended

Source
pub struct DenseBitSetExtended { /* private fields */ }
Expand description

Provides a dense BitSet implementation (only limited by available memory)

Internally, a Vec<u64> data structure is used to store information.

This structure implements BitSet, Clone, Default, Debug, Hash, PartialEq, Eq and bit operations.

Implementations§

Source§

impl DenseBitSetExtended

Source

pub fn new() -> Self

Returns a new empty DenseBitsetExtended

§Example
let bs = DenseBitSetExtended::new();
Source

pub fn with_capacity(size: usize) -> Self

Returns an empty DenseBitsetExtended with pre-allocated memory of size bits.

This is useful to avoid additional allocations is situations where the bitset’s space requirements are known in advance.

§Example
let mut bs = DenseBitSetExtended::with_capacity(128);
bs.set_bit(127, true); // No additional allocation performed
Source

pub fn from_dense_bitset(dbs: DenseBitSet) -> Self

Returns a DenseBitSetExtended extending a given DenseBitSet.

§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.to_string())
Source

pub fn all(&self) -> bool

Returns true if and only if all bits are set to true

Source

pub fn any(&self) -> bool

Returns true if at least one bit is set to true

Source

pub fn none(&self) -> bool

Returns true if all the bits are set to false

Source

pub fn get_size(&self) -> usize

Returns the size (in bits) of the bitset

Source

pub fn extract_u64(&self, position: usize, length: usize) -> u64

Returns an integer representation of the bitsting starting at the given position with given length (little endian convention).

Note: this method can extract up to 64 bits into an u64. For larger extractions, use subset instead.

§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.extract_u64(2, 4)); // Extracts "0001" (displayed with leading zeros)
§Panics

The function panics if length is zero

let panic_me = dbse.extract_u64(3, 0);
Source

pub fn subset(&self, position: usize, length: usize) -> Self

Returns a DenseBitSetExtended of given length whose bits are extracted from the given position.

§Example
let dbs = DenseBitSet::from_integer(0b111000111);
let dbse = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbse.subset(2, 4).to_string());
Source

pub fn insert(&mut self, other: &Self, position: usize, length: usize)

Inserts the first length bits of other at the given position in the current structure.

§Example
let mut bs = DenseBitSetExtended::new();
let bs2 =
   DenseBitSetExtended::from_dense_bitset(DenseBitSet::from_integer(0b1011011101111));
bs.insert(&bs2, 60, 13);
Source

pub fn insert_u64(&mut self, value: u64, position: usize, length: usize)

Inserts a length-bit integer as a bitset at the given position.

§Example
let mut bs = DenseBitSetExtended::new();
bs.insert_u64(0b1011011101111, 50, 64);
Source

pub fn reverse(&self) -> Self

Returns a bit-reversed bitset.

§Example
let val = 66612301234;
let dbs = DenseBitSet::from_integer(val);
let ext_dbs = DenseBitSetExtended::from_dense_bitset(dbs);
println!("{}", dbs.to_string());
println!("{}", ext_dbs.reverse().to_string());
Source

pub fn rotl(self, shift: usize) -> Self

Returns a left rotation of the bitset by shift bits.

Note: The bitset is extended by shift bits by this operation.

Source

pub fn rotr(self, shift: usize) -> Self

Returns a right rotation of the bitset by shift bits.

Source

pub fn from_string(s: String, radix: u32) -> Self

Constructs a DenseBitSetExtended from a provided String.

§Example
let bs2 = DenseBitSetExtended::from_string(String::from("f8d5215a52b57ea0aeb294af576a0aeb"), 16);
§Panics

This function expects a radix between 2 and 32 included, and will otherwise panic. This function will also panic if incorrect characters are provided.

Source

pub fn first_set(&self) -> usize

Returns the position of the first set bit (little endian convention)

§Example
let dbs = DenseBitSetExtended::from_dense_bitset( DenseBitSet::from_integer(256) ) << 12;
println!("{}", dbs.first_set());

Trait Implementations§

Source§

impl BitAnd for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: Self) -> Self

Performs the & operation. Read more
Source§

impl BitAndAssign for DenseBitSetExtended

Source§

fn bitand_assign(&mut self, rhs: Self)

Performs the &= operation. Read more
Source§

impl BitOr for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Self) -> Self

Performs the | operation. Read more
Source§

impl BitOrAssign for DenseBitSetExtended

Source§

fn bitor_assign(&mut self, rhs: Self)

Performs the |= operation. Read more
Source§

impl BitSet for DenseBitSetExtended

This is an extended implementation of the BitSet trait. It dynamically resizes the bitset as necessary to accomodate growing or shrinking operations (e.g. left shifts) and is only limited by available memory. In practice however, we (arbitrarily) limited allocation to 64000 bits.

Note: The BitSet trait must be in scope in order to use methods from this trait.

Note: The Copy trait cannot be implemented for DenseBitSetExtended (for the same reasons avec Vec).

Source§

fn set_bit(&mut self, position: usize, value: bool)

Sets the bit at index position to value.

Source§

fn get_bit(&self, position: usize) -> bool

Get the bit at index position.

Source§

fn get_weight(&self) -> u32

Returns the bitset’s Hamming weight (in other words, the number of bits set to true).

Source§

fn reset(&mut self)

This resets the bitset to its empty state.

Source§

fn to_string(self) -> String

Returns a representation of the bitset as a String.

Source§

impl BitXor for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: Self) -> Self

Performs the ^ operation. Read more
Source§

impl BitXorAssign for DenseBitSetExtended

Source§

fn bitxor_assign(&mut self, rhs: Self)

Performs the ^= operation. Read more
Source§

impl Clone for DenseBitSetExtended

Source§

fn clone(&self) -> DenseBitSetExtended

Returns a copy 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 Debug for DenseBitSetExtended

Source§

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

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

impl Default for DenseBitSetExtended

Source§

fn default() -> DenseBitSetExtended

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

impl Hash for DenseBitSetExtended

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Not for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the ! operator.
Source§

fn not(self) -> Self

Performs the unary ! operation. Read more
Source§

impl PartialEq for DenseBitSetExtended

Source§

fn eq(&self, other: &Self) -> 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 Shl<usize> for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the << operator.
Source§

fn shl(self, rhs: usize) -> Self

Performs the << operation. Read more
Source§

impl ShlAssign<usize> for DenseBitSetExtended

Source§

fn shl_assign(&mut self, rhs: usize)

Performs the <<= operation. Read more
Source§

impl Shr<usize> for DenseBitSetExtended

Source§

type Output = DenseBitSetExtended

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: usize) -> Self

Performs the >> operation. Read more
Source§

impl ShrAssign<usize> for DenseBitSetExtended

Source§

fn shr_assign(&mut self, rhs: usize)

Performs the >>= operation. Read more
Source§

impl Eq for DenseBitSetExtended

Auto Trait Implementations§

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> 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> 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> 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> 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, 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.