14 This class is used to construct a RLEVector.
17 class RLEEncoder : public VectorEncoder
20 RLEEncoder(usint block_bytes, usint superblock_size = VectorEncoder::SUPERBLOCK_SIZE);
23 void setBit(usint value);
24 void setRun(usint start, usint len);
26 // These versions try to combine the runs if possible.
27 void addBit(usint value);
28 void addRun(usint start, usint len);
29 void flush(); // Call this when finished.
31 inline void RLEncode(usint diff, usint len)
33 this->size += diff + len - 1;
35 this->buffer->writeDeltaCode(diff);
36 this->buffer->writeDeltaCode(len);
42 // These are not allowed.
44 RLEEncoder(const RLEEncoder&);
45 RLEEncoder& operator = (const RLEEncoder&);
50 This is a run-length encoded bit vector using delta coding.
53 class RLEVector : public BitVector
56 typedef RLEEncoder Encoder;
58 RLEVector(std::ifstream& file);
59 RLEVector(Encoder& encoder, usint universe_size);
62 //--------------------------------------------------------------------------
64 usint reportSize() const;
66 //--------------------------------------------------------------------------
68 class Iterator : public BitVector::Iterator
71 Iterator(const RLEVector& par);
74 usint rank(usint value, bool at_least = false);
76 usint select(usint index);
79 pair_type valueAfter(usint value);
80 pair_type nextValue();
82 pair_type selectRun(usint index, usint max_length);
83 pair_type selectNextRun(usint max_length);
85 bool isSet(usint value);
87 // Counts the number of 1-bit runs.
92 inline void valueLoop(usint value)
94 this->getSample(this->sampleForValue(value));
97 if(this->val >= value) { return; }
98 while(this->cur < this->block_items)
100 this->val += this->buffer.readDeltaCode();
102 this->run = this->buffer.readDeltaCode() - 1;
103 if(this->val >= value) { break; }
105 this->cur += this->run;
106 this->val += this->run;
107 if(this->val >= value)
109 this->run = this->val - value;
111 this->cur -= this->run;
118 // These are not allowed.
120 Iterator(const Iterator&);
121 Iterator& operator = (const Iterator&);
124 //--------------------------------------------------------------------------
128 // These are not allowed.
130 RLEVector(const RLEVector&);
131 RLEVector& operator = (const RLEVector&);
138 #endif // RLEVECTOR_H