Skip to content

Commit 8160e42

Browse files
committed
WIP c++11
1 parent cc5b6bd commit 8160e42

23 files changed

Lines changed: 946 additions & 1625 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
4343
#set(CMAKE_VERBOSE_MAKEFILE ON)
4444
set(CMAKE_MACOSX_RPATH ON)
4545

46-
set(CMAKE_CXX_STANDARD 20)
46+
set(CMAKE_CXX_STANDARD 11)
4747

4848
# enable compiler warnings globally
4949
# derived from https://foonathan.net/blog/2018/10/17/cmake-warnings.html

ddsketch/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ install(FILES
5959
include/logarithmic_mapping_impl.hpp
6060
include/quadratically_interpolated_mapping.hpp
6161
include/quadratically_interpolated_mapping_impl.hpp
62-
include/sparse_store.hpp
63-
include/sparse_store_impl.hpp
64-
include/store.hpp
6562
include/store_factory.hpp
6663
include/unbounded_size_dense_store.hpp
6764
include/unbounded_size_dense_store_impl.hpp

ddsketch/include/ddsketch.hpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include <utility>
2424
#include <type_traits>
2525
#include <variant>
26-
#include "store.hpp"
2726
#include "store_factory.hpp"
2827
#include "common_defs.hpp"
2928
#include "memory_operations.hpp"
@@ -41,7 +40,7 @@ namespace datasketches {
4140
* @tparam Store underlying data structure that keeps track of bin counts.
4241
* @tparam Mapping maps an index to its corresponding bin.
4342
*/
44-
template<store_concept Store, class Mapping>
43+
template<class Store, class Mapping>
4544
class DDSketch {
4645
public:
4746

@@ -75,7 +74,7 @@ class DDSketch {
7574
* @param other DDSketch; its counts are added into this store.
7675
* @tparam OtherStore type of the other store.
7776
*/
78-
template<store_concept OtherStore>
77+
template<class OtherStore>
7978
void merge(const DDSketch<OtherStore, Mapping>& other);
8079

8180
/**
@@ -166,17 +165,12 @@ class DDSketch {
166165

167166
void check_value_trackable(const double& value) const;
168167

169-
template<store_concept OtherStore>
168+
template<class OtherStore>
170169
void check_mergeability(const DDSketch<OtherStore, Mapping>& other) const;
171170

172171
double get_quantile(const double& rank, const double& count) const;
173172
};
174173

175-
// CTA (class template argument deduction) deduction guides (so you can write `ddsketch sketch(s1);`)
176-
template<store_concept Store, class Mapping>
177-
DDSketch(Store, Mapping) -> DDSketch<Store, Mapping>;\
178-
179-
180174
} /* namespace datasketches */
181175

182176
#include "ddsketch_impl.hpp"

ddsketch/include/ddsketch_impl.hpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222

2323
#include <iomanip>
2424
#include <iostream>
25+
#include "bin.hpp"
26+
#include <sstream>
2527
#include "ddsketch.hpp"
2628
#include "store_factory.hpp"
2729
namespace datasketches {
2830

29-
template<store_concept Store, class Mapping>
31+
template<class Store, class Mapping>
3032
DDSketch<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>
3335
DDSketch<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>
4244
DDSketch<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>
5254
void 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>
6062
void 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>
6769
void 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>
8587
void 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>
9395
bool 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>
98100
void 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>
105107
double 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>
110112
double 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>
122124
double 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>
133135
double 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>
144146
double 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>
165167
double 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>
170172
double 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>
203205
void 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>
219221
DDSketch<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>
242244
int 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>
251253
template<class A>
252254
string<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>
271273
bool DDSketch<Store, Mapping>::operator==(const DDSketch<Store, Mapping>& other) const {
272274
return positive_store == other.positive_store &&
273275
negative_store == other.negative_store &&

ddsketch/include/dense_store.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include "common_defs.hpp"
2626

2727
namespace datasketches {
28-
// Forward declaration
29-
template<typename Allocator> class SparseStore;
3028

3129
/**
3230
* @class DenseStore
@@ -109,12 +107,6 @@ class DenseStore {
109107
template<class Store>
110108
void merge(const DenseStore<Store, Allocator>& other);
111109

112-
/**
113-
* @brief Merge a sparse store into this dense store.
114-
* @param other SparseStore to accumulate from.
115-
*/
116-
void merge(const SparseStore<Allocator>& other);
117-
118110
/**
119111
* This method serializes the store into a given stream in a binary form
120112
* @param os output stream

ddsketch/include/dense_store_impl.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,6 @@ void DenseStore<Derived, Allocator>::merge(const DenseStore<OtherDerived, Alloca
128128
}
129129
}
130130

131-
template<class Derived, typename Allocator>
132-
void DenseStore<Derived, Allocator>::merge(const SparseStore<Allocator>& other) {
133-
for (const Bin &bin : other) {
134-
add(bin);
135-
}
136-
}
137-
138131
template<class Derived, typename Allocator>
139132
typename DenseStore<Derived, Allocator>::iterator DenseStore<Derived, Allocator>::begin() const {
140133
if (is_empty()) {

ddsketch/include/index_mapping_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class index_mapping_factory {
3030
template<typename... Args>
3131
static std::unique_ptr<IndexMapping> new_mapping(Args&&... args)
3232
{
33-
return std::make_unique<IndexMapping>(std::forward<Args>(args)...);
33+
return std::unique_ptr<IndexMapping>();
3434
}
3535
};
3636
}

ddsketch/include/linearly_interpolated_mapping.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#define LINEARLY_INTERPOLATED_MAPPING_HPP
2222

2323
#include "log_like_index_mapping.hpp"
24-
#include <numbers>
2524

2625

2726
namespace datasketches {
@@ -57,7 +56,7 @@ class LinearlyInterpolatedMapping : public LogLikeIndexMapping<LinearlyInterpola
5756
IndexMappingLayout layout() const;
5857

5958
static constexpr double BASE = 2.0;
60-
static constexpr double CORRECTING_FACTOR = std::numbers::log2e;
59+
static constexpr double CORRECTING_FACTOR = 1.44269504088896340735;
6160

6261
private:
6362
static double index_offset_shift(const double& relative_accuracy);

ddsketch/include/linearly_interpolated_mapping_impl.hpp

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

2323
namespace datasketches {
2424

25+
constexpr double LinearlyInterpolatedMapping::BASE;
26+
constexpr double LinearlyInterpolatedMapping::CORRECTING_FACTOR;
27+
2528
inline LinearlyInterpolatedMapping::LinearlyInterpolatedMapping(const double& relative_accuracy):
2629
LogLikeIndexMapping<LinearlyInterpolatedMapping>(compute_gamma(require_valid_relative_accuracy(relative_accuracy), CORRECTING_FACTOR), index_offset_shift(relative_accuracy)) {}
2730

ddsketch/include/log_like_index_mapping.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class LogLikeIndexMapping : public IndexMapping<Derived> {
101101
string<A> to_string() const;
102102

103103
bool operator==(const LogLikeIndexMapping<Derived>& other) const;
104+
bool operator!=(const LogLikeIndexMapping<Derived>& other) const;
104105

105106
private:
106107
static double compute_relative_accuracy(const double& gamma, const double& correcting_factor);

0 commit comments

Comments
 (0)