Skip to main content

Crate bit_manipulation

Crate bit_manipulation 

Source
Expand description

Bit manipulation utilities and a tiny fixed-size bitset.

The free-standing functions cover the operations that show up over and over in competitive programming:

Bitset wraps Vec<u64> and exposes the operations you’d expect: get, set, reset, flip, plus count_ones over the whole set.

All inputs are u64 unless documented otherwise.

Structs§

Bitset
Fix-sized bitset backed by Vec<u64>.

Functions§

highest_bit
Mask with the highest set bit. Returns 0 if x == 0.
is_power_of_two
True iff x is a (positive) power of two.
log2_floor
Floor of the base-2 logarithm of x. Panics if x == 0.
lowest_bit
Mask with the lowest set bit. Returns 0 if x == 0.
next_power_of_two
Smallest power of two ≥ x. Returns 1 for x == 0.
popcount
Number of set bits in x.
subsets
Iterate over all 2^k non-empty subsets of a k-bit mask.
trailing_ones
Index of the lowest unset bit of !x. Returns 64 if x is all ones.
trailing_zeros
Index of the lowest set bit. Returns 64 if x == 0.