| Crates.io | bitm |
| lib.rs | bitm |
| version | 0.5.2 |
| created_at | 2022-03-01 15:26:02.79931+00 |
| updated_at | 2025-09-10 14:35:56.097829+00 |
| description | The library for bit and bitmap (bit vector) manipulation. |
| homepage | |
| repository | https://github.com/beling/bsuccinct-rs |
| max_upload_size | |
| id | 541628 |
| size | 162,890 |
bitm is the Rust library by Piotr Beling for bit and bitmap (bit vector) manipulation.
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
The performance of some of the structures included in bitm can be tested with the cseq_benchmark crate. Its documentation contains benchmark results.