Regina Calculation Engine
|
An optimised class for bitwise analysis and manipulation of native data types.
More...
#include <utilities/bitmanip.h>
Public Types | |
enum | { specialised } |
enum | { specialised = 0 } |
enum | |
Static Public Member Functions | |
static int | firstBit (T x) |
Returns the index of the first true bit in the given integer, or -1 if the given integer is zero. More... | |
static int | lastBit (T x) |
Returns the index of the last true bit in the given integer, or -1 if the given integer is zero. More... | |
static T | nextPermutation (T x) |
Returns the next largest integer with the same number of true bits as x. More... | |
static int | bits (T x) |
Returns the number of bits that are set to 1 in the given integer. More... | |
An optimised class for bitwise analysis and manipulation of native data types.
The class BitManipulator<T> is used to manipulate an integer of type T as a sequence of bits. Here T must be an unsigned native integer type such as unsigned char, unsigned int, or unsigned long long.
Whilst BitManipulator has a generic implementation, all or most native types T have template specialisations that are carefully optimised (precisely what gets specialised depends upon properties of the compiler).
|
inherited |
Enumerator | |
---|---|
specialised | Indicates whether this class is a template specialisation of BitManipulatorByType with extra optimisations. This compile-time constant is set to 0 for the generic implementation of BitManipulatorByType, and 1 for all specialisations. |
anonymous enum |
Enumerator | |
---|---|
specialised | Indicates whether this class is a template specialisation of BitManipulator with extra optimisations. This compile-time constant is set to 0 for the generic implementation of BitManipulator, and 1 for all specialisations. |
|
inlinestaticinherited |
Returns the number of bits that are set to 1 in the given integer.
x | the integer of type T to examine. |
|
inlinestatic |
Returns the index of the first true
bit in the given integer, or -1 if the given integer is zero.
Bits are indexed from 0 upwards, starting at the least significant bit.
x | the integer of type T to examine. |
true
bit, or -1 if there are no true
bits.
|
inlinestatic |
Returns the index of the last true
bit in the given integer, or -1 if the given integer is zero.
Bits are indexed from 0 upwards, starting at the least significant bit.
x | the integer of type T to examine. |
true
bit, or -1 if there are no true
bits.
|
inlinestaticinherited |
Returns the next largest integer with the same number of true
bits as x.
If x is the largest such integer (i.e., x is of the form 111...1000...0), then this routine returns 0.
x | the integer of type T to examine. |
true
bits, or 0 if this is the largest such integer.