00001 # ifndef Conjecture_BitOverlay_h
00002 # define Conjecture_BitOverlay_h Conjecture_BitInfo_h
00003
00004
00005
00006
00007
00008
00009 # include "Root.h"
00010 # include <string>
00011
00012 namespace Conjecture {
00013
00042 class BitOverlay : public Root {
00043 public:
00052 typedef unsigned int Layout;
00053
00071 typedef int BitPos;
00072 static const BitPos npos = 255;
00073
00078 typedef unsigned BitCount;
00079
00080 inline BitOverlay(Layout data) { this->bitsIs(data); }
00081
00082
00083 inline Layout bits() const { return this->_bits; }
00084
00085
00086
00095 static BitPos FindFirstHigh(Layout val);
00096 inline BitPos findFirstHigh() const { return FindFirstHigh(this->_bits); }
00097 static BitPos FindFirstHighSlow(Layout val);
00098
00103 static BitPos FindFirstLow(Layout val);
00104 inline BitPos findFirstLow() const { return FindFirstLow(this->_bits); }
00105
00110 static inline int _bx(Layout x) { return (x - ((x>>1)&0x77777777) - ((x>>2)&0x33333333) - ((x>>3)&0x11111111)); }
00111 static inline BitCount PopCount(Layout val) { return (((_bx(val)+(_bx(val)>>4)) & 0x0F0F0F0F) % 255); }
00112 inline BitCount popc() const { return PopCount(this->_bits); }
00113 static BitCount PopCountSlow(Layout val);
00114
00123 static std::string Str(Layout val);
00124 inline std::string str() const { return Str(this->_bits); }
00125
00134 static BitCount Regions(Layout val, int* largest = NULL, int* all = NULL);
00135 inline BitCount regions(int* largest = NULL, int* all = NULL) const { return Regions(this->_bits, largest, all); }
00136
00141 static void Test(int argc = 0, const char* argv[] = NULL);
00142
00143 protected:
00144
00145 inline void bitsIs(const Layout & bits) { this->_bits = bits; }
00146
00147
00148
00149 private:
00150
00151 inline Layout & bitsRef() { return this->_bits; }
00152
00153
00154
00155
00156 Layout _bits;
00157 };
00158 }
00159
00160 # endif // Conjecture_BitOverlay_h
00161