16 releases

0.5.1 Apr 19, 2025
0.5.0 Mar 19, 2025
0.4.3 Oct 2, 2024
0.4.2 Jun 21, 2024
0.1.1 Mar 18, 2022

#219 in Data structures

Download history 4101/week @ 2025-02-14 3502/week @ 2025-02-21 3765/week @ 2025-02-28 4423/week @ 2025-03-07 4162/week @ 2025-03-14 3836/week @ 2025-03-21 3906/week @ 2025-03-28 4270/week @ 2025-04-04 4633/week @ 2025-04-11 4358/week @ 2025-04-18 3230/week @ 2025-04-25 3470/week @ 2025-05-02 3896/week @ 2025-05-09 4083/week @ 2025-05-16 5040/week @ 2025-05-23 3941/week @ 2025-05-30

17,801 downloads per month
Used in 14 crates (9 directly)

MIT/Apache

145KB
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

~115KB

OSZAR »