2222
2323#include < iomanip>
2424#include < iostream>
25+ #include " bin.hpp"
26+ #include < sstream>
2527#include " ddsketch.hpp"
2628#include " store_factory.hpp"
2729namespace datasketches {
2830
29- template <store_concept Store, class Mapping >
31+ template <class Store , class Mapping >
3032DDSketch<Store, Mapping>::DDSketch(const double & relative_accuracy): DDSketch(Mapping(relative_accuracy)) {}
3133
32- template <store_concept Store, class Mapping >
34+ template <class Store , class Mapping >
3335DDSketch<Store, Mapping>::DDSketch(const Mapping& index_mapping):
3436 index_mapping (index_mapping),
3537 zero_count(0 ),
@@ -38,7 +40,7 @@ DDSketch<Store, Mapping>::DDSketch(const Mapping& index_mapping):
3840{}
3941
4042
41- template <store_concept Store, class Mapping >
43+ template <class Store , class Mapping >
4244DDSketch<Store, Mapping>::DDSketch(const Store& positive_store, const Store& negative_store, const Mapping& mapping, const double & zero_count, const double & min_indexed_value):
4345 positive_store (std::move(positive_store)),
4446 negative_store(std::move(negative_store)),
@@ -48,22 +50,22 @@ DDSketch<Store, Mapping>::DDSketch(const Store& positive_store, const Store& neg
4850 max_indexed_value(mapping.max_indexable_value()) {}
4951
5052
51- template <store_concept Store, class Mapping >
53+ template <class Store , class Mapping >
5254void DDSketch<Store, Mapping>::check_value_trackable(const double & value) const {
5355 if (value < -max_indexed_value || value > max_indexed_value) {
5456 throw std::invalid_argument (" input value is outside the range that is tracked by the sketch." );
5557 }
5658}
5759
58- template <store_concept Store, class Mapping >
59- template <store_concept OtherStore>
60+ template <class Store , class Mapping >
61+ template <class OtherStore >
6062void DDSketch<Store, Mapping>::check_mergeability(const DDSketch<OtherStore, Mapping>& other) const {
6163 if (index_mapping != other.index_mapping ) {
6264 throw std::invalid_argument (" sketches are not mergeable because they do not use the same index mappings." );
6365 }
6466}
6567
66- template <store_concept Store, class Mapping >
68+ template <class Store , class Mapping >
6769void DDSketch<Store, Mapping>::update(const double & value, const double & count) {
6870 check_value_trackable (value);
6971
@@ -80,33 +82,33 @@ void DDSketch<Store, Mapping>::update(const double& value, const double& count)
8082 }
8183}
8284
83- template <store_concept Store, class Mapping >
84- template <store_concept OtherStore>
85+ template <class Store , class Mapping >
86+ template <class OtherStore >
8587void DDSketch<Store, Mapping>::merge(const DDSketch<OtherStore, Mapping>& other) {
8688 check_mergeability<OtherStore>(other);
8789 negative_store.merge (other.negative_store );
8890 positive_store.merge (other.positive_store );
8991 zero_count += other.zero_count ;
9092}
9193
92- template <store_concept Store, class Mapping >
94+ template <class Store , class Mapping >
9395bool DDSketch<Store, Mapping>::is_empty() const {
9496 return zero_count == 0.0 && positive_store.is_empty () && negative_store.is_empty ();
9597}
9698
97- template <store_concept Store, class Mapping >
99+ template <class Store , class Mapping >
98100void DDSketch<Store, Mapping>::clear() {
99101 negative_store.clear ();
100102 positive_store.clear ();
101103 zero_count = 0.0 ;
102104}
103105
104- template <store_concept Store, class Mapping >
106+ template <class Store , class Mapping >
105107double DDSketch<Store, Mapping>::get_count() const {
106108 return zero_count + negative_store.get_total_count () + positive_store.get_total_count ();
107109}
108110
109- template <store_concept Store, class Mapping >
111+ template <class Store , class Mapping >
110112double DDSketch<Store, Mapping>::get_sum() const {
111113 double sum = 0.0 ;
112114 for (const Bin& bin : negative_store) {
@@ -118,7 +120,7 @@ double DDSketch<Store, Mapping>::get_sum() const {
118120 return sum;
119121}
120122
121- template <store_concept Store, class Mapping >
123+ template <class Store , class Mapping >
122124double DDSketch<Store, Mapping>::get_min() const {
123125 if (!negative_store.is_empty ()) {
124126 return -index_mapping.value (negative_store.get_max_index ());
@@ -129,7 +131,7 @@ double DDSketch<Store, Mapping>::get_min() const {
129131 return index_mapping.value (positive_store.get_min_index ());
130132}
131133
132- template <store_concept Store, class Mapping >
134+ template <class Store , class Mapping >
133135double DDSketch<Store, Mapping>::get_max() const {
134136 if (!positive_store.is_empty ()) {
135137 return index_mapping.value (positive_store.get_max_index ());
@@ -140,7 +142,7 @@ double DDSketch<Store, Mapping>::get_max() const {
140142 return -index_mapping.value (negative_store.get_min_index ());
141143}
142144
143- template <store_concept Store, class Mapping >
145+ template <class Store , class Mapping >
144146double DDSketch<Store, Mapping>::get_rank(const double &item) const {
145147 double rank = 0.0 ;
146148
@@ -161,12 +163,12 @@ double DDSketch<Store, Mapping>::get_rank(const double &item) const {
161163}
162164
163165
164- template <store_concept Store, class Mapping >
166+ template <class Store , class Mapping >
165167double DDSketch<Store, Mapping>::get_quantile(const double & rank) const {
166168 return get_quantile (rank, get_count ());
167169}
168170
169- template <store_concept Store, class Mapping >
171+ template <class Store , class Mapping >
170172double DDSketch<Store, Mapping>::get_quantile(const double & rank, const double & count) const {
171173 if (rank < 0.0 || rank > 1.0 ) {
172174 throw std::invalid_argument (" rank must be in [0.0, 1.0]" );
@@ -199,7 +201,7 @@ double DDSketch<Store, Mapping>::get_quantile(const double& rank, const double&
199201 throw std::invalid_argument (" no such element" );
200202}
201203
202- template <store_concept Store, class Mapping >
204+ template <class Store , class Mapping >
203205void DDSketch<Store, Mapping>::serialize(std::ostream& os) const {
204206 index_mapping.serialize (os);
205207
@@ -215,21 +217,21 @@ void DDSketch<Store, Mapping>::serialize(std::ostream& os) const {
215217 negative_store.serialize (os);
216218}
217219
218- template <store_concept Store, class Mapping >
220+ template <class Store , class Mapping >
219221DDSketch<Store, Mapping> DDSketch<Store, Mapping>::deserialize(std::istream &is) {
220222 Mapping deserialized_index_mapping = Mapping::deserialize (is);
221223 const auto deserialized_zero_count = read<double >(is);
222224
223225 const auto positive_store_serialized_size = read<int >(is);
224226
225227 std::string pos_buf (positive_store_serialized_size, ' \0 ' );
226- is.read (pos_buf. data () , pos_buf.size ());
228+ is.read (& pos_buf[ 0 ] , pos_buf.size ());
227229 std::stringstream pos_stream (pos_buf);
228230 Store deserialized_positive_store = Store::deserialize (pos_stream);
229231
230232 const auto negative_store_serialized_size = read<int >(is);
231233 std::string neg_buf (negative_store_serialized_size, ' \0 ' );
232- is.read (neg_buf. data () , neg_buf.size ());
234+ is.read (& neg_buf[ 0 ] , neg_buf.size ());
233235 std::stringstream neg_stream (neg_buf);
234236 Store deserialized_negative_store = Store::deserialize (neg_stream);
235237
@@ -238,7 +240,7 @@ DDSketch<Store, Mapping> DDSketch<Store, Mapping>::deserialize(std::istream &is)
238240 return ddsketch;
239241}
240242
241- template <store_concept Store, class Mapping >
243+ template <class Store , class Mapping >
242244int DDSketch<Store, Mapping>::get_serialized_size_bytes() const {
243245 return index_mapping.get_serialized_size_bytes () +
244246 positive_store.get_serialized_size_bytes () +
@@ -247,7 +249,7 @@ int DDSketch<Store, Mapping>::get_serialized_size_bytes() const {
247249 2 * sizeof (double );
248250}
249251
250- template <store_concept Store, class Mapping >
252+ template <class Store , class Mapping >
251253template <class A >
252254string<A> DDSketch<Store, Mapping>::to_string() const {
253255 std::ostringstream os;
@@ -267,7 +269,7 @@ string<A> DDSketch<Store, Mapping>::to_string() const {
267269}
268270
269271
270- template <store_concept Store, class Mapping >
272+ template <class Store , class Mapping >
271273bool DDSketch<Store, Mapping>::operator ==(const DDSketch<Store, Mapping>& other) const {
272274 return positive_store == other.positive_store &&
273275 negative_store == other.negative_store &&
0 commit comments