Changeset - ec2bd041e1de
[Not reviewed]
longmem
0 2 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-08-12 12:58:41
hy@ozderya.net
added clear method
2 files changed with 19 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/chunkedbuffer.cpp
Show inline comments
 
@@ -49,24 +49,40 @@ void ChunkedBuffer::addSamples(double* s
 
            chunk = addNewChunk(); // create a new chunk
 
        }
 

	
 
        // add data to chunk
 
        size_t c = std::min(chunk->left(), (size - i));
 
        chunk->addSamples(&samples[i], c);
 
        i += c;
 
    }
 

	
 
    _size += size;
 
}
 

	
 
void ChunkedBuffer::clear()
 
{
 
    // delete all chunks
 
    for (auto chunk : chunks)
 
    {
 
        delete chunk;
 
    }
 
    chunks.clear();
 

	
 
    numChunks = 0;
 
    _size = 0;
 

	
 
    // create first chunk
 
    addNewChunk();
 
}
 

	
 
DataChunk* ChunkedBuffer::addNewChunk()
 
{
 
    auto chunk = new DataChunk(_size, CHUNK_SIZE);
 
    chunks.append(chunk);
 
    return chunk;
 
}
 

	
 
size_t ChunkedBuffer::size() const
 
{
 
    return _size;
 
}
 

	
tests/test.cpp
Show inline comments
 
@@ -107,27 +107,27 @@ TEST_CASE("ChunkedBuffer adding data and
 

	
 
    // add data for second chunk
 
    b.addSamples(samples, N);
 
    REQUIRE(b.size() == CHUNK_SIZE+N);
 
    REQUIRE(b.boundingRect() == QRectF(0,10,CHUNK_SIZE+N,10));
 

	
 
    // add more data to make it 4 chunks
 
    double samples3[CHUNK_SIZE*3-N] = {0};
 
    b.addSamples(samples3, CHUNK_SIZE*3-N);
 
    REQUIRE(b.size() == CHUNK_SIZE*4);
 
    REQUIRE(b.boundingRect() == QRectF(0,10,CHUNK_SIZE*4,10));
 

	
 
    // TODO: clear
 
    // b.clear();
 
    // REQUIRE(b.size() == 0);
 
    // clear
 
    b.clear();
 
    REQUIRE(b.size() == 0);
 
}
 

	
 
TEST_CASE("ChunkedBuffer accessing data", "[memory]")
 
{
 
    ChunkedBuffer b;
 

	
 
    // prepare data
 
    double samples[CHUNK_SIZE*3];
 
    samples[0] = 10;
 
    samples[10] = 20;
 
    samples[CHUNK_SIZE-1] = 30;
 
    samples[CHUNK_SIZE] = 40;
0 comments (0 inline, 0 general)