X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=incbwt%2Fbits%2Frlevector.h;fp=incbwt%2Fbits%2Frlevector.h;h=7ba7f5cb951242207db30a8bb562238519d816a2;hb=13e254b7c0ee22dffbc7c3125cee0408f9b375da;hp=847ce58655ee3bab1979e8b58c0fb27b4845786a;hpb=e4b6bdc7cc2a1372e4d4dae50acac55cebcc7e9b;p=SXSI%2FTextCollection.git diff --git a/incbwt/bits/rlevector.h b/incbwt/bits/rlevector.h index 847ce58..7ba7f5c 100644 --- a/incbwt/bits/rlevector.h +++ b/incbwt/bits/rlevector.h @@ -20,9 +20,14 @@ class RLEEncoder : public VectorEncoder RLEEncoder(usint block_bytes, usint superblock_size = VectorEncoder::SUPERBLOCK_SIZE); ~RLEEncoder(); -// void setBit(usint value); + void setBit(usint value); void setRun(usint start, usint len); + // These versions try to combine the runs if possible. + void addBit(usint value); + void addRun(usint start, usint len); + void flush(); // Call this when finished. + inline void RLEncode(usint diff, usint len) { this->size += diff + len - 1; @@ -30,6 +35,14 @@ class RLEEncoder : public VectorEncoder this->buffer->writeDeltaCode(diff); this->buffer->writeDeltaCode(len); } + + protected: + pair_type run; + + // These are not allowed. + RLEEncoder(); + RLEEncoder(const RLEEncoder&); + RLEEncoder& operator = (const RLEEncoder&); }; @@ -40,57 +53,82 @@ class RLEEncoder : public VectorEncoder class RLEVector : public BitVector { public: + typedef RLEEncoder Encoder; + RLEVector(std::ifstream& file); - RLEVector(RLEEncoder& encoder, usint universe_size); + RLEVector(Encoder& encoder, usint universe_size); ~RLEVector(); //-------------------------------------------------------------------------- - usint rank(usint value, bool at_least = false); + usint reportSize() const; - usint select(usint index); - usint selectNext(); +//-------------------------------------------------------------------------- - pair_type valueAfter(usint value); - pair_type nextValue(); + class Iterator : public BitVector::Iterator + { + public: + Iterator(const RLEVector& par); + ~Iterator(); - pair_type selectRun(usint index, usint max_length); - pair_type selectNextRun(usint max_length); + usint rank(usint value, bool at_least = false); - bool isSet(usint value); + usint select(usint index); + usint selectNext(); -//-------------------------------------------------------------------------- + pair_type valueAfter(usint value); + pair_type nextValue(); - usint reportSize(); + pair_type selectRun(usint index, usint max_length); + pair_type selectNextRun(usint max_length); - protected: - usint run; + bool isSet(usint value); - inline void valueLoop(usint value) - { - this->getSample(this->sampleForValue(value)); - this->run = 0; - - if(this->val >= value) { return; } - while(this->cur < this->block_items) - { - this->val += this->buffer->readDeltaCode(); - this->cur++; - this->run = this->buffer->readDeltaCode() - 1; - if(this->val >= value) { break; } - - this->cur += this->run; - this->val += this->run; - if(this->val >= value) + // Counts the number of 1-bit runs. + usint countRuns(); + + protected: + + inline void valueLoop(usint value) { - this->run = this->val - value; - this->val = value; - this->cur -= this->run; - break; + this->getSample(this->sampleForValue(value)); + this->run = 0; + + if(this->val >= value) { return; } + while(this->cur < this->block_items) + { + this->val += this->buffer.readDeltaCode(); + this->cur++; + this->run = this->buffer.readDeltaCode() - 1; + if(this->val >= value) { break; } + + this->cur += this->run; + this->val += this->run; + if(this->val >= value) + { + this->run = this->val - value; + this->val = value; + this->cur -= this->run; + break; + } + this->run = 0; + } } - this->run = 0; - } - } + + // These are not allowed. + Iterator(); + Iterator(const Iterator&); + Iterator& operator = (const Iterator&); + }; + +//-------------------------------------------------------------------------- + + protected: + + // These are not allowed. + RLEVector(); + RLEVector(const RLEVector&); + RLEVector& operator = (const RLEVector&); };