Skip to content

Commit 3c1d929

Browse files
committed
Bring back sparse store
1 parent b5f9220 commit 3c1d929

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

ddsketch/include/sparse_store.hpp

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

2323
#include <map>
24+
#include <string>
2425

2526
#include "bin.hpp"
2627

ddsketch/test/DDSketchTest.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,20 @@
2424
#include <cmath>
2525
#include <stdexcept>
2626
#include <map>
27+
#include <cmath>
2728

2829
#include "ddsketch.hpp"
2930
#include "logarithmic_mapping.hpp"
3031
#include "linearly_interpolated_mapping.hpp"
3132
#include "unbounded_size_dense_store.hpp"
3233
#include "collapsing_highest_dense_store.hpp"
3334
#include "collapsing_lowest_dense_store.hpp"
35+
#include "sparse_store.hpp"
36+
#include "../../tdigest/include/tdigest.hpp"
3437

3538
namespace datasketches {
3639

37-
using A = std::allocator<uint64_t>;
40+
using A = std::allocator<double>;
3841
constexpr double EPSILON = 1e-10;
3942

4043
void assert_accurate(double min_expected, double max_expected, double actual, double relative_accuracy) {
@@ -552,21 +555,34 @@ TEMPLATE_TEST_CASE("DDSketch serialize - deserialize test", "[ddsketch][random]"
552555
}
553556

554557
TEST_CASE("quantile", "[ddsketch]") {
558+
DDSketch<CollapsingLowestDenseStore<8, A>, LinearlyInterpolatedMapping> sk(0.01);
555559
std::random_device rd{};
556560
std::mt19937_64 gen{rd()};
557561
std::normal_distribution<double> d(0.0, 1.0);
558562

563+
std::vector<double> values;
564+
565+
tdigest<double, A> td(100);
559566
DDSketch<CollapsingHighestDenseStore<1024, A>, LogarithmicMapping> ddsketch(0.01);
560-
for (size_t i = 0; i < 1000000; ++i) {
567+
DDSketch<SparseStore<A>, LogarithmicMapping> sparse_sk(0.01);
568+
for (size_t i = 0; i < 10000000; ++i) {
561569
double val = d(gen);
562570
ddsketch.update(val);
571+
sparse_sk.update(val);
572+
td.update(val);
563573
}
564574

565-
DDSketch<CollapsingLowestDenseStore<8, A>, LinearlyInterpolatedMapping> sk(0.01);
566575

567-
// std::cout << ddsketch.get_quantile(0.5) << std::endl;
568-
// std::cout << ddsketch.get_rank(4) << std::endl;
569576

570577
std::cout << ddsketch.to_string();
578+
std::cout << std::endl;
579+
std::cout << sparse_sk.to_string();
580+
std::cout << std::endl;
581+
std::cout << td.to_string();
582+
583+
std::cout << std::setprecision(20) << std::fixed;
584+
for (double q = 0.0; q <= 1.00; q += 0.01) {
585+
std::cout << std::setw(4) << q << " " << std::setw(15) << ddsketch.get_quantile(q) << " " << std::setw(15) << sparse_sk.get_quantile(q) << " " << std::setw(15) << td.get_quantile(q) << " " << std::endl;
586+
}
571587
}
572588
} /* namespace datasketches */

0 commit comments

Comments
 (0)