Expand description
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.
Structs§
- Specifies adaptive sampling of select values by
CombinedSampling. - A select strategy for
RankSelect101111that does not introduce any overhead (on space or construction speed) and is based on a binary search over ranks. - Iterator over indices of bits set to 1 (if
Bistrue) or 0 (ifBisfalse) in slice ofu64. - Iterator over bits in slice of
u64. It yieldstruefor bit 1 andfalsefor 0. - Fast select strategy for
RankSelect101111with about 0.39% space overhead. - Specifies a constant sampling of select values by
CombinedSampling, given as the base 2 logarithm (which can be calculated byoptimal_combined_samplingfunction). The actual sampling is 2 times denser, but every second sample sometimes cannot be recorded accurately. - Returns number of bits set (to one) in
contentwhose length does not exceeds 8. Returns number of bits set (to one) incontentwhose length does not exceeds 8. The structure that holds bit vectorcontentandranksstructure that takes no more than 3.125% extra space. It can return the number of ones (or zeros) in firstindexbits of thecontent(seerankandrank0method) in O(1) time. In addition, it supports select queries utilizing binary search over ranks (seeBinaryRankSearch) or (optionally, at the cost of extra space overhead; about 0.39% with default settings) combined sampling (which is usually faster; seeCombinedSampling). - The structure that holds array of bits
contentandranksstructure that takes no more than 6.25% extra space. It can returns the number of ones in firstindexbits of thecontent(seerankmethod) in O(1) time. Onlycontentwith less than 232 bit ones is supported. Any type that implements theDereftrait withTarget = [u64]can be used as a bit vector.
Traits§
- The trait that is implemented for the array of
u64and extends it with methods for accessing and modifying single bits or arbitrary fragments consisted of few (up to 63) bits. - The trait that is implemented for
Box<[u64]>and extends it with bit-oriented constructors. - Trait for rank queries on bit vector. Rank query returns the number of ones (or zeros) in requested number of the first bits.
- Trait implemented by the types that support select (one) queries, i.e. can (quickly) find the position of the n-th one in the bitmap.
- Trait implemented by the types that support select zero queries, i.e. can (quickly) find the position of the n-th zero in the bitmap.
- Trait implemented by strategies for select zeros operations for
ArrayWithRank101111. - Trait implemented by strategies for select (ones) operations for
ArrayWithRank101111.
Functions§
- Calculates the minimal number of bits needed to store values from
0to givenmax_value. - Returns ceil of
n/d. - Returns the largest
how_many-bit number, i.e. 0..01..1 mask withhow_manyones.how_manymust be in range [0, 63]. - Returns the largest
how_many-bit number, i.e. 0..01..1 mask withhow_manyones.how_manymust be in range [0, 64]. - Returns the largest
how_many-bit number, i.e. 0..01..1 mask withhow_manyones.how_manymust be in range [1, 64]. - Calculates such a sampling density of select values that provides an approximately constant space overhead (independent of set/unset bits ratio in the vector) of
CombinedSampling. - Returns the position of the
rank-th (counting from 0) one in the bit representation ofn, i.e. the index of the one with the given rank.
Type Aliases§
- Alias for backward compatibility.
RankSelect101111withBinaryRankSearch(which does not introduce a space overhead) for select queries. - Alias for backward compatibility.
- Iterator over bits set to 1 in slice of
u64. - Iterator over bits set to 0 in slice of
u64.