diff options
author | serxa <serxa@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:08 +0300 |
commit | d6d7db348c2cc64e71243cab9940ee6778f4317d (patch) | |
tree | bac67f42a02f9368eb4d329f5d79b77d0a6adc18 /library/cpp/lwtrace/mon/analytics/data.h | |
parent | 8d57b69dee81198a59c39e64704f7dc9f04b4fbf (diff) | |
download | ydb-d6d7db348c2cc64e71243cab9940ee6778f4317d.tar.gz |
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/lwtrace/mon/analytics/data.h')
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/data.h | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/library/cpp/lwtrace/mon/analytics/data.h b/library/cpp/lwtrace/mon/analytics/data.h index 4b643fe20b..7aeedbdd5e 100644 --- a/library/cpp/lwtrace/mon/analytics/data.h +++ b/library/cpp/lwtrace/mon/analytics/data.h @@ -1,15 +1,15 @@ -#pragma once - +#pragma once + #include <util/generic/string.h> -#include <util/generic/hash.h> +#include <util/generic/hash.h> #include <util/generic/vector.h> #include <util/string/builder.h> #include <util/string/cast.h> - + #include <variant> -namespace NAnalytics { - +namespace NAnalytics { + using TRowValue = std::variant<i64, ui64, double, TString>; TString ToString(const TRowValue& val) { @@ -22,7 +22,7 @@ TString ToString(const TRowValue& val) { struct TRow : public THashMap<TString, TRowValue> { TString Name; - + template<typename T> bool Get(const TString& name, T& value) const { if constexpr (std::is_same_v<double, T>) { @@ -30,9 +30,9 @@ struct TRow : public THashMap<TString, TRowValue> { value = 1.0; return true; } - } - auto iter = find(name); - if (iter != end()) { + } + auto iter = find(name); + if (iter != end()) { try { value = std::get<T>(iter->second); return true; @@ -51,58 +51,58 @@ struct TRow : public THashMap<TString, TRowValue> { auto iter = find(name); if (iter != end()) { value = ToString(iter->second); - return true; - } + return true; + } return false; - } -}; - + } +}; + using TAttributes = THashMap<TString, TString>; - + struct TTable : public TVector<TRow> { - TAttributes Attributes; -}; - + TAttributes Attributes; +}; + struct TMatrix : public TVector<double> { - size_t Rows; - size_t Cols; - - explicit TMatrix(size_t rows = 0, size_t cols = 0) + size_t Rows; + size_t Cols; + + explicit TMatrix(size_t rows = 0, size_t cols = 0) : TVector<double>(rows * cols) - , Rows(rows) - , Cols(cols) - {} - - void Reset(size_t rows, size_t cols) - { - Rows = rows; - Cols = cols; - clear(); - resize(rows * cols); - } - - double& Cell(size_t row, size_t col) - { - Y_VERIFY(row < Rows); - Y_VERIFY(col < Cols); - return operator[](row * Cols + col); - } - - double Cell(size_t row, size_t col) const - { - Y_VERIFY(row < Rows); - Y_VERIFY(col < Cols); - return operator[](row * Cols + col); - } - - double CellSum() const - { - double sum = 0.0; - for (double x : *this) { - sum += x; - } - return sum; - } -}; - -} + , Rows(rows) + , Cols(cols) + {} + + void Reset(size_t rows, size_t cols) + { + Rows = rows; + Cols = cols; + clear(); + resize(rows * cols); + } + + double& Cell(size_t row, size_t col) + { + Y_VERIFY(row < Rows); + Y_VERIFY(col < Cols); + return operator[](row * Cols + col); + } + + double Cell(size_t row, size_t col) const + { + Y_VERIFY(row < Rows); + Y_VERIFY(col < Cols); + return operator[](row * Cols + col); + } + + double CellSum() const + { + double sum = 0.0; + for (double x : *this) { + sum += x; + } + return sum; + } +}; + +} |