Skip to content

Commit 50d513e

Browse files
committed
Encode decode WIP
1 parent d53a4e3 commit 50d513e

6 files changed

Lines changed: 41 additions & 3 deletions

File tree

ddsketch/include/ddsketch.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <variant>
2626
#include "store.hpp"
2727
#include "store_factory.hpp"
28+
#include "common_defs.hpp"
29+
#include "memory_operations.hpp"
2830

2931
namespace datasketches {
3032

@@ -61,6 +63,9 @@ class DDSketch {
6163
double get_min() const;
6264
double get_max() const;
6365

66+
void serialize(std::ostream& os) const;
67+
static DDSketch deserialize(std::istream& is);
68+
6469
protected:
6570
Store positive_store;
6671
Store negative_store;
@@ -70,6 +75,11 @@ class DDSketch {
7075
const double min_indexed_value;
7176
const double max_indexed_value;
7277

78+
// Serialization constants
79+
static const uint8_t SERIAL_VERSION = 1;
80+
static const uint8_t FAMILY = 18; // DDSketch family ID
81+
static const size_t PREAMBLE_SIZE_BYTES = 8;
82+
7383
void check_value_trackable(const double& value) const;
7484
template<store_concept OtherStore>
7585
void check_mergeability(const DDSketch<OtherStore, Mapping>& other) const;

ddsketch/include/ddsketch_impl.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@ double DDSketch<Store, Mapping>::get_quantile(const double& rank, const double&
194194
}
195195
throw std::invalid_argument("no such element");
196196
}
197+
198+
template<store_concept Store, class Mapping>
199+
void DDSketch<Store, Mapping>::serialize(std::ostream& os) const {
200+
index_mapping.serialize(os);
201+
if (zero_count > 0.0) {
202+
write(os, zero_count);
203+
}
204+
205+
positive_store.serialize(os);
206+
negative_store.serialize(os);
207+
}
208+
209+
template<store_concept Store, class Mapping>
210+
DDSketch<Store, Mapping> DDSketch<Store, Mapping>::deserialize(std::istream &is) {
211+
212+
}
213+
197214
}
198215

199216
#endif

ddsketch/include/dense_store.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class DenseStore {
5050

5151
void merge(const SparseStore<Allocator>& other);
5252

53+
void serialize(std::ostream& is) const;
54+
DenseStore<Derived, Allocator> deserialize(std::ostream& is);
55+
5356
iterator begin() const;
5457
iterator end() const;
5558

ddsketch/include/dense_store_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ template<class Derived, typename Allocator>
335335
typename DenseStore<Derived, Allocator>::reverse_iterator::reference DenseStore<Derived, Allocator>::reverse_iterator::operator*() const {
336336
return Bin(this->index, this->bins[this->index - this->offset]);
337337
}
338+
339+
template<class Derived, typename Allocator>
340+
void DenseStore<Derived, Allocator>::serialize(std::ostream& os) const {
341+
if (is_empty()) {
342+
return;
343+
}
344+
345+
346+
}
338347
}
339348

340349
#endif //DENSE_STORE_IMPL_HPP

ddsketch/include/index_mapping.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class IndexMapping {
4444
double min_indexable_value() const;
4545
double max_indexable_value() const;
4646
void serialize(std::ostream& os) const;
47-
4847
static Derived deserialize(std::istream& is);
4948

5049
~IndexMapping() = default;

ddsketch/test/DDSketchTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ TEST_CASE("quantile", "[ddsketch]") {
527527
ddsketch.update(val);
528528
}
529529

530-
std::cout << ddsketch.get_quantile(0.5) << std::endl;
531-
std::cout << ddsketch.get_rank(4) << std::endl;
530+
// std::cout << ddsketch.get_quantile(0.5) << std::endl;
531+
// std::cout << ddsketch.get_rank(4) << std::endl;
532532
}
533533
} /* namespace datasketches */

0 commit comments

Comments
 (0)