[][src]Struct rust_dense_bitset::DenseBitSetExtended

pub struct DenseBitSetExtended { /* fields omitted */ }

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.

Methods

impl DenseBitSetExtended
[src]

pub fn new() -> Self
[src]

Returns a new empty DenseBitsetExtended

Example

let bs = DenseBitSetExtended::new();

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

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

pub fn from_dense_bitset(dbs: DenseBitSet) -> Self
[src]

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())

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

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

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

Returns true if at least one bit is set to true

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

Returns true if all the bits are set to false

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

Returns the size (in bits) of the bitset

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

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);

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

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());

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

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);

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

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

Example

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

pub fn reverse(&self) -> Self
[src]

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());

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

Returns a left rotation of the bitset by shift bits.

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

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

Returns a right rotation of the bitset by shift bits.

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

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.

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

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

impl BitSet for DenseBitSetExtended
[src]

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

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

Sets the bit at index position to value.

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

Get the bit at index position.

fn get_weight(&self) -> u32
[src]

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

fn reset(&mut self)
[src]

This resets the bitset to its empty state.

fn to_string(self) -> String
[src]

Returns a representation of the bitset as a String.

impl Eq for DenseBitSetExtended
[src]

impl Default for DenseBitSetExtended
[src]

impl PartialEq<DenseBitSetExtended> for DenseBitSetExtended
[src]

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

impl Clone for DenseBitSetExtended
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for DenseBitSetExtended
[src]

impl Hash for DenseBitSetExtended
[src]

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

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

impl Not for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the ! operator.

impl BitAnd<DenseBitSetExtended> for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the & operator.

impl BitOr<DenseBitSetExtended> for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the | operator.

impl BitXor<DenseBitSetExtended> for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the ^ operator.

impl Shl<usize> for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the << operator.

impl Shr<usize> for DenseBitSetExtended
[src]

type Output = Self

The resulting type after applying the >> operator.

impl BitAndAssign<DenseBitSetExtended> for DenseBitSetExtended
[src]

impl BitOrAssign<DenseBitSetExtended> for DenseBitSetExtended
[src]

impl BitXorAssign<DenseBitSetExtended> for DenseBitSetExtended
[src]

impl ShlAssign<usize> for DenseBitSetExtended
[src]

impl ShrAssign<usize> for DenseBitSetExtended
[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From for T
[src]

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

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

type Owned = T

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

type Error = !

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

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.

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