Give mvt_value and serial_val a double-with-count concept

This commit is contained in:
Erica Fischer
2025-01-30 11:58:10 -08:00
parent b9b48f42c9
commit 9c299ba653
2 changed files with 28 additions and 1 deletions
+14 -1
View File
@@ -81,7 +81,8 @@ struct mvt_value;
double mvt_value_to_double(mvt_value const &v); double mvt_value_to_double(mvt_value const &v);
struct mvt_value { struct mvt_value {
mvt_value_type type; long /* mvt_value_type */ type : 5;
long count : 64 - 5;
std::shared_ptr<std::string> s; std::shared_ptr<std::string> s;
union { union {
@@ -138,6 +139,10 @@ struct mvt_value {
return mvt_value_to_double(*this); return mvt_value_to_double(*this);
} }
size_t get_count() const {
return count;
}
bool operator<(const mvt_value &o) const; bool operator<(const mvt_value &o) const;
bool operator==(const mvt_value &o) const; bool operator==(const mvt_value &o) const;
std::string toString() const; std::string toString() const;
@@ -145,11 +150,19 @@ struct mvt_value {
mvt_value() { mvt_value() {
this->type = mvt_double; this->type = mvt_double;
this->numeric_value.double_value = 0; this->numeric_value.double_value = 0;
this->count = 0;
} }
mvt_value(double v) { mvt_value(double v) {
this->type = mvt_double; this->type = mvt_double;
this->numeric_value.double_value = v; this->numeric_value.double_value = v;
this->count = 0;
}
void set_double_accum(double v, size_t c) {
this->type = mvt_double;
this->numeric_value.double_value = v;
this->count = c;
} }
}; };
+14
View File
@@ -70,6 +70,20 @@ struct serial_val {
type = mvt_string; type = mvt_string;
s = val; s = val;
} }
size_t get_count() const {
size_t found = s.find('\0');
if (found == std::string::npos) {
return 0;
} else {
return atoll(s.c_str() + found + 1);
}
}
void set_double_accum(double v, size_t c) {
type = mvt_double;
s = milo::dtoa_milo(v) + '\0' + std::to_string(c);
}
}; };
struct key_pool { struct key_pool {