@@ -198,17 +198,50 @@ double DDSketch<Store, Mapping>::get_quantile(const double& rank, const double&
198198template <store_concept Store, class Mapping >
199199void DDSketch<Store, Mapping>::serialize(std::ostream& os) const {
200200 index_mapping.serialize (os);
201- if (zero_count > 0.0 ) {
202- write (os, zero_count);
203- }
204201
202+ write (os, zero_count);
203+
204+
205+ auto val = positive_store.get_serialized_size_bytes ();
206+ write (os, positive_store.get_serialized_size_bytes ());
205207 positive_store.serialize (os);
208+
209+ val = negative_store.get_serialized_size_bytes ();
210+ write (os, negative_store.get_serialized_size_bytes ());
206211 negative_store.serialize (os);
207212}
208213
209214template <store_concept Store, class Mapping >
210215DDSketch<Store, Mapping> DDSketch<Store, Mapping>::deserialize(std::istream &is) {
216+ Mapping deserialized_index_mapping = Mapping::deserialize (is);
217+ const auto deserialized_zero_count = read<double >(is);
218+
219+ const auto positive_store_serialized_size = read<int >(is);
211220
221+ std::string pos_buf (positive_store_serialized_size, ' \0 ' );
222+ is.read (pos_buf.data (), pos_buf.size ());
223+ std::stringstream pos_stream (pos_buf);
224+ Store deserialized_positive_store = Store::deserialize (pos_stream);
225+
226+ const auto negative_store_serialized_size = read<int >(is);
227+ std::string neg_buf (negative_store_serialized_size, ' \0 ' );
228+ is.read (neg_buf.data (), neg_buf.size ());
229+ std::stringstream neg_stream (neg_buf);
230+ Store deserialized_negative_store = Store::deserialize (neg_stream);
231+
232+ DDSketch<Store, Mapping> ddsketch (deserialized_positive_store, deserialized_negative_store, deserialized_index_mapping);
233+ ddsketch.zero_count = deserialized_zero_count;
234+ return ddsketch;
235+ }
236+
237+ template <store_concept Store, class Mapping >
238+ bool DDSketch<Store, Mapping>::operator ==(const DDSketch<Store, Mapping>& other) const {
239+ return positive_store == other.positive_store &&
240+ negative_store == other.negative_store &&
241+ index_mapping == other.index_mapping &&
242+ zero_count == other.zero_count &&
243+ min_indexed_value == other.min_indexed_value &&
244+ max_indexed_value == other.max_indexed_value ;
212245}
213246
214247}
0 commit comments