[][src]Trait rust_dense_bitset::BitSet

pub trait BitSet {
    fn set_bit(&mut self, position: usize, value: bool);
fn get_bit(&self, position: usize) -> bool;
fn get_weight(&self) -> u32;
fn reset(&mut self);
fn to_string(self) -> String; }

Trait to define the basic functions of a BitSet

Required methods

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

Sets the value of the bit at position position to value

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

Gets the value of the bit at position position

fn get_weight(&self) -> u32

Returns the bitset's Hamming weight

fn reset(&mut self)

Resets the bitset

fn to_string(self) -> String

Produces a string representation of the bitset (little endian), aligned with 64 bits and with leading zeroes

Loading content...

Implementors

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

Loading content...