#![doc = include_str!("../README.md")]
mod rank_select;
pub use rank_select::{RankSimple, ArrayWithRankSimple, RankSelect101111, ArrayWithRank101111,
Rank, Select, Select0, SelectForRank101111, Select0ForRank101111, select64, optimal_combined_sampling,
BinaryRankSearch, CombinedSampling, ConstCombinedSamplingDensity, AdaptiveCombinedSamplingDensity, };
mod bitvec;
pub use bitvec::*;
#[inline(always)] pub const fn ceiling_div(n: usize, d: usize) -> usize { (n+d-1)/d }
#[inline(always)] pub const fn n_lowest_bits(how_many: u8) -> u64 { (1u64 << how_many).wrapping_sub(1) }
#[inline(always)] pub const fn n_lowest_bits_1_64(how_many: u8) -> u64 { u64::MAX >> (64-how_many) }
#[inline(always)] pub const fn n_lowest_bits_0_64(how_many: u8) -> u64 {
if how_many >= 64 { return u64::MAX; }
n_lowest_bits(how_many)
}
#[inline] pub fn bits_to_store<V: Into<u64>>(max_value: V) -> u8 {
max_value.into().checked_ilog2().map_or(0, |v| v as u8+1)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_div_up() {
assert_eq!(ceiling_div(7, 2), 4);
assert_eq!(ceiling_div(8, 2), 4);
assert_eq!(ceiling_div(9, 2), 5);
assert_eq!(ceiling_div(10, 3), 4);
}
#[test]
fn test_n_lowest() {
assert_eq!(n_lowest_bits(63), u64::MAX>>1);
assert_eq!(n_lowest_bits(3), 0b111);
assert_eq!(n_lowest_bits(1), 0b1);
assert_eq!(n_lowest_bits(0), 0);
}
#[test]
fn test_bits_to_store() {
assert_eq!(bits_to_store(0u32), 0);
assert_eq!(bits_to_store(1u32), 1);
assert_eq!(bits_to_store(2u32), 2);
assert_eq!(bits_to_store(3u32), 2);
assert_eq!(bits_to_store(4u32), 3);
assert_eq!(bits_to_store(7u32), 3);
assert_eq!(bits_to_store(8u32), 4);
assert_eq!(bits_to_store(9u32), 4);
assert_eq!(bits_to_store(15u32), 4);
assert_eq!(bits_to_store(16u32), 5);
assert_eq!(bits_to_store(u32::MAX-1), 32);
assert_eq!(bits_to_store(u32::MAX), 32);
assert_eq!(bits_to_store(u64::MAX), 64);
}
}