ClickHouse/src/IO/HashingReadBuffer.h

47 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
#include <IO/HashingWriteBuffer.h>
2021-02-04 23:14:17 +00:00
#include <IO/ReadBuffer.h>
namespace DB
{
2021-02-04 23:14:17 +00:00
/*
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.
*/
class HashingReadBuffer : public IHashingBuffer<ReadBuffer>
{
public:
2021-02-04 23:14:17 +00:00
explicit 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();
2017-05-28 14:29:40 +00:00
/// calculate hash from the data already read
2021-02-04 23:14:17 +00:00
if (!working_buffer.empty())
{
calculateHash(pos, working_buffer.end() - pos);
}
}
private:
bool nextImpl() override
{
in.position() = pos;
bool res = in.next();
working_buffer = in.buffer();
pos = in.position();
2021-07-05 20:02:24 +00:00
// `pos` may be different from working_buffer.begin() when using sophisticated ReadBuffers.
2020-07-31 14:53:41 +00:00
calculateHash(pos, working_buffer.end() - pos);
return res;
}
ReadBuffer & in;
};
2021-02-04 23:14:17 +00:00
}