#include <BitOverlay.h>
Inheritance diagram for Conjecture::BitOverlay:
******************************************************************
This class provides a variety of routines for analyzing the bits within a 32-bit value.
There are both static and instance versions of each method.
An "on" bit is 1, an "off" bit is 0.
IMPORTANT: This class can be used as simply a collection of static methods, OR it can be used as an "overlay", a means of adding semantics and functionality to an arbitrary integer. However, in order for it to be an overlay, NO VIRTUAL METHODS! We do not want a vtbl here! Includes parents, of course. Because of this, statically typing a variable as BitOverlay and assigning it an instance of the subclass BitInfo is NOT recommended.
FUTURE WORK: Analyze http://graphics.stanford.edu/~seander/bithacks.html and incorporate useful methods from there into this class!
See Also: BitOverlay64
Public Types | |
typedef unsigned int | Layout |
typedef int | BitPos |
typedef unsigned | BitCount |
Public Member Functions | |
BitOverlay (Layout data) | |
Layout | bits () const |
BitPos | findFirstHigh () const |
BitPos | findFirstLow () const |
BitCount | popc () const |
std::string | str () const |
BitCount | regions (int *largest=NULL, int *all=NULL) const |
Static Public Member Functions | |
static BitPos | FindFirstHigh (Layout val) |
static BitPos | FindFirstHighSlow (Layout val) |
static BitPos | FindFirstLow (Layout val) |
static int | _bx (Layout x) |
static BitCount | PopCount (Layout val) |
static BitCount | PopCountSlow (Layout val) |
static std::string | Str (Layout val) |
static BitCount | Regions (Layout val, int *largest=NULL, int *all=NULL) |
static void | Test (int argc=0, const char *argv[]=NULL) |
Static Public Attributes | |
static const BitPos | npos = 255 |
Protected Member Functions | |
void | bitsIs (const Layout &bits) |
|
A type for use in methods that return a bit count. |
|
A bit position. Bit position 0 is the lowest-order bit, and bit position 31 is the highest-order-bit. The special value 'npos' is used to represent "not present", and is outside the 0-31 range. NOTE: Although this type could be described using a single byte (the maximum bit position possible is 31, after all), it is defined as an 'int' because 'char' types get printed out as chars, not integers, when used in '<<' debugging operators. If size becomes relevant, it can be changed to 'unsigned char'. FUTURE FIX: A better name for this type should be found! |
|
The type describing the underlying value being analyzed. A typedef to make a BitOverlay64 implementation look as similar as possible to BitOverlay (and to make potential transitioning to a template implementation easier). |
|
Population Count: Returns the number of "on" bits. |
|
Returns the bit position of the most-significant "on" bit. NOTE: Some chipsets have a 'find-first-set' (ffs) instruction that implements this. I've renamed it because I want to distinguish ffh and ffl. |
|
Returns the bit position of the least-significant "on" bit. |
|
Returns number of "regions" of contiguous "on" pixels.
|
|
String representation of 'val' as a binary number. Currently always returns a string of length 32. Future extensions may add an optional arg specifying when we can truncate (could use FFS to establish minimum length). |
|
The Unit-testing method Reimplemented in Conjecture::BitInfo. |