pub fn nearest_power_of_two(cap: usize) -> usizeExpand description
Calculates the smallest power of two greater than or equal to the given capacity.
This function determines the nearest power of two that is not less than the provided cap. If
the calculated power of two exceeds the predefined MAXIMUM_CAPACITY, it returns MAXIMUM_CAPACITY.
§Arguments
cap- The target capacity. Must be a non-negative integer.
§Returns
usize- The nearest power of two greater than or equal tocap.
§Panics
- This function does not panic.
§Examples
use lowdash::nearest_power_of_two;
assert_eq!(nearest_power_of_two(0), 1);
assert_eq!(nearest_power_of_two(1), 1);
assert_eq!(nearest_power_of_two(5), 8);
assert_eq!(nearest_power_of_two(16), 16);
assert_eq!(nearest_power_of_two(17), 32);