#bit-vector #bit #bitmap #rank #bitset

bitm

The library for bit and bitmap (bit vector) manipulation

12 unstable releases (3 breaking)

0.4.1 Feb 25, 2024
0.3.1 Jan 18, 2024
0.3.0 Dec 26, 2023
0.2.3 Jun 30, 2023
0.1.1 Mar 18, 2022

#268 in Data structures

Download history 2095/week @ 2023-12-25 2281/week @ 2024-01-01 2737/week @ 2024-01-08 3140/week @ 2024-01-15 3636/week @ 2024-01-22 2745/week @ 2024-01-29 2303/week @ 2024-02-05 3237/week @ 2024-02-12 4506/week @ 2024-02-19 5911/week @ 2024-02-26 5999/week @ 2024-03-04 5187/week @ 2024-03-11 4823/week @ 2024-03-18 3764/week @ 2024-03-25 3694/week @ 2024-04-01 2698/week @ 2024-04-08

15,317 downloads per month
Used in 12 crates (8 directly)

MIT/Apache

130KB
2K SLoC

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

Example

use bitm::{BitAccess, BitVec, Rank, 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

Benchmarks

The performance of some of the structures included in bitm can be tested with the cseq_benchmark crate. Its documentation contains benchmark results.

Dependencies