[][src]Struct rust_dense_bitset::DenseBitSet

pub struct DenseBitSet { /* fields omitted */ }

Provides an efficient and compact BitSet implementation for up to 64 bits.

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

Methods

impl DenseBitSet
[src]

pub fn new() -> Self
[src]

Returns a new empty DenseBitSet.

Example

use rust_dense_bitset::DenseBitSet;

let mut bs = DenseBitSet::new();

pub fn from_integer(i: u64) -> Self
[src]

Generates a bitset from an integer (little endian convention).

Example

use rust_dense_bitset::DenseBitSet;

let bs = DenseBitSet::from_integer(1234567890);

pub fn from_string(s: &str, base: u32) -> Self
[src]

Generates a bitset from a string and a base (little endian convention).

The base must be an integer between 2 and 32.

Example

use rust_dense_bitset::DenseBitSet;

let mut bs1 = DenseBitSet::from_string("101010", 2);
let mut bs2 = DenseBitSet::from_string("2a", 16);

assert_eq!(bs1,bs2);

Panics

This function will panic if an incorrect base is provided or if invalid characters are found when parsing.

pub fn to_integer(self) -> u64
[src]

Returns an integer representing the bitset (little endian convention).

Example

use rust_dense_bitset::DenseBitSet;

let bs = DenseBitSet::from_integer(1234);

assert_eq!(bs.to_integer(), 1234);

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

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

Example

use rust_dense_bitset::DenseBitSet;

let bs = DenseBitSet::from_integer(0b11110101010010);
let value = bs.extract(5,6);

assert_eq!(value, 42);

Panics

This function will panic if length is zero or if one tries to access a bit beyond the 64 bit limit (i.e., position + length > 64).

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

Returns nothing, mutates the DenseBitSet to insert value at the given position.

Note that value is treated as a length-bit integer (little endian convention); if necessary, value is padded with zeros (or truncated) to be of the correct length.

Example

use rust_dense_bitset::DenseBitSet;

let mut bs = DenseBitSet::new();
bs.insert(10, 8, 0b10101011);
bs.insert(3,1,1);

assert_eq!(bs.to_integer(), 0b101010110000001000)

Panics

This function will panic if length is zero, or if one tries to insert a bit beyond the 64 bit limit (i.e. position + length > 64)

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

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

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let mut bs = DenseBitSet::from_integer(u64::max_value());

assert!(bs.all());

bs.set_bit(28,false);
bs.all(); // -> false

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

Returns true if at least one of the bits is set to true.

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let mut bs = DenseBitSet::from_integer(2048);

assert!(bs.any());

bs.set_bit(11,false);
bs.any(); // -> false

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

Returns true if all the bits are set to false.

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let mut bs = DenseBitSet::from_integer(2048);
bs.set_bit(11,false);

assert!(bs.none());

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

Returns a bit-reversed DenseBitSet.

This method is using a constant time bit reversal algorithm for 64 bits integers.

Example

use rust_dense_bitset::DenseBitSet;

let bs = DenseBitSet::from_integer(0b11110001);
let bs2 = bs.reverse();

assert_eq!(bs2.to_integer(), 0b1000111100000000000000000000000000000000000000000000000000000000);

pub fn rotr(&mut self, shift: u32)
[src]

Right rotation of shift bits.

Shifts the bits to the right, wrapping the truncated bits to the end of the bitset.

The rotation is done in-place, so the bitset needs to be mutable.

Example

use rust_dense_bitset::DenseBitSet;

let mut bs = DenseBitSet::from_integer(0b111000111000111000111);
bs.rotr(10);

assert_eq!(bs.to_integer(), 0b111000111000000000000000000000000000000000000000000011100011100 );

pub fn rotl(&mut self, shift: u32)
[src]

Left rotation of shift bits.

Shifts the bits to the left, wrapping the truncated bits to the beginning of the bitset.

The rotation is done in place, so the bitset needs to be mutable.

Example

use rust_dense_bitset::DenseBitSet;

let mut bs = DenseBitSet::from_integer(0b111000111000111000111);
bs.rotl(10);

assert_eq!(bs.to_integer(), 0b1110001110001110001110000000000 );

pub fn first_set(self) -> u32
[src]

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

Example

let dbs = DenseBitSet::from_integer(256);
println!("{}", dbs.first_set());

Trait Implementations

impl BitSet for DenseBitSet
[src]

This is a compact implementation of the BitSet trait over a 64-bit word (which is the native word size for many architectures), allowing for efficient operations and compact memory usage.

Modifiers and accessors are boundary checked to ensure that operations remain within that 64 bit range.

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

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

Sets the bit at index position to value. The bitset needs to be mutable for this operation to succeed.

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let mut bs = DenseBitSet::new();
bs.set_bit(25, true); // This sets the bit at index 25 , hence the 26th bit -> 2^25

assert_eq!(bs.to_integer(), 33554432);

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

Get the bit at index position.

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let bs = DenseBitSet::from_integer(65536);

assert!(bs.get_bit(16));

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

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

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let bs = DenseBitSet::from_integer(0b01100100111010);

println!("{}", bs.get_weight()); // -> 7

fn reset(&mut self)
[src]

This resets the bitset to its empty state. (The bitset must be mutable for this operation).

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let mut bs = DenseBitSet::from_integer(1234567890);
bs.reset();

assert!(bs.none());

fn to_string(self) -> String
[src]

Returns a representation of the bitset as a String.

Example

use rust_dense_bitset::DenseBitSet;
use rust_dense_bitset::BitSet;

let bs = DenseBitSet::from_integer(68719481088);

println!("{}", bs.to_string()) // -> "0000000000000000000000000001000000000000000000000001000100000000"

impl Eq for DenseBitSet
[src]

impl Copy for DenseBitSet
[src]

impl Default for DenseBitSet
[src]

impl PartialEq<DenseBitSet> for DenseBitSet
[src]

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

This method tests for !=.

impl Clone for DenseBitSet
[src]

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

Performs copy-assignment from source. Read more

impl Debug for DenseBitSet
[src]

impl Hash for DenseBitSet
[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 DenseBitSet
[src]

type Output = Self

The resulting type after applying the ! operator.

impl BitAnd<DenseBitSet> for DenseBitSet
[src]

type Output = Self

The resulting type after applying the & operator.

impl BitOr<DenseBitSet> for DenseBitSet
[src]

type Output = Self

The resulting type after applying the | operator.

impl BitXor<DenseBitSet> for DenseBitSet
[src]

type Output = Self

The resulting type after applying the ^ operator.

impl Shl<usize> for DenseBitSet
[src]

type Output = Self

The resulting type after applying the << operator.

impl Shr<usize> for DenseBitSet
[src]

type Output = Self

The resulting type after applying the >> operator.

impl BitAndAssign<DenseBitSet> for DenseBitSet
[src]

impl BitOrAssign<DenseBitSet> for DenseBitSet
[src]

impl BitXorAssign<DenseBitSet> for DenseBitSet
[src]

impl ShlAssign<usize> for DenseBitSet
[src]

impl ShrAssign<usize> for DenseBitSet
[src]

Auto Trait Implementations

impl Send for DenseBitSet

impl Sync for DenseBitSet

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]