mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
97f2a2213e
* Move some code outside dbms/src folder * Fix paths
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <IO/ReadBuffer.h>
|
|
#include <IO/HashingWriteBuffer.h>
|
|
|
|
namespace DB
|
|
{
|
|
/*
|
|
* Calculates the hash from the read data. When reading, the data is read from the nested ReadBuffer.
|
|
* Small pieces are copied into its own memory.
|
|
*/
|
|
class HashingReadBuffer : public IHashingBuffer<ReadBuffer>
|
|
{
|
|
public:
|
|
HashingReadBuffer(ReadBuffer & in_, size_t block_size_ = DBMS_DEFAULT_HASHING_BLOCK_SIZE) :
|
|
IHashingBuffer<ReadBuffer>(block_size_), in(in_)
|
|
{
|
|
working_buffer = in.buffer();
|
|
pos = in.position();
|
|
|
|
/// calculate hash from the data already read
|
|
if (working_buffer.size())
|
|
{
|
|
calculateHash(pos, working_buffer.end() - pos);
|
|
}
|
|
}
|
|
|
|
private:
|
|
bool nextImpl() override
|
|
{
|
|
in.position() = pos;
|
|
bool res = in.next();
|
|
working_buffer = in.buffer();
|
|
pos = in.position();
|
|
|
|
calculateHash(working_buffer.begin(), working_buffer.size());
|
|
|
|
return res;
|
|
}
|
|
|
|
private:
|
|
ReadBuffer & in;
|
|
};
|
|
}
|