Struct bitset::BitSet [] [src]

pub struct BitSet { /* fields omitted */ }

Methods

impl BitSet
[src]

Create a new BitSet with ZERO bit.

Example

use bitset::BitSet;

let bs = BitSet::new();

Create a new BitSet with nbits bits with all bit initialized by 0.

Arguments

  • nbits - A integer, which value is the bits count BitSet will hold.

Example

use bitset::BitSet;

let bs = BitSet::with_capacity(100);

Create a new BitSet from a u64 value, and initialize all bits by 0.

Arguments

  • v - A u64 value.

Example

use bitset::BitSet;

let bs = BitSet::from_u64(2);
assert!(bs.test(0) == false);
assert!(bs.test(1) == true);

Create a new BitSet from a u64 vec, and initialize all bits by 0.

Arguments

  • vec - A u64 vector.

Example

use bitset::BitSet;

let vec = vec![u64::max_value(), 0, u64::max_value()];
let bs = BitSet::from_vec64(&vec);
assert!(bs.test(63) == true);
assert!(bs.test(64) == false);

Return the actual bits count.

Example

use bitset::BitSet;
 
let bs = BitSet::with_capacity(100);
assert!(bs.size() == 100);

Return the count of 1.

Example

use bitset::BitSet;

let bs = BitSet::with_capacity(100);
assert!(bs.count() == 0);

Return if the given bit index has been set to 1.

Example

use bitset::BitSet;

let bs = BitSet::with_capacity(100);
assert!(bs.test(99) == false);

Return if there is one bit has been set to 1 in the whole bitset..

Example

use bitset::BitSet;

let bs = BitSet::with_capacity(100);
assert!(bs.any() == false);

Return if all bits are set to 0.

Example

use bitset::BitSet;

let bs = BitSet::with_capacity(100);
assert!(bs.none() == true);

Set the bit specified by bit_idx to v, which is true or false.

Arguments

  • bit_idx - the bit index we want to set.
  • v - the value we want to set. true or false.

Example

use bitset::BitSet;

let mut bs = BitSet::with_capacity(100);
bs.set(99, true);
assert!(bs.test(99) == true);

Reset all bits to 0.

Example

use bitset::BitSet;

let mut bs = BitSet::with_capacity(100);
bs.set(99, true);
assert!(bs.test(99) == true);
bs.reset();
assert!(bs.test(99) == false);

Flip the bit specified by bit_idx to the reverse value. If the bit value is true, then it will be flipped to false. The other case is like the same.

Arguments

bit_idx - the index of the bit we want to flip.

Example

use bitset::BitSet;

let mut bs = BitSet::with_capacity(100);
assert!(bs.test(99) == false);
bs.flip(99);
assert!(bs.test(99) == true);

Flip all bits in the bitset. It may run time-costly.

Example

use bitset::BitSet;

let mut bs = BitSet::with_capacity(100);
bs.flip_all();
for i in 0..100 {
    assert!(bs.test(i) == true);
}
bs.flip_all();
for i in 0..100 {
    assert!(bs.test(i) == false);
}

Trait Implementations

impl Default for BitSet
[src]

Returns the "default value" for a type. Read more