Crate bitm

source · []
Expand description

bitm is the Rust library by Piotr Beling for bit and bitmap (bit vector) manipulation.

Example

use bitm::{BitAccess, BitVec, BitArrayWithRank, ArrayWithRank101111};

let mut b = Box::<[u64]>::with_zeroed_bits(2048);    // b can store 2048 bits
assert_eq!(b.get_bit(100), false);  // b is zeroed so bit at index 100 is not set  
b.set_bit(100);                     // set the bit
assert_eq!(b.get_bit(100), true);   // now it is set
assert_eq!(b.get_bits(99, 5), 0b00010); // 5 bits, beginning from index 99, should be 00010

let (r, ones) = ArrayWithRank101111::build(b);
assert_eq!(ones, 1);        // one bit is set in b
assert_eq!(r.rank(100), 0); // no ones in the first 100 bits of b
assert_eq!(r.rank(101), 1); // 1 one in the first 101 bits of b
assert_eq!(r.rank(999), 1); // 1 one in the first 999 bits of b

Structs

The structure that holds array of bits content and ranks structure that takes no more than 3.125% extra space. It can returns the number of ones in first index bits of the content (see rank method) in O(1) time.

The structure that holds array of bits content and ranks structure that takes no more than 6.25% extra space. It can returns the number of ones in first index bits of the content (see rank method) in O(1) time.

Traits

The trait that is implemented for the array of u64 and extends it with methods for accessing and modifying single bits or arbitrary fragments consisted of few (up to 63) bits.

The trait implemented by the types which holds the array of bits and the rank structure for this array. Thanks to the rank structure, the implementor can quickly return the number of ones in requested number of the first bits of the stored array (see rank method).

The trait that is implemented for Box<[u64]> and extends it with bit-oriented constructors.

Functions

Returns ceil of n/d.

Returns the largest how_many-bit number, i.e. 0..01..1 mask with how_many ones.