2012-07-18 14:59:03 -04:00
|
|
|
#pragma once
|
2023-03-31 23:18:41 -04:00
|
|
|
///@file
|
2003-07-14 10:23:11 +00:00
|
|
|
|
2009-03-28 20:51:33 +00:00
|
|
|
#include "hash.hh"
|
2003-07-14 10:23:11 +00:00
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
namespace nix {
|
2003-07-14 10:23:11 +00:00
|
|
|
|
2021-10-04 14:29:42 +02:00
|
|
|
class RefScanSink : public Sink
|
|
|
|
{
|
|
|
|
StringSet hashes;
|
|
|
|
StringSet seen;
|
|
|
|
|
|
|
|
std::string tail;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
RefScanSink(StringSet && hashes) : hashes(hashes)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
StringSet & getResult()
|
|
|
|
{ return seen; }
|
|
|
|
|
|
|
|
void operator () (std::string_view data) override;
|
|
|
|
};
|
|
|
|
|
2018-03-30 00:56:13 +02:00
|
|
|
struct RewritingSink : Sink
|
|
|
|
{
|
2023-03-17 15:51:08 +01:00
|
|
|
const StringMap rewrites;
|
2023-06-15 21:24:14 +02:00
|
|
|
std::string::size_type maxRewriteSize;
|
2023-03-17 15:51:08 +01:00
|
|
|
std::string prev;
|
2018-03-30 00:56:13 +02:00
|
|
|
Sink & nextSink;
|
|
|
|
uint64_t pos = 0;
|
|
|
|
|
|
|
|
std::vector<uint64_t> matches;
|
|
|
|
|
|
|
|
RewritingSink(const std::string & from, const std::string & to, Sink & nextSink);
|
2023-03-17 15:51:08 +01:00
|
|
|
RewritingSink(const StringMap & rewrites, Sink & nextSink);
|
2018-03-30 00:56:13 +02:00
|
|
|
|
2020-12-02 14:00:43 +01:00
|
|
|
void operator () (std::string_view data) override;
|
2018-03-30 00:56:13 +02:00
|
|
|
|
|
|
|
void flush();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HashModuloSink : AbstractHashSink
|
|
|
|
{
|
|
|
|
HashSink hashSink;
|
|
|
|
RewritingSink rewritingSink;
|
|
|
|
|
2023-11-28 14:20:27 +01:00
|
|
|
HashModuloSink(HashAlgorithm ha, const std::string & modulus);
|
2018-03-30 00:56:13 +02:00
|
|
|
|
2020-12-02 14:00:43 +01:00
|
|
|
void operator () (std::string_view data) override;
|
2018-03-30 00:56:13 +02:00
|
|
|
|
|
|
|
HashResult finish() override;
|
|
|
|
};
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
}
|