LcsBitOps.h File Reference

Go to the source code of this file.

Typedefs

typedef uint8_t WidthVec [WIDTH_VECTOR_SIZE]
typedef WidthVecPWidthVec
typedef uint8_tPtrVec [WIDTH_VECTOR_SIZE]
typedef PtrVecPPtrVec
typedef void(*) PBitVecFuncPtr (uint16_t *v, const PtrVec p, uint pos)
typedef void(*) PByteBitVecFuncPtr (uint8_t *v, const PtrVec p, uint pos)

Functions

FENNEL_BEGIN_NAMESPACE void setBits (uint8_t *pB, uint nBits, uint whatBits, uint16_t v)
 Sets nBits(1,2,4) starting at whatBits in *pB, from the LSB of v.
void readBits (uint8_t b, uint nBits, uint fromBits, uint16_t *v, uint toBits)
 Copies nBits(1,2,4), starting at fromBits from byte B to uint16_t V, starting at toBits.
uint calcWidth (uint n)
 Calculates the # of bits it takes to encode n different values correct the number so that no more then 2 vectors (1,2,4,8,16) wide are required.
uint bitVecWidth (uint l, WidthVec w)
uint bitVecPtr (uint iCount, uint iW, WidthVec w, PtrVec p, uint8_t *pVec)
 Calculates the offsets of the bitVecs, returns the number of bytes the bitVecs will take.
uint sizeofBitVec (uint nRow, uint iW, WidthVec w)
 Returns size of bit vector.
void readBitVecs (uint16_t *v, uint iV, const WidthVec w, const PtrVec p, uint pos, uint count)
 Reads bit vectors.
void readBitVec0 (uint16_t *v, const PtrVec p, uint pos)
 Sets bit vector to 0.
void readBitVec16 (uint16_t *v, const PtrVec p, uint pos)
 Reads one row from a bit vector with 1 or 2 vectors only.
void readBitVec8 (uint16_t *v, const PtrVec p, uint pos)
 Reads an 8-bit vector.
void readBitVec4 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 4-bit vector.
void readBitVec2 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 2-bit vector.
void readBitVec1 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 1-bit vector.
void readBitVec12 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 12-bit vector (8 bits + 4 bits).
void readBitVec10 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 10-bit vector (8 bits + 2 bits).
void readBitVec9 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 9-bit vector (8 bits + 1 bit).
void readBitVec6 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 6 bit vector (4 bits + 2 bits).
void readBitVec5 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 5-bit vector (4 bits + 1 bit).
void readBitVec3 (uint16_t *v, const PtrVec p, uint pos)
 Reads a 3-bit vector (2 bits + 1 bit).

Variables

const uint WIDTH_VECTOR_SIZE = 4


Typedef Documentation

typedef void(*) PBitVecFuncPtr(uint16_t *v, const PtrVec p, uint pos)

Definition at line 97 of file LcsBitOps.h.

typedef void(*) PByteBitVecFuncPtr(uint8_t *v, const PtrVec p, uint pos)

Definition at line 98 of file LcsBitOps.h.

typedef PtrVec* PPtrVec

Definition at line 95 of file LcsBitOps.h.

typedef uint8_t* PtrVec[WIDTH_VECTOR_SIZE]

Definition at line 94 of file LcsBitOps.h.

typedef WidthVec* PWidthVec

Definition at line 93 of file LcsBitOps.h.

typedef uint8_t WidthVec[WIDTH_VECTOR_SIZE]

Definition at line 92 of file LcsBitOps.h.


Function Documentation

uint bitVecPtr ( uint  iCount,
uint  iW,
WidthVec  w,
PtrVec  p,
uint8_t pVec 
) [inline]

Calculates the offsets of the bitVecs, returns the number of bytes the bitVecs will take.

Parameters:
iCount number of entries
iW size of the vectors
w bitVec width vector
p bit vector that is set
pVec vector storage

Definition at line 135 of file LcsBitOps.h.

Referenced by LcsClusterDump::dump(), LcsClusterNodeWriter::moveFromIndexToTemp(), LcsClusterNodeWriter::moveFromTempToIndex(), LcsClusterNodeWriter::putCompressedBatch(), LcsClusterNodeWriter::rollBackLastBatch(), and LcsColumnReader::sync().

00137 {
00138     uint i;
00139     uint8_t *t;
00140 
00141     for (i = 0, t = pVec ; i < iW ; i++) {
00142         p[i] = t;
00143         t += ((w[i] * iCount + 7) / 8);
00144     }
00145 
00146     return t - pVec;
00147 }

uint bitVecWidth ( uint  l,
WidthVec  w 
) [inline]

Definition at line 103 of file LcsBitOps.h.

Referenced by LcsClusterDump::dump(), LcsClusterNodeWriter::moveFromIndexToTemp(), LcsClusterNodeWriter::moveFromTempToIndex(), LcsClusterNodeWriter::pickCompressionMode(), LcsClusterNodeWriter::putCompressedBatch(), LcsClusterNodeWriter::rollBackLastBatch(), and LcsColumnReader::sync().

00104 {
00105     uint8_t po2;
00106     uint iW;
00107     WidthVec t;
00108     int i,j;
00109 
00110     for (po2 = 1, iW = 0; l ; l >>= 1, po2 *= 2) {
00111         if (l & 0x1) {
00112             t[iW++] = po2;
00113         }
00114     }
00115 
00116     for (i = iW - 1, j = 0; i >= 0 ; w[j++] = t[i--]) {
00117     }
00118     return iW;
00119 }

uint calcWidth ( uint  n  )  [inline]

Calculates the # of bits it takes to encode n different values correct the number so that no more then 2 vectors (1,2,4,8,16) wide are required.

Returns:
number of bits required

Definition at line 54 of file LcsBitOps.h.

Referenced by LcsClusterNodeWriter::addValue(), LcsClusterDump::dump(), LcsClusterNodeWriter::moveFromIndexToTemp(), LcsClusterNodeWriter::moveFromTempToIndex(), LcsClusterNodeWriter::rollBackLastBatch(), LcsColumnReader::sync(), and LcsClusterNodeWriter::undoValue().

00055 {
00056     uint w;
00057 
00058     // find out how many bits are needed to represent n
00059     w = 0;
00060     if (n > 0) {
00061         n--;
00062     }
00063     while (n) {
00064         w++;
00065         n >>= 1;
00066     }
00067 
00068     // round up the width to a value which can be
00069     // represented by two bit vectors (where each vector
00070     // has length 1, 2, 4, 8, or 16
00071     switch (w) {
00072     case  7:
00073         w = 8;
00074         break;
00075     case 11:
00076         w = 12;
00077         break;
00078     case 13:
00079     case 14:
00080     case 15:
00081         w = 16;
00082         break;
00083     default:
00084         break;
00085     }
00086 
00087     return w;
00088 }

void readBits ( uint8_t  b,
uint  nBits,
uint  fromBits,
uint16_t v,
uint  toBits 
) [inline]

Copies nBits(1,2,4), starting at fromBits from byte B to uint16_t V, starting at toBits.

Definition at line 41 of file LcsBitOps.h.

Referenced by readBitVec1(), readBitVec10(), readBitVec12(), readBitVec2(), readBitVec3(), readBitVec4(), readBitVec5(), readBitVec6(), readBitVec9(), and readBitVecs().

00043 {
00044     *v |= (((b & (((1 << nBits) -1) << fromBits)) >> fromBits) << toBits);
00045 }

void readBitVec0 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Sets bit vector to 0.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 246 of file LcsBitOps.h.

Referenced by LcsColumnReader::sync().

00247 {
00248     // ARG_USED(p);
00249     // ARG_USED(pos);
00250     *v = 0;
00251 }

void readBitVec1 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 1-bit vector.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 322 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00323 {
00324     // clear the destination
00325     *v = 0;
00326     readBits(p[0][pos / 8], 1, pos % 8, v, 0);
00327 }

void readBitVec10 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 10-bit vector (8 bits + 2 bits).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 353 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00354 {
00355     *v = *(p[0] + pos);
00356     readBits(p[1][pos/4], 2, (pos*2) % 8, v, 8);
00357 }

void readBitVec12 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 12-bit vector (8 bits + 4 bits).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 338 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00339 {
00340     *v = *(p[0] + pos);
00341     readBits(p[1][pos/2], 4, (pos*4) % 8, v, 8);
00342 }

void readBitVec16 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads one row from a bit vector with 1 or 2 vectors only.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 262 of file LcsBitOps.h.

Referenced by LcsColumnReader::sync().

00263 {
00264     *v = *(p[0] + pos*2);
00265 }

void readBitVec2 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 2-bit vector.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 306 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00307 {
00308     // clear the destination
00309     *v = 0;
00310     readBits(p[0][pos/4], 2, (pos*2) % 8, v, 0);
00311 }

void readBitVec3 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 3-bit vector (2 bits + 1 bit).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 417 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00418 {
00419     // clear the destination
00420     *v = 0;
00421     readBits(p[0][pos / 4], 2, (pos * 2) % 8, v, 0);
00422     readBits(p[1][pos / 8], 1, pos % 8, v, 2);
00423 }

void readBitVec4 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 4-bit vector.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 290 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00291 {
00292     // clear the destination
00293     *v = 0;
00294     readBits(p[0][pos/2], 4, (pos*4) % 8, v, 0);
00295 }

void readBitVec5 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 5-bit vector (4 bits + 1 bit).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 400 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00401 {
00402     // clear the destination
00403     *v = 0;
00404     readBits(p[0][pos / 2], 4, (pos * 4) % 8, v, 0);
00405     readBits(p[1][pos / 8], 1, pos % 8, v, 4);
00406 }

void readBitVec6 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 6 bit vector (4 bits + 2 bits).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 383 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00384 {
00385     // clear the destination
00386     *v = 0;
00387     readBits(p[0][pos/2], 4, (pos*4) % 8, v, 0);
00388     readBits(p[1][pos/4], 2, (pos*2) % 8, v, 4);
00389 }

void readBitVec8 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads an 8-bit vector.

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 276 of file LcsBitOps.h.

Referenced by LcsColumnReader::sync().

00277 {
00278     *v = *(p[0] + pos);
00279 }

void readBitVec9 ( uint16_t v,
const PtrVec  p,
uint  pos 
) [inline]

Reads a 9-bit vector (8 bits + 1 bit).

Parameters:
v destination of ref numbers
p bitVec offsets
pos first row of interest

Definition at line 368 of file LcsBitOps.h.

References readBits().

Referenced by LcsColumnReader::sync().

00369 {
00370     *v = *(p[0] + pos);
00371     readBits(p[1][pos / 8], 1, pos % 8, v, 8);
00372 }

void readBitVecs ( uint16_t v,
uint  iV,
const WidthVec  w,
const PtrVec  p,
uint  pos,
uint  count 
) [inline]

Reads bit vectors.

Parameters:
v destination of ref numbers
iV # of bit vectors
w bitVec width vector
p bitVec offsets
pos first row of interest
count how many rows to read

Definition at line 184 of file LcsBitOps.h.

References readBits().

Referenced by LcsClusterDump::dump(), LcsColumnReader::readCompressedBatch(), and LcsClusterNodeWriter::rollBackLastBatch().

00187 {
00188     uint        i, j, k;
00189     uint        b;
00190 
00191     // clear the destination
00192     memset(v, 0, sizeof(uint16_t) * count);
00193 
00194     // read bit arrays
00195     for (i = 0, b = 0; i < iV; i++) {
00196         // w[i] contains the width of the bit vector
00197         // read append each vector bits into v[i], b is the bit position
00198         // of the next append
00199         switch (w[i]) {
00200         case 16:
00201             memcpy(v, p[i] + pos*2, sizeof(uint16_t) * count);
00202             break;
00203 
00204         case 8:
00205             for (j = 0; j < count; j++) {
00206                 v[j] = (p[i] + pos)[j];
00207             }
00208             break;
00209 
00210         case 4:
00211             for (j = 0, k = pos*4;  j < count; j++, k += 4) {
00212                 readBits(p[i][k / 8], 4, k % 8, &v[j], b);
00213             }
00214             break;
00215 
00216         case 2:
00217             for (j = 0, k = pos*2; j < count; j++, k += 2) {
00218                 readBits(p[i][k / 8], 2, k % 8, &v[j], b);
00219             }
00220             break;
00221 
00222         case 1:
00223             for (j = 0, k = pos; j < count; j++, k++) {
00224                 readBits(p[i][k / 8], 1, k % 8, &v[j], b);
00225             }
00226             break;
00227 
00228         default:
00229             assert(false);          // unsupported width
00230             break;
00231         }
00232 
00233         b += w[i];
00234     }
00235 }

FENNEL_BEGIN_NAMESPACE void setBits ( uint8_t pB,
uint  nBits,
uint  whatBits,
uint16_t  v 
) [inline]

Sets nBits(1,2,4) starting at whatBits in *pB, from the LSB of v.

Definition at line 32 of file LcsBitOps.h.

Referenced by LcsClusterNodeWriter::putCompressedBatch().

00033 {
00034     *pB |= ((v & ((1 << nBits) -1)) << whatBits);
00035 }

uint sizeofBitVec ( uint  nRow,
uint  iW,
WidthVec  w 
) [inline]

Returns size of bit vector.

Parameters:
nRow number of rows
iW size of the vectors
w bitVec width vector

Definition at line 158 of file LcsBitOps.h.

Referenced by LcsClusterNodeWriter::pickCompressionMode().

00159 {
00160     uint t;
00161     uint i;
00162 
00163     for (i = 0, t = 0; i < iW; i++) {
00164         t += ((w[i] * nRow + 7) / 8);
00165     }
00166     return t;
00167 }


Variable Documentation

const uint WIDTH_VECTOR_SIZE = 4

Definition at line 91 of file LcsBitOps.h.


Generated on Mon Jun 22 04:00:22 2009 for Fennel by  doxygen 1.5.1