From 9c299ba653d4a8841f2e063036b05fbe79174b8e Mon Sep 17 00:00:00 2001 From: Erica Fischer Date: Thu, 30 Jan 2025 11:58:10 -0800 Subject: [PATCH] Give mvt_value and serial_val a double-with-count concept --- mvt.hpp | 15 ++++++++++++++- serial.hpp | 14 ++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/mvt.hpp b/mvt.hpp index e44a632a..800021d3 100644 --- a/mvt.hpp +++ b/mvt.hpp @@ -81,7 +81,8 @@ struct mvt_value; double mvt_value_to_double(mvt_value const &v); struct mvt_value { - mvt_value_type type; + long /* mvt_value_type */ type : 5; + long count : 64 - 5; std::shared_ptr s; union { @@ -138,6 +139,10 @@ struct mvt_value { 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; std::string toString() const; @@ -145,11 +150,19 @@ struct mvt_value { mvt_value() { this->type = mvt_double; this->numeric_value.double_value = 0; + this->count = 0; } mvt_value(double v) { this->type = mvt_double; 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; } }; diff --git a/serial.hpp b/serial.hpp index 91cdac5c..0fb9c5c0 100644 --- a/serial.hpp +++ b/serial.hpp @@ -70,6 +70,20 @@ struct serial_val { type = mvt_string; 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 {