1#include <vkdb/time_series_key.h>
5 auto timestamp_end{
str.find(
'}')};
6 auto metric_start{
str.find(
'{', timestamp_end) + 1};
7 auto metric_end{
str.find(
'}', metric_start)};
8 auto tags_start{
str.find(
'{', metric_end) + 1};
9 auto tags_end{
str.find(
'}', tags_start)};
11 timestamp_ = std::stoull(
str.substr(1, timestamp_end - 1));
12 metric_ = {
str.substr(metric_start, metric_end - metric_start)};
13 auto tags_str{
str.substr(tags_start, tags_end - tags_start)};
17 std::istringstream ss{tags_str};
18 while (std::getline(ss, key,
':')) {
19 std::getline(ss, value,
',');
23 str_ = std::move(
str);
24 hash_ = std::hash<std::string>{}(str_);
32 : timestamp_{timestamp}
33 , metric_{std::move(metric)}
34 , tags_{std::move(tags)} {
36 ss <<
"{" << std::setw(TIMESTAMP_WIDTH) << std::setfill(
'0');
37 ss << timestamp_ <<
"}{" << metric_ <<
"}{";
38 for (
const auto& [key, value] : tags_) {
39 ss << key <<
":" << value <<
",";
41 ss.seekp(-!tags_.empty(), std::ios_base::end);
44 hash_ = std::hash<std::string>{}(str_);
48 return hash_ == other.hash_;
52 return !(*
this == other);
56 if (other.hash_ == MIN_TIME_SERIES_KEY_HASH) {
59 if (hash_ == MIN_TIME_SERIES_KEY_HASH) {
62 if (hash_ == MAX_TIME_SERIES_KEY_HASH) {
65 if (other.hash_ == MAX_TIME_SERIES_KEY_HASH) {
68 if (timestamp_ != other.timestamp_) {
69 return timestamp_ < other.timestamp_;
71 if (metric_ != other.metric_) {
72 return metric_ < other.metric_;
74 return tags_ < other.tags_;
82 return !(*
this > other);
86 return !(*
this < other);
Represents a key in vkdb.
const TagTable & tags() const noexcept
Get the tags.
TimeSeriesKey() noexcept=default
Construct a new TimeSeriesKey object.
Metric metric() const noexcept
Get the metric.
bool operator>=(const TimeSeriesKey &other) const noexcept
Greater-than-or-equal-to operator.
bool operator==(const TimeSeriesKey &other) const noexcept
Equality operator.
bool operator<=(const TimeSeriesKey &other) const noexcept
Less-than-or-equal-to operator.
bool operator>(const TimeSeriesKey &other) const noexcept
Greater-than operator.
std::string str() const noexcept
Get the string representation of the key.
bool operator<(const TimeSeriesKey &other) const noexcept
Less-than operator.
Timestamp timestamp() const noexcept
Get the timestamp.
bool operator!=(const TimeSeriesKey &other) const noexcept
Inequality operator.