diff options
author | v-mak33v <v-mak33v@yandex-team.ru> | 2022-02-10 16:50:50 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:50 +0300 |
commit | fd57eb4948385b403f53b2f711399e516d46dcac (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/hyperloglog/hyperloglog.h | |
parent | b563943b467b077146b7f7dab9d0d31f786d1515 (diff) | |
download | ydb-fd57eb4948385b403f53b2f711399e516d46dcac.tar.gz |
Restoring authorship annotation for <v-mak33v@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/hyperloglog/hyperloglog.h')
-rw-r--r-- | library/cpp/hyperloglog/hyperloglog.h | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/library/cpp/hyperloglog/hyperloglog.h b/library/cpp/hyperloglog/hyperloglog.h index 2b9725dc6e..e79ee0ed77 100644 --- a/library/cpp/hyperloglog/hyperloglog.h +++ b/library/cpp/hyperloglog/hyperloglog.h @@ -1,64 +1,64 @@ #pragma once #include <util/system/types.h> -#include <util/stream/input.h> -#include <util/generic/array_ref.h> +#include <util/stream/input.h> +#include <util/generic/array_ref.h> #include <vector> class IOutputStream; -class THyperLogLogBase { -protected: - explicit THyperLogLogBase(unsigned precision); +class THyperLogLogBase { +protected: + explicit THyperLogLogBase(unsigned precision); public: static const constexpr unsigned PRECISION_MIN = 4; - + static const constexpr unsigned PRECISION_MAX = 18; void Update(ui64 hash); - void Merge(const THyperLogLogBase& rh); + void Merge(const THyperLogLogBase& rh); ui64 Estimate() const; void Save(IOutputStream& out) const; -protected: - unsigned Precision; - - TArrayRef<ui8> RegistersRef; -}; - -template <typename Alloc> -class THyperLogLogWithAlloc : public THyperLogLogBase { -private: - explicit THyperLogLogWithAlloc(unsigned precision) - : THyperLogLogBase(precision) { - Registers.resize(1u << precision); - RegistersRef = MakeArrayRef(Registers); +protected: + unsigned Precision; + + TArrayRef<ui8> RegistersRef; +}; + +template <typename Alloc> +class THyperLogLogWithAlloc : public THyperLogLogBase { +private: + explicit THyperLogLogWithAlloc(unsigned precision) + : THyperLogLogBase(precision) { + Registers.resize(1u << precision); + RegistersRef = MakeArrayRef(Registers); + } + +public: + THyperLogLogWithAlloc(THyperLogLogWithAlloc&&) = default; + + THyperLogLogWithAlloc& operator=(THyperLogLogWithAlloc&&) = default; + + static THyperLogLogWithAlloc Create(unsigned precision) { + return THyperLogLogWithAlloc(precision); + } + + static THyperLogLogWithAlloc Load(IInputStream& in) { + char precision = {}; + Y_ENSURE(in.ReadChar(precision)); + auto res = Create(precision); + in.LoadOrFail(res.Registers.data(), res.Registers.size() * sizeof(res.Registers.front())); + return res; } -public: - THyperLogLogWithAlloc(THyperLogLogWithAlloc&&) = default; - - THyperLogLogWithAlloc& operator=(THyperLogLogWithAlloc&&) = default; - - static THyperLogLogWithAlloc Create(unsigned precision) { - return THyperLogLogWithAlloc(precision); - } - - static THyperLogLogWithAlloc Load(IInputStream& in) { - char precision = {}; - Y_ENSURE(in.ReadChar(precision)); - auto res = Create(precision); - in.LoadOrFail(res.Registers.data(), res.Registers.size() * sizeof(res.Registers.front())); - return res; - } - private: - std::vector<ui8, Alloc> Registers; + std::vector<ui8, Alloc> Registers; }; - -using THyperLogLog = THyperLogLogWithAlloc<std::allocator<ui8>>; + +using THyperLogLog = THyperLogLogWithAlloc<std::allocator<ui8>>; |