Skip to content

Commit d655e5b

Browse files
committed
Working stores cross merge with C++11
1 parent bb00fe7 commit d655e5b

6 files changed

Lines changed: 525 additions & 488 deletions

File tree

ddsketch/include/dense_store.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vector>
2424
#include "bin.hpp"
2525
#include "common_defs.hpp"
26+
#include "sparse_store.hpp"
2627

2728
namespace datasketches {
2829

@@ -107,6 +108,12 @@ class DenseStore {
107108
template<class Store>
108109
void merge(const DenseStore<Store, Allocator>& other);
109110

111+
/**
112+
* @brief Merge a sparse store (same allocator) into this one.
113+
* @param other store; its counts are added here.
114+
*/
115+
void merge(const SparseStore<Allocator>& other);
116+
110117
/**
111118
* This method serializes the store into a given stream in a binary form
112119
* @param os output stream

ddsketch/include/dense_store_impl.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ void DenseStore<Derived, Allocator>::merge(const DenseStore<OtherDerived, Alloca
131131
}
132132
}
133133

134+
template<class Derived, typename Allocator>
135+
void DenseStore<Derived, Allocator>::merge(const SparseStore<Allocator>& other) {
136+
for (const Bin& bin : other) {
137+
add(bin);
138+
}
139+
}
140+
134141
template<class Derived, typename Allocator>
135142
typename DenseStore<Derived, Allocator>::iterator DenseStore<Derived, Allocator>::begin() const {
136143
if (is_empty()) {

ddsketch/include/log_like_index_mapping_impl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef LOG_LIKE_INDEX_MAPPING_IMPL_HPP
2121
#define LOG_LIKE_INDEX_MAPPING_IMPL_HPP
2222
#include "log_like_index_mapping.hpp"
23+
#include <cassert>
2324
#include <cmath>
2425
#include "common_defs.hpp"
2526

ddsketch/test/DDSketchTest.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,20 +558,24 @@ TEST_CASE("quantile", "[ddsketch]") {
558558
DDSketch<CollapsingLowestDenseStore<8, A>, LinearlyInterpolatedMapping> sk(0.01);
559559
std::random_device rd{};
560560
std::mt19937_64 gen{rd()};
561-
std::normal_distribution<double> d(0.0, 1.0);
561+
// std::normal_distribution<double> d(0.0, 1.0);
562+
std::exponential_distribution<double> d(1.5);
563+
int sample_size = 10000000;
562564

563565
std::vector<double> values;
564566

565567
tdigest<double, A> td(100);
566-
DDSketch<CollapsingHighestDenseStore<1024, A>, LogarithmicMapping> ddsketch(0.01);
568+
DDSketch<CollapsingLowestDenseStore<4096, A>, LogarithmicMapping> ddsketch(0.001);
567569
DDSketch<SparseStore<A>, LogarithmicMapping> sparse_sk(0.01);
568-
for (size_t i = 0; i < 10000000; ++i) {
570+
for (size_t i = 0; i < sample_size; ++i) {
569571
double val = d(gen);
572+
values.push_back(val);
570573
ddsketch.update(val);
571574
sparse_sk.update(val);
572575
td.update(val);
573576
}
574577

578+
std::sort(values.begin(), values.end());
575579

576580

577581
std::cout << ddsketch.to_string();
@@ -582,7 +586,11 @@ TEST_CASE("quantile", "[ddsketch]") {
582586

583587
std::cout << std::setprecision(20) << std::fixed;
584588
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;
589+
const double true_q = values[(sample_size-1) * q];
590+
const double ddsketch_est = std::abs(true_q - ddsketch.get_quantile(q)) / true_q;
591+
const double tdigest_est = std::abs(true_q - td.get_quantile(q)) / true_q;
592+
std::cout << q << " " << ddsketch_est << " " << tdigest_est << std::endl;
593+
// std::cout << std::setw(4) << q << " " << values[(sample_size-1) * 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;
586594
}
587595
}
588596
} /* namespace datasketches */

ddsketch/test/IndexMappingTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TEMPLATE_TEST_CASE("test index mapping accuracy", "[indexmappingtest]",
6868
}
6969
}
7070

71-
TEMPLATE_TEST_CASE("test index mapping validity", "[indexmappingtest}",
71+
TEMPLATE_TEST_CASE("test index mapping validity", "[indexmappingtest]",
7272
LinearlyInterpolatedMapping,
7373
LogarithmicMapping,
7474
QuadraticallyInterpolatedMapping
@@ -92,7 +92,7 @@ TEMPLATE_TEST_CASE("test index mapping validity", "[indexmappingtest}",
9292
}
9393
}
9494

95-
TEMPLATE_TEST_CASE("encode - decode", "[indexmappingtest",
95+
TEMPLATE_TEST_CASE("encode - decode", "[indexmappingtest]",
9696
LinearlyInterpolatedMapping,
9797
LogarithmicMapping,
9898
QuadraticallyInterpolatedMapping

0 commit comments

Comments
 (0)