示例#1
0
void SVSet::deleteVec(DLPSV* ps)
{
   /* delete last entries, in an SVECTOR and also in an DLPSV there is always the position -1 used for memorizing
    * the size; this is the reason why we need to delete max()+1 entries
    */
   if (list.last() == ps)
      removeLast(ps->max() + 1);
   /* merge space of predecessor with position which will be deleted, therefore we do not need to delete any
    * memory or do an expensive memmove
    *
    * @note an SVECTOR and also in an DLPSV memorize the size always on position -1; this is the reason why we
    *       need to set the new mem size to the old combined size + 2
    */
   else if (list.first() != ps)
   {
      SVector* prev = ps->prev();
      int sz = prev->size();
      prev->setMem(prev->max() + ps->max() + 2, prev->mem());
      prev->set_size(sz);
   }
   /* delete the front entries of the first list entry and correct the memory pointers in the vectors */
   /* @note we do this by merging the first both vectors, move the entries from the second vector up front, and
    *       correct the size
    */
   else
   {
      SVector* next = ps->next();
      int sz = next->size();
      int bothmax = next->max() + ps->max();
      int offset = 0;

      /* the first element does not need to start at the beginning of the data array; why ??? */
      while( &(this->SVSetBase::operator[](offset)) != ps->mem() )
      {
         ++offset;
         assert(offset < size());
      }

      /* move all entries of the second vector to the front */
      for(int j = 0; j <= sz; ++j)
      {
         this->SVSetBase::operator[](offset + j) = next->mem()[j];
      }

      /* correct the data memmory pointer and the maximal space */
      next->setMem(bothmax + 2, ps->mem());
      /* correct size */
      next->set_size(sz);
   }

   list.remove(ps);
}
示例#2
0
void SVSet::xtend(SVector& svec, int newmax)
{
   if (svec.max() < newmax)
   {
      if (possiblyUnusedMem * memFactor > memSize())
         memPack(); 

      assert(has(&svec));
      DLPSV* ps = static_cast<DLPSV*>( & svec );

      if (ps == list.last())
      {
         int sz = ps->size();
         ensureMem (newmax - ps->max() + 1);
         insert(memSize(), newmax - ps->max());
         ps->setMem (newmax + 1, ps->mem());
         ps->set_size( sz );
      }
      else
      {
         ensureMem(newmax + 1);
         SVector newps(newmax + 1, &last() + 1);
         int sz = ps->size();
         insert(memSize(), newmax + 1);
         newps = svec;

         if (ps != list.first())
         {
            SVector* prev = ps->prev();
            int prevsz = prev->size();
            prev->setMem (prev->max()
                           + ps->max() + 2, prev->mem());
            prev->set_size(prevsz);
            
            possiblyUnusedMem += ps->max();
         }
         list.remove(ps);
         list.append(ps);

         ps->setMem(newmax + 1, newps.mem());
         ps->set_size(sz);
      }
   }
}