Added RLCSA index option
[SXSI/TextCollection.git] / incbwt / bits / deltavector.cpp
index a543f6b..66f30be 100644 (file)
@@ -11,13 +11,14 @@ DeltaVector::DeltaVector(std::ifstream& file) :
   BitVector(file)
 {
 }
+
 DeltaVector::DeltaVector(std::FILE * file) :
   BitVector(file)
 {
 }
 
 
-DeltaVector::DeltaVector(DeltaEncoder& encoder, usint universe_size) :
+DeltaVector::DeltaVector(Encoder& encoder, usint universe_size) :
   BitVector(encoder, universe_size)
 {
 }
@@ -29,14 +30,35 @@ DeltaVector::~DeltaVector()
 //--------------------------------------------------------------------------
 
 usint
-DeltaVector::rank(usint value, bool at_least)
+DeltaVector::reportSize() const
+{
+  usint bytes = sizeof(*this);
+  bytes += BitVector::reportSize();
+  return bytes;
+}
+
+//--------------------------------------------------------------------------
+
+DeltaVector::Iterator::Iterator(const DeltaVector& par) :
+  BitVector::Iterator(par)
+{
+}
+
+DeltaVector::Iterator::~Iterator()
 {
-  if(value >= this->size) { return this->items; }
+}
+
+usint
+DeltaVector::Iterator::rank(usint value, bool at_least)
+{
+  const DeltaVector& par = (const DeltaVector&)(this->parent);
+
+  if(value >= par.size) { return par.items; }
   this->getSample(this->sampleForValue(value));
 
   while(this->cur < this->block_items && this->val < value)
   {
-    this->val += this->buffer->readDeltaCode();
+    this->val += this->buffer.readDeltaCode();
     this->cur++;
   }
 
@@ -47,22 +69,24 @@ DeltaVector::rank(usint value, bool at_least)
 }
 
 usint
-DeltaVector::select(usint index)
+DeltaVector::Iterator::select(usint index)
 {
-  if(index >= this->items) { return this->size; }
+  const DeltaVector& par = (const DeltaVector&)(this->parent);
+
+  if(index >= par.items) { return par.size; }
   this->getSample(this->sampleForIndex(index));
 
   usint lim = index - this->sample.first;
   for(; this->cur < lim; this->cur++)
   {
-    this->val += this->buffer->readDeltaCode();
+    this->val += this->buffer.readDeltaCode();
   }
 
   return this->val;
 }
 
 usint
-DeltaVector::selectNext()
+DeltaVector::Iterator::selectNext()
 {
   if(this->cur >= this->block_items)
   {
@@ -71,19 +95,21 @@ DeltaVector::selectNext()
   }
 
   this->cur++;
-  this->val += this->buffer->readDeltaCode();
+  this->val += this->buffer.readDeltaCode();
   return this->val;
 }
 
 pair_type
-DeltaVector::valueAfter(usint value)
+DeltaVector::Iterator::valueAfter(usint value)
 {
-  if(value >= this->size) { return pair_type(this->size, this->items); }
+  const DeltaVector& par = (const DeltaVector&)(this->parent);
+
+  if(value >= par.size) { return pair_type(par.size, par.items); }
   this->getSample(this->sampleForValue(value));
 
   while(this->cur < this->block_items && this->val < value)
   {
-    this->val += this->buffer->readDeltaCode();
+    this->val += this->buffer.readDeltaCode();
     this->cur++;
   }
   if(this->val < value)
@@ -95,7 +121,7 @@ DeltaVector::valueAfter(usint value)
 }
 
 pair_type
-DeltaVector::nextValue()
+DeltaVector::Iterator::nextValue()
 {
   if(this->cur >= this->block_items)
   {
@@ -104,31 +130,33 @@ DeltaVector::nextValue()
   }
 
   this->cur++;
-  this->val += this->buffer->readDeltaCode();
+  this->val += this->buffer.readDeltaCode();
   return pair_type(this->val, this->sample.first + this->cur);
 }
 
 pair_type
-DeltaVector::selectRun(usint index, usint max_length)
+DeltaVector::Iterator::selectRun(usint index, usint max_length)
 {
   return pair_type(this->select(index), 0);
 }
 
 pair_type
-DeltaVector::selectNextRun(usint max_length)
+DeltaVector::Iterator::selectNextRun(usint max_length)
 {
   return pair_type(this->selectNext(), 0);
 }
 
 bool
-DeltaVector::isSet(usint value)
+DeltaVector::Iterator::isSet(usint value)
 {
-  if(value >= this->size) { return false; }
+  const DeltaVector& par = (const DeltaVector&)(this->parent);
+
+  if(value >= par.size) { return false; }
   this->getSample(this->sampleForValue(value));
 
   while(this->cur < this->block_items && this->val < value)
   {
-    this->val += this->buffer->readDeltaCode();
+    this->val += this->buffer.readDeltaCode();
     this->cur++;
   }
 
@@ -137,16 +165,6 @@ DeltaVector::isSet(usint value)
 
 //--------------------------------------------------------------------------
 
-usint
-DeltaVector::reportSize()
-{
-  usint bytes = sizeof(*this);
-  bytes += BitVector::reportSize();
-  return bytes;
-}
-
-//--------------------------------------------------------------------------
-
 DeltaEncoder::DeltaEncoder(usint block_bytes, usint superblock_size) :
   VectorEncoder(block_bytes, superblock_size)
 {
@@ -175,5 +193,30 @@ DeltaEncoder::setBit(usint value)
   this->addNewBlock();
 }
 
+void
+DeltaEncoder::setRun(usint start, usint len)
+{
+  for(usint i = start; i < start + len; i++)
+  {
+    this->setBit(i);
+  }
+}
+
+void
+DeltaEncoder::addBit(usint value)
+{
+  this->setBit(value);
+}
+
+void
+DeltaEncoder::addRun(usint start, usint len)
+{
+  this->setRun(start, len);
+}
+
+void
+DeltaEncoder::flush()
+{
+}
 
 } // namespace CSA