Esempio n. 1
0
    /**
     * @brief Loads the next chunk.
     *
     * If the current chunk was the last chunk in the array a new chunk is created.
     * Otherwise the old chunk is reset and loaded as current chunk.
     *
     * Always the position of the nested chunk vector is stored.
     */
    CODI_NO_INLINE void nextChunk() {
      curChunk->store();

      curChunkIndex += 1;
      if(chunks.size() == curChunkIndex) {
        curChunk = new ChunkData(chunkSize);
        chunks.push_back(curChunk);
        positions.push_back(nested->getPosition());
      } else {
        curChunk = chunks[curChunkIndex];
        curChunk->reset();
        positions[curChunkIndex] = nested->getPosition();
      }
    }
Esempio n. 2
0
    /**
     * @brief Initialize the nested vector.
     *
     * Can only be called once.
     *
     * @param[in,out] v  The nested vector.
     */
    void setNested(NestedVector* v) {
      // Set nested is only called once during the initialization.
      codiAssert(this->nested == NULL);

      this->nested = v;

      curChunk = new ChunkData(chunkSize);
      chunks.push_back(curChunk);
      positions.push_back(nested->getZeroPosition());
    }
Esempio n. 3
0
    CODI_INLINE void forEachChunkForward(FunctionObject& function, bool recursive, Args&&... args) {

      for(size_t chunkPos = 0; chunkPos < chunks.size(); ++chunkPos) {

        function(chunks[chunkPos], std::forward<Args>(args)...);
      }

      if(recursive) {
        nested->forEachChunkForward(function, recursive, std::forward<Args>(args)...);
      }
    }
Esempio n. 4
0
    /**
     * @brief Ensures that enough chunks are allocated so that totalSize data items can be stored.
     * @param totalSize   The number of data items which should be available.
     */
    void resize(const size_t& totalSize) {
      size_t noOfChunks = totalSize / chunkSize;
      if(0 != totalSize % chunkSize) {
        noOfChunks += 1;
      }

      for(size_t i = chunks.size(); i < noOfChunks; ++i) {
        chunks.push_back(new ChunkData(chunkSize));
        positions.push_back(nested->getPosition());
      }
    }
Esempio n. 5
0
 /**
  * @brief Creates one chunk and loads it.
  * @param chunkSize   The size for the chunks.
  * @param    nested   The nested chunk vector.
  */
 ChunkVector(const size_t& chunkSize, NestedVector& nested) :
   chunks(),
   positions(),
   curChunk(NULL),
   curChunkIndex(0),
   chunkSize(chunkSize),
   nested(nested)
 {
   curChunk = new ChunkData(chunkSize);
   chunks.push_back(curChunk);
   positions.push_back(nested.getPosition());
 }
Esempio n. 6
0
    /**
     * @brief Swap the contents of this chunk vector with the contents of the other
     *        chunk vector.
     *
     * On standard containers the default std::swap method is used.
     * The method is called also on the nested vector.
     *
     * @param[in,out] other  The other chunk vector.
     */
    void swap(ChunkVector<ChunkData, NestedVector>& other) {
      std::swap(chunks, other.chunks);
      std::swap(positions, other.positions);
      std::swap(curChunkIndex, other.curChunkIndex);
      std::swap(chunkSize, other.chunkSize);

      curChunk = chunks[curChunkIndex];
      other.curChunk = other.chunks[other.curChunkIndex];

      nested->swap(*other.nested);

    }
Esempio n. 7
0
    /**
     * @brief Release all the memory, that the chunk vector has acquired.
     *
     * Reverts the chunk vector into its initial state after the construction.
     * Only the memory of one chunk stays allocated.
     */
    void resetHard() {
      for(size_t i = 1; i < chunks.size(); ++i) {
        delete chunks[i];
      }

      chunks.resize(1);
      positions.resize(1);
      curChunk = chunks[0];
      curChunk->load();

      curChunk->setUsedSize(0);
      curChunkIndex = 0;

      nested->resetHard();
    }
Esempio n. 8
0
    /**
     * @brief Resets the chunk vector to the given position.
     *
     * This method will call reset on all chunks which are behind the
     * given position.
     *
     * It calls also reset on the nested chunk vector.
     *
     * @param pos   The position to reset to.
     */
    void reset(const Position& pos) {
      codiAssert(pos.chunk < chunks.size());
      codiAssert(pos.data <= chunkSize);

      for(size_t i = curChunkIndex; i > pos.chunk; --i) {
        chunks[i]->reset();
      }

      curChunk = chunks[pos.chunk];
      curChunk->load();
      curChunk->setUsedSize(pos.data);
      curChunkIndex = pos.chunk;

      nested->reset(pos.inner);
    }
Esempio n. 9
0
 /**
  * @brief Get the zero position of the chunk vector and the nested vectors.
  * @return The zero position of the chunk vector.
  */
 CODI_INLINE Position getZeroPosition() const {
   return Position(0, 0, nested->getZeroPosition());
 }
Esempio n. 10
0
 /**
  * @brief Get the position of the chunk vector and the nested vectors.
  * @return The position of the chunk vector.
  */
 CODI_INLINE Position getPosition() const {
   return Position(curChunkIndex, curChunk->getUsedSize(), nested->getPosition());
 }