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
3538namespace datasketches {
3639
37- using A = std::allocator<uint64_t >;
40+ using A = std::allocator<double >;
3841constexpr double EPSILON = 1e-10 ;
3942
4043void 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
554557TEST_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