+ class Iterator
+ {
+ public:
+ Iterator(const BitVector& par);
+ ~Iterator();
+
+ inline bool hasNext() const
+ {
+ return (this->sample.first + this->cur < this->parent.items - 1);
+ }
+
+ protected:
+ const BitVector& parent;
+
+ usint block;
+ pair_type sample;
+ usint cur, val, run; // cur == 0 is the sample
+ usint block_items;
+
+ ReadBuffer buffer, samples;
+
+ /*
+ These functions return the sample corresponding to the block the given
+ index/value might be found in. Parameters are assumed to be valid.
+ */
+ usint sampleForIndex(usint index);
+ usint sampleForValue(usint value);
+
+ inline void getSample(usint sample_number)
+ {
+ this->block = sample_number;
+ this->samples.goToItem(2 * sample_number);
+ this->sample.first = this->samples.readItem();
+ this->sample.second = this->samples.readItem();
+ this->cur = 0;
+ this->val = this->sample.second;
+ this->block_items = this->samples.readItem() - this->sample.first - 1;
+ this->buffer.moveBuffer(this->parent.array + (this->block * this->parent.block_size));
+ }
+
+ // These are not allowed.
+ Iterator();
+ Iterator(const Iterator&);
+ Iterator& operator = (const Iterator&);
+ };
+