2014-06-06 09:14:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/HashingWriteBuffer.h>
|
2014-06-06 09:14:51 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
/*
|
2017-05-28 14:29:40 +00:00
|
|
|
* 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.
|
2014-06-06 09:14:51 +00:00
|
|
|
*/
|
2014-06-06 14:50:29 +00:00
|
|
|
class HashingReadBuffer : public IHashingBuffer<ReadBuffer>
|
2014-06-06 09:14:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-07 10:40:58 +00:00
|
|
|
HashingReadBuffer(ReadBuffer & in_, size_t block_size_ = DBMS_DEFAULT_HASHING_BLOCK_SIZE) :
|
|
|
|
IHashingBuffer<ReadBuffer>(block_size_), in(in_)
|
2017-04-01 07:20:54 +00:00
|
|
|
{
|
|
|
|
working_buffer = in.buffer();
|
|
|
|
pos = in.position();
|
2014-06-06 09:14:51 +00:00
|
|
|
|
2017-05-28 14:29:40 +00:00
|
|
|
/// calculate hash from the data already read
|
2017-04-01 07:20:54 +00:00
|
|
|
if (working_buffer.size())
|
|
|
|
{
|
|
|
|
calculateHash(pos, working_buffer.end() - pos);
|
|
|
|
}
|
|
|
|
}
|
2014-06-06 09:14:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
bool nextImpl() override
|
|
|
|
{
|
|
|
|
in.position() = pos;
|
|
|
|
bool res = in.next();
|
|
|
|
working_buffer = in.buffer();
|
|
|
|
pos = in.position();
|
2014-06-06 13:50:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
calculateHash(working_buffer.begin(), working_buffer.size());
|
2014-06-06 13:50:09 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
|
|
|
}
|
2014-06-06 09:14:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
ReadBuffer & in;
|
2014-06-06 09:14:51 +00:00
|
|
|
};
|
|
|
|
}
|