1
Fork 0

Reduce HashMap allocations.

This commit is contained in:
Clark Gaebel 2014-03-26 21:58:08 -04:00
parent b75683cadf
commit 9f45484db5
2 changed files with 69 additions and 27 deletions

View file

@ -311,6 +311,12 @@ pub fn next_power_of_two<T: Unsigned + Int>(n: T) -> T {
tmp + one()
}
// Returns `true` iff `n == 2^k` for some k.
#[inline]
pub fn is_power_of_two<T: Unsigned + Int>(n: T) -> bool {
(n - one()) & n == zero()
}
/// Returns the smallest power of 2 greater than or equal to `n`. If the next
/// power of two is greater than the type's maximum value, `None` is returned,
/// otherwise the power of 2 is wrapped in `Some`.