Fennel: /home/pub/open/dev/fennel/lucidera/bitmap/LbmByteSegment.h Source File (original) (raw)

00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 #ifndef Fennel_LbmByteSegment_Included 00023 #define Fennel_LbmByteSegment_Included 00024 00025 #include "fennel/common/ByteBuffer.h" 00026 #include "fennel/lucidera/bitmap/LbmSegment.h" 00027 #include "fennel/tuple/TupleData.h" 00028 00029 FENNEL_BEGIN_NAMESPACE 00030 00035 class FENNEL_LBM_EXPORT LbmByteSegment 00036 { 00037 public: 00038 static const uint bitsInByte[]; 00039 00040 LbmByteNumber byteNum; 00041 PBuffer byteSeg; 00042 uint len; 00043 00044 inline void reset() 00045 { 00046 byteNum = (LbmByteNumber) 0; 00047 byteSeg = NULL; 00048 len = 0; 00049 } 00050 00054 inline LcsRid getSrid() const 00055 { 00056 return byteNumberToRid(byteNum); 00057 } 00058 00062 inline bool isNull() const 00063 { 00064 return byteSeg == NULL; 00065 } 00066 00070 inline LbmByteNumber getEnd() const 00071 { 00072 return byteNum + len; 00073 } 00074 00078 inline LcsRid getEndRid() const 00079 { 00080 return byteNumberToRid(getEnd()); 00081 } 00082 00090 void advanceToByteNum(LbmByteNumber newStartByteNum) 00091 { 00092
00093 if (isNull()) { 00094 return; 00095 } 00096 00097
00098 if (getEnd() <= newStartByteNum) { 00099 reset(); 00100 return; 00101 } 00102 00103
00104 if (byteNum < newStartByteNum) { 00105 uint diff = opaqueToInt(newStartByteNum - byteNum); 00106 byteNum += diff; 00107 byteSeg -= diff; 00108 len -= diff; 00109 } 00110 } 00111 00115 uint countBits() 00116 { 00117 return countBits(byteSeg - len + 1, len); 00118 } 00119 00124 static uint countBits(TupleDatum const &datum) 00125 { 00126 if (datum.pData == NULL || datum.cbData == 0) { 00127 return 1; 00128 } 00129 return countBits(datum.pData, datum.cbData); 00130 } 00131 00135 static uint countBits(PConstBuffer pBuf, uint len) 00136 { 00137 uint total = 0; 00138 for (uint i = 0; i < len; i++) { 00139 total += bitsInByte[pBuf[i]]; 00140 } 00141 return total; 00142 } 00143 00144 static void verifyBitsInByte() 00145 { 00146 for (uint i = 0; i < 256; i++) { 00147 uint slowBits = 0; 00148 for (uint j = 0; j < 8; j++) { 00149 if (i & (1 << j)) { 00150 slowBits++; 00151 } 00152 } 00153 assert (slowBits == bitsInByte[i]); 00154 } 00155 } 00156 00162 void print(std::ostream &output) 00163 { 00164 output << std::dec << opaqueToInt(byteNum) << "."; 00165 output << std::dec << len << " ("; 00166 for (uint i = 0; i < len; i++) { 00167 uint val = byteSeg[i]; 00168 if (i > 0) { 00169 output << ","; 00170 } 00171 output << std::hex << val; 00172 } 00173 output << ")" << std::endl; 00174 } 00175 }; 00176 00177 FENNEL_END_NAMESPACE 00178 00179 #endif 00180 00181