Skip to main content

blocks_number_for_bits

Function blocks_number_for_bits 

Source
pub const fn blocks_number_for_bits(requested_bits: usize) -> usize
Expand description

Calculate the number of blocks needed to store a given number of bits.

This function computes the minimum number of usize blocks required to store the specified number of bits, rounding up when necessary. This is a constant function that can be evaluated at compile time.

ยงExample

use ranged_bitmap::blocks_number_for_bits;

const BLOCKS_64: usize = blocks_number_for_bits(64);
const BLOCKS_65: usize = blocks_number_for_bits(65);

assert_eq!(BLOCKS_64, 1);  // Exactly one block
assert_eq!(BLOCKS_65, 2);  // Needs two blocks