gix_bitmap/lib.rs
1//! An implementation of the shared parts of git bitmaps used in `gix-pack`, `gix-index` and `gix-worktree`.
2//!
3//! Note that many tests are performed indirectly by tests in the aforementioned consumer crates.
4//!
5//! ## Examples
6//!
7//! ```
8//! let encoded = [
9//! 0, 0, 0, 64, // 64 bits in total
10//! 0, 0, 0, 2, // two u64 words follow
11//! 0, 0, 0, 2, 0, 0, 0, 0, // one RLW word with one literal word
12//! 0, 0, 0, 0, 0, 0, 0, 21, // literal bits 0, 2 and 4 set
13//! 0, 0, 0, 0, // RLW points at the first word
14//! ];
15//!
16//! let (bitmap, rest) = gix_bitmap::ewah::decode(&encoded).unwrap();
17//! let mut set_bits = Vec::new();
18//! bitmap.for_each_set_bit(|idx| {
19//! set_bits.push(idx);
20//! Some(())
21//! });
22//!
23//! assert!(rest.is_empty());
24//! assert_eq!(bitmap.num_bits(), 64);
25//! assert_eq!(set_bits, vec![0, 2, 4]);
26//! ```
27#![deny(rust_2018_idioms, unsafe_code, missing_docs)]
28
29/// Bitmap utilities for the advanced word-aligned hybrid bitmap
30pub mod ewah;
31
32pub(crate) mod decode {
33 #[inline]
34 pub(crate) fn u32(data: &[u8]) -> Option<(u32, &[u8])> {
35 data.split_at_checked(4)
36 .map(|(num, data)| (u32::from_be_bytes(num.try_into().unwrap()), data))
37 }
38}