Skip to content

Commit 46af536

Browse files
committed
Implement to string
1 parent 9ca0f32 commit 46af536

8 files changed

Lines changed: 65 additions & 12 deletions

ddsketch/include/ddsketch.hpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "store_factory.hpp"
2828
#include "common_defs.hpp"
2929
#include "memory_operations.hpp"
30+
#include "quartically_interpolated_mapping.hpp"
3031

3132
namespace datasketches {
3233

@@ -60,6 +61,8 @@ class DDSketch {
6061
static DDSketch deserialize(std::istream& is);
6162
int get_serialized_size_bytes() const;
6263

64+
template<class A>
65+
string<A> to_string() const;
6366
bool operator==(const DDSketch<Store, Mapping>& other) const;
6467
protected:
6568
Store positive_store;
@@ -70,22 +73,10 @@ class DDSketch {
7073
const double min_indexed_value;
7174
const double max_indexed_value;
7275

73-
// Serialization constants
74-
static const uint8_t SERIAL_VERSION = 1;
75-
static const uint8_t FAMILY = 18; // DDSketch family ID
76-
static const size_t PREAMBLE_SIZE_BYTES = 8;
77-
7876
void check_value_trackable(const double& value) const;
7977
template<store_concept OtherStore>
8078
void check_mergeability(const DDSketch<OtherStore, Mapping>& other) const;
8179
double get_quantile(const double& rank, const double& count) const;
82-
83-
enum Flag : uint8_t {
84-
POSITIVE_STORE,
85-
NEGATIVE_STORE,
86-
INDEX_MAPPING,
87-
ZERO_COUNT,
88-
};
8980
};
9081

9182
// CTA (class template argument deduction) deduction guides (so you can write `ddsketch sketch(s1);`)

ddsketch/include/ddsketch_impl.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,32 @@ DDSketch<Store, Mapping> DDSketch<Store, Mapping>::deserialize(std::istream &is)
238238
return ddsketch;
239239
}
240240

241+
template<store_concept Store, class Mapping>
242+
int DDSketch<Store, Mapping>::get_serialized_size_bytes() const {
243+
return index_mapping.get_serialized_size_bytes() +
244+
positive_store.get_serialized_size_bytes() +
245+
negative_store.get_serialized_size_bytes() +
246+
sizeof(zero_count) +
247+
2 * sizeof(double);
248+
}
249+
250+
template<store_concept Store, class Mapping>
251+
template<class A>
252+
string<A> DDSketch<Store, Mapping>::to_string() const {
253+
std::ostringstream os;
254+
os << "### ddsketch summary:" << std::endl;
255+
os << " Index mapping :" << std::endl;
256+
os << index_mapping.to_string() << std::endl;
257+
os << " Positive store :" << std::endl;
258+
os << positive_store.to_string() << std::endl;
259+
os << " Negative store :" << std::endl;
260+
os << negative_store.to_string() << std::endl;
261+
os << " Zero count :" << zero_count << std::endl;
262+
return os.str();
263+
264+
}
265+
266+
241267
template<store_concept Store, class Mapping>
242268
bool DDSketch<Store, Mapping>::operator==(const DDSketch<Store, Mapping>& other) const {
243269
return positive_store == other.positive_store &&

ddsketch/include/dense_store.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <vector>
2424
#include "bin.hpp"
25+
#include "common_defs.hpp"
2526

2627
namespace datasketches {
2728
// Forward declaration
@@ -53,6 +54,8 @@ class DenseStore {
5354
void serialize(std::ostream& os) const;
5455
static Derived deserialize(std::istream& is);
5556

57+
string<Allocator> to_string() const;
58+
5659
bool operator==(const DenseStore<Derived, Allocator>& other) const;
5760

5861
iterator begin() const;

ddsketch/include/dense_store_impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,16 @@ int DenseStore<Derived, Allocator>::get_serialized_size_bytes_common() const {
443443
// Final cast matches the serialized-size field type used elsewhere
444444
return static_cast<int>(size_bytes);
445445
}
446+
447+
template<class Derived, typename Allocator>
448+
string<Allocator> DenseStore<Derived, Allocator>::to_string() const {
449+
std::ostringstream os;
450+
os << " Type : dense store " << std::endl;
451+
os << " Bins number : " << bins.size() << std::endl;
452+
os << " Min index : " << min_index << std::endl;
453+
os << " Max index : " << max_index << std::endl;
454+
return os.str();
455+
}
446456
}
447457

448458
#endif //DENSE_STORE_IMPL_HPP

ddsketch/include/log_like_index_mapping.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class LogLikeIndexMapping : public IndexMapping<Derived> {
4040
double max_indexable_value() const;
4141
void serialize(std::ostream& os) const;
4242

43+
template<class A>
44+
string<A> to_string() const;
45+
4346
bool operator==(const LogLikeIndexMapping<Derived>& other) const;
4447

4548
private:

ddsketch/include/log_like_index_mapping_impl.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ const Derived& LogLikeIndexMapping<Derived>::derived() const {
124124
return static_cast<const Derived&>(*this);
125125
}
126126

127+
template<class Derived>
128+
template<class A>
129+
string<A> LogLikeIndexMapping<Derived>::to_string() const {
130+
std::ostringstream os;
131+
os << " gamma : " << gamma << std::endl;
132+
os << " index offset : " << index_offset << std::endl;
133+
os << " relative accuracy : " << relative_accuracy << std::endl;
134+
return os.str();
135+
}
136+
127137
}
128138

129139
#endif //LOG_LIKE_INDEX_MAPPING_IMPL_HPP

ddsketch/include/sparse_store.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class SparseStore {
6363
static SparseStore deserialize(std::istream& is);
6464
int get_serialized_size_bytes() const;
6565

66+
string<Allocator> to_string() const;
67+
6668
iterator begin() const;
6769
iterator end() const;
6870
reverse_iterator rbegin() const;

ddsketch/include/sparse_store_impl.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ int SparseStore<Allocator>::get_serialized_size_bytes() const {
229229
return size_bytes;
230230
}
231231

232+
template<typename Allocator>
233+
string<Allocator> SparseStore<Allocator>::to_string() const {
234+
std::ostringstream os;
235+
os << " Type : sparse store" << std::endl;
236+
os << " Bins number : " << bins.size() << std::endl;
237+
return os.str();
238+
}
239+
232240

233241
}
234242

0 commit comments

Comments
 (0)