14 This class is used to construct a NibbleVector.
17 class NibbleEncoder : public VectorEncoder
20 NibbleEncoder(usint block_bytes, usint superblock_size = VectorEncoder::SUPERBLOCK_SIZE);
23 void setBit(usint value);
24 void setRun(usint start, usint len);
26 // FIXME for gap encoding
27 inline void nibbleEncode(usint diff, usint len)
29 this->size += diff + len - 1;
31 this->buffer->writeNibbleCode(diff);
32 this->buffer->writeNibbleCode(len);
37 // These are not allowed.
39 NibbleEncoder(const NibbleEncoder&);
40 NibbleEncoder& operator = (const NibbleEncoder&);
45 This bit vector uses nibble coding. Each block is either run-length encoded or
46 gap encoded, depending on the first nibble.
48 // FIXME reverting to gap encoding not implemented yet
51 class NibbleVector : public BitVector
54 typedef NibbleEncoder Encoder;
56 NibbleVector(std::ifstream& file);
57 NibbleVector(Encoder& encoder, usint universe_size);
60 //--------------------------------------------------------------------------
62 usint reportSize() const;
64 //--------------------------------------------------------------------------
66 class Iterator : public BitVector::Iterator
69 Iterator(const NibbleVector& par);
72 usint rank(usint value, bool at_least = false);
74 usint select(usint index);
77 pair_type valueAfter(usint value);
78 pair_type nextValue();
80 pair_type selectRun(usint index, usint max_length);
81 pair_type selectNextRun(usint max_length);
83 bool isSet(usint value);
85 // Counts the number of 1-bit runs.
88 static const usint GAP_ENCODING = 0;
89 static const usint RUN_LENGTH_ENCODING = 1;
93 // FIXME for gap encoding
94 inline void valueLoop(usint value)
96 this->getSample(this->sampleForValue(value));
98 if(this->val >= value) { return; }
99 while(this->cur < this->block_items)
101 this->val += this->buffer.readNibbleCode();
103 this->run = this->buffer.readNibbleCode() - 1;
104 if(this->val >= value) { break; }
106 this->cur += this->run;
107 this->val += this->run;
108 if(this->val >= value)
110 this->run = this->val - value;
112 this->cur -= this->run;
119 inline void getSample(usint sample_number)
121 BitVector::Iterator::getSample(sample_number);
123 // this->use_rle = this->buffer.readNibble();
128 // These are not allowed.
130 Iterator(const Iterator&);
131 Iterator& operator = (const Iterator&);
134 //--------------------------------------------------------------------------
138 // These are not allowed.
140 NibbleVector(const NibbleVector&);
141 NibbleVector& operator = (const NibbleVector&);
148 #endif // NIBBLEVECTOR_H