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#![deny(rust_2018_idioms, unsafe_code, missing_docs)]
5
6/// Bitmap utilities for the advanced word-aligned hybrid bitmap
7pub mod ewah;
8
9pub(crate) mod decode {
10 #[inline]
11 pub(crate) fn split_at_pos(data: &[u8], pos: usize) -> Option<(&[u8], &[u8])> {
12 if data.len() < pos {
13 return None;
14 }
15 data.split_at(pos).into()
16 }
17
18 #[inline]
19 pub(crate) fn u32(data: &[u8]) -> Option<(u32, &[u8])> {
20 split_at_pos(data, 4).map(|(num, data)| (u32::from_be_bytes(num.try_into().unwrap()), data))
21 }
22}