aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/hyperloglog/hyperloglog_ut.cpp
diff options
context:
space:
mode:
authorvitamin-ca <vitamin-ca@yandex-team.ru>2022-02-10 16:50:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:46 +0300
commit33975e98548306c90ccdc156bc436408a213be00 (patch)
treef3f70f93263e848986d3f52e04e4e9a980e224b0 /library/cpp/hyperloglog/hyperloglog_ut.cpp
parenta175286682787b2d1213734c5be7458aaf594c1c (diff)
downloadydb-33975e98548306c90ccdc156bc436408a213be00.tar.gz
Restoring authorship annotation for <vitamin-ca@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/hyperloglog/hyperloglog_ut.cpp')
-rw-r--r--library/cpp/hyperloglog/hyperloglog_ut.cpp102
1 files changed, 51 insertions, 51 deletions
diff --git a/library/cpp/hyperloglog/hyperloglog_ut.cpp b/library/cpp/hyperloglog/hyperloglog_ut.cpp
index b987aa0fa4..efee7ea889 100644
--- a/library/cpp/hyperloglog/hyperloglog_ut.cpp
+++ b/library/cpp/hyperloglog/hyperloglog_ut.cpp
@@ -1,20 +1,20 @@
#include "hyperloglog.h"
-
-#include <util/generic/buffer.h>
-#include <util/random/mersenne.h>
-#include <util/stream/buffer.h>
-
+
+#include <util/generic/buffer.h>
+#include <util/random/mersenne.h>
+#include <util/stream/buffer.h>
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <cmath>
-
+
+#include <cmath>
+
Y_UNIT_TEST_SUITE(THyperLogLog) {
Y_UNIT_TEST(TestPrecision18) {
- TMersenne<ui64> rand;
-
+ TMersenne<ui64> rand;
+
auto counter = THyperLogLog::Create(18);
-
- static const std::pair<ui64, ui64> POINTS[] = {
+
+ static const std::pair<ui64, ui64> POINTS[] = {
{10, 10},
{100, 100},
{1000, 998},
@@ -24,44 +24,44 @@ Y_UNIT_TEST_SUITE(THyperLogLog) {
{10000000, 9983891},
{100000000, 100315572},
{1000000000, 998791445},
- //1:37: {10000000000, 10015943904}
- };
- ui64 unique = 0;
- for (const auto& pnt : POINTS) {
- while (unique < pnt.first) {
- const auto val = rand();
- counter.Update(val);
- ++unique;
- }
- const auto estimation = counter.Estimate();
- const auto delta = i64(estimation) - i64(unique);
- const auto error = double(delta) / unique;
- UNIT_ASSERT(std::abs(error) < 0.0032);
- UNIT_ASSERT_EQUAL(estimation, pnt.second);
- }
- {
+ //1:37: {10000000000, 10015943904}
+ };
+ ui64 unique = 0;
+ for (const auto& pnt : POINTS) {
+ while (unique < pnt.first) {
+ const auto val = rand();
+ counter.Update(val);
+ ++unique;
+ }
+ const auto estimation = counter.Estimate();
+ const auto delta = i64(estimation) - i64(unique);
+ const auto error = double(delta) / unique;
+ UNIT_ASSERT(std::abs(error) < 0.0032);
+ UNIT_ASSERT_EQUAL(estimation, pnt.second);
+ }
+ {
auto counter2 = THyperLogLog::Create(18);
- while (unique < 2000000000) {
- const auto val = rand();
- counter2.Update(val);
- ++unique;
- }
- const auto estimation = counter2.Estimate();
- UNIT_ASSERT_EQUAL(estimation, 1000013484);
-
- counter.Merge(counter2);
- UNIT_ASSERT_EQUAL(counter.Estimate(), 1998488794);
- }
-
- {
- TBufferStream stream;
- counter.Save(stream);
- UNIT_ASSERT_EQUAL(stream.Buffer().Size(), 1 + (1 << 18));
-
- stream.Rewind();
+ while (unique < 2000000000) {
+ const auto val = rand();
+ counter2.Update(val);
+ ++unique;
+ }
+ const auto estimation = counter2.Estimate();
+ UNIT_ASSERT_EQUAL(estimation, 1000013484);
+
+ counter.Merge(counter2);
+ UNIT_ASSERT_EQUAL(counter.Estimate(), 1998488794);
+ }
+
+ {
+ TBufferStream stream;
+ counter.Save(stream);
+ UNIT_ASSERT_EQUAL(stream.Buffer().Size(), 1 + (1 << 18));
+
+ stream.Rewind();
const auto copy = THyperLogLog::Load(stream);
-
- UNIT_ASSERT_EQUAL(counter.Estimate(), copy.Estimate());
- }
- }
-}
+
+ UNIT_ASSERT_EQUAL(counter.Estimate(), copy.Estimate());
+ }
+ }
+}