datasketches 0.2.3 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/README.md +8 -8
  4. data/ext/datasketches/kll_wrapper.cpp +7 -3
  5. data/ext/datasketches/theta_wrapper.cpp +20 -4
  6. data/lib/datasketches/version.rb +1 -1
  7. data/vendor/datasketches-cpp/CMakeLists.txt +25 -5
  8. data/vendor/datasketches-cpp/MANIFEST.in +3 -0
  9. data/vendor/datasketches-cpp/NOTICE +6 -5
  10. data/vendor/datasketches-cpp/README.md +76 -9
  11. data/vendor/datasketches-cpp/cmake/DataSketchesConfig.cmake.in +10 -0
  12. data/vendor/datasketches-cpp/common/CMakeLists.txt +18 -13
  13. data/vendor/datasketches-cpp/common/include/binomial_bounds.hpp +1 -0
  14. data/vendor/datasketches-cpp/common/include/common_defs.hpp +14 -0
  15. data/vendor/datasketches-cpp/{kll → common}/include/kolmogorov_smirnov.hpp +5 -3
  16. data/vendor/datasketches-cpp/{kll → common}/include/kolmogorov_smirnov_impl.hpp +13 -16
  17. data/vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view.hpp +121 -0
  18. data/vendor/datasketches-cpp/common/include/quantile_sketch_sorted_view_impl.hpp +91 -0
  19. data/vendor/datasketches-cpp/common/test/test_type.hpp +2 -0
  20. data/vendor/datasketches-cpp/cpc/CMakeLists.txt +15 -35
  21. data/vendor/datasketches-cpp/cpc/include/cpc_compressor_impl.hpp +3 -1
  22. data/vendor/datasketches-cpp/cpc/include/cpc_confidence.hpp +1 -0
  23. data/vendor/datasketches-cpp/cpc/include/cpc_sketch_impl.hpp +5 -3
  24. data/vendor/datasketches-cpp/cpc/include/cpc_union_impl.hpp +10 -6
  25. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_allocation_test.cpp +17 -0
  26. data/vendor/datasketches-cpp/cpc/test/cpc_sketch_test.cpp +1 -0
  27. data/vendor/datasketches-cpp/cpc/test/cpc_union_test.cpp +2 -0
  28. data/vendor/datasketches-cpp/fi/CMakeLists.txt +5 -15
  29. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch.hpp +37 -5
  30. data/vendor/datasketches-cpp/fi/include/frequent_items_sketch_impl.hpp +29 -11
  31. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_custom_type_test.cpp +2 -1
  32. data/vendor/datasketches-cpp/fi/test/frequent_items_sketch_test.cpp +1 -0
  33. data/vendor/datasketches-cpp/hll/CMakeLists.txt +33 -56
  34. data/vendor/datasketches-cpp/hll/include/AuxHashMap-internal.hpp +2 -0
  35. data/vendor/datasketches-cpp/hll/include/CompositeInterpolationXTable-internal.hpp +1 -0
  36. data/vendor/datasketches-cpp/hll/include/CouponHashSet-internal.hpp +2 -2
  37. data/vendor/datasketches-cpp/hll/include/CouponList-internal.hpp +1 -0
  38. data/vendor/datasketches-cpp/hll/include/HllSketch-internal.hpp +6 -4
  39. data/vendor/datasketches-cpp/hll/include/HllSketchImpl-internal.hpp +2 -0
  40. data/vendor/datasketches-cpp/hll/include/HllSketchImplFactory.hpp +2 -0
  41. data/vendor/datasketches-cpp/hll/test/AuxHashMapTest.cpp +1 -0
  42. data/vendor/datasketches-cpp/hll/test/CouponHashSetTest.cpp +1 -0
  43. data/vendor/datasketches-cpp/hll/test/CouponListTest.cpp +2 -0
  44. data/vendor/datasketches-cpp/hll/test/HllArrayTest.cpp +1 -0
  45. data/vendor/datasketches-cpp/hll/test/HllSketchTest.cpp +59 -0
  46. data/vendor/datasketches-cpp/hll/test/HllUnionTest.cpp +2 -0
  47. data/vendor/datasketches-cpp/hll/test/TablesTest.cpp +1 -0
  48. data/vendor/datasketches-cpp/kll/CMakeLists.txt +5 -19
  49. data/vendor/datasketches-cpp/kll/include/kll_helper.hpp +0 -4
  50. data/vendor/datasketches-cpp/kll/include/kll_helper_impl.hpp +5 -2
  51. data/vendor/datasketches-cpp/kll/include/kll_sketch.hpp +108 -41
  52. data/vendor/datasketches-cpp/kll/include/kll_sketch_impl.hpp +150 -132
  53. data/vendor/datasketches-cpp/kll/test/kll_sketch_test.cpp +165 -31
  54. data/vendor/datasketches-cpp/kll/test/kolmogorov_smirnov_test.cpp +1 -1
  55. data/vendor/datasketches-cpp/pyproject.toml +1 -1
  56. data/vendor/datasketches-cpp/python/CMakeLists.txt +8 -1
  57. data/vendor/datasketches-cpp/python/README.md +13 -9
  58. data/vendor/datasketches-cpp/python/src/datasketches.cpp +4 -0
  59. data/vendor/datasketches-cpp/python/src/fi_wrapper.cpp +6 -1
  60. data/vendor/datasketches-cpp/python/src/kll_wrapper.cpp +48 -13
  61. data/vendor/datasketches-cpp/python/src/ks_wrapper.cpp +68 -0
  62. data/vendor/datasketches-cpp/python/src/quantiles_wrapper.cpp +240 -0
  63. data/vendor/datasketches-cpp/python/src/req_wrapper.cpp +9 -2
  64. data/vendor/datasketches-cpp/python/src/vector_of_kll.cpp +1 -0
  65. data/vendor/datasketches-cpp/python/tests/kll_test.py +10 -4
  66. data/vendor/datasketches-cpp/python/tests/quantiles_test.py +126 -0
  67. data/vendor/datasketches-cpp/quantiles/CMakeLists.txt +42 -0
  68. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch.hpp +656 -0
  69. data/vendor/datasketches-cpp/quantiles/include/quantiles_sketch_impl.hpp +1373 -0
  70. data/vendor/datasketches-cpp/quantiles/test/CMakeLists.txt +44 -0
  71. data/vendor/datasketches-cpp/quantiles/test/Qk128_n1000_v0.3.0.sk +0 -0
  72. data/vendor/datasketches-cpp/quantiles/test/Qk128_n1000_v0.6.0.sk +0 -0
  73. data/vendor/datasketches-cpp/quantiles/test/Qk128_n1000_v0.8.0.sk +0 -0
  74. data/vendor/datasketches-cpp/quantiles/test/Qk128_n1000_v0.8.3.sk +0 -0
  75. data/vendor/datasketches-cpp/quantiles/test/Qk128_n50_v0.3.0.sk +0 -0
  76. data/vendor/datasketches-cpp/quantiles/test/Qk128_n50_v0.6.0.sk +0 -0
  77. data/vendor/datasketches-cpp/quantiles/test/Qk128_n50_v0.8.0.sk +0 -0
  78. data/vendor/datasketches-cpp/quantiles/test/Qk128_n50_v0.8.3.sk +0 -0
  79. data/vendor/datasketches-cpp/quantiles/test/kolmogorov_smirnov_test.cpp +110 -0
  80. data/vendor/datasketches-cpp/quantiles/test/quantiles_compatibility_test.cpp +129 -0
  81. data/vendor/datasketches-cpp/quantiles/test/quantiles_sketch_test.cpp +975 -0
  82. data/vendor/datasketches-cpp/req/CMakeLists.txt +6 -21
  83. data/vendor/datasketches-cpp/req/include/req_common.hpp +0 -5
  84. data/vendor/datasketches-cpp/req/include/req_compactor.hpp +6 -0
  85. data/vendor/datasketches-cpp/req/include/req_compactor_impl.hpp +30 -2
  86. data/vendor/datasketches-cpp/req/include/req_sketch.hpp +73 -23
  87. data/vendor/datasketches-cpp/req/include/req_sketch_impl.hpp +95 -63
  88. data/vendor/datasketches-cpp/req/test/req_sketch_test.cpp +74 -3
  89. data/vendor/datasketches-cpp/sampling/CMakeLists.txt +5 -9
  90. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch.hpp +44 -7
  91. data/vendor/datasketches-cpp/sampling/include/var_opt_sketch_impl.hpp +44 -33
  92. data/vendor/datasketches-cpp/sampling/include/var_opt_union.hpp +41 -6
  93. data/vendor/datasketches-cpp/sampling/include/var_opt_union_impl.hpp +33 -15
  94. data/vendor/datasketches-cpp/sampling/test/var_opt_allocation_test.cpp +2 -2
  95. data/vendor/datasketches-cpp/sampling/test/var_opt_sketch_test.cpp +1 -0
  96. data/vendor/datasketches-cpp/sampling/test/var_opt_union_test.cpp +1 -0
  97. data/vendor/datasketches-cpp/setup.py +1 -1
  98. data/vendor/datasketches-cpp/theta/CMakeLists.txt +26 -45
  99. data/vendor/datasketches-cpp/theta/include/bounds_on_ratios_in_sampled_sets.hpp +1 -0
  100. data/vendor/datasketches-cpp/theta/include/compact_theta_sketch_parser_impl.hpp +92 -23
  101. data/vendor/datasketches-cpp/theta/include/theta_helpers.hpp +15 -0
  102. data/vendor/datasketches-cpp/theta/include/theta_intersection_base_impl.hpp +7 -6
  103. data/vendor/datasketches-cpp/theta/include/theta_set_difference_base_impl.hpp +3 -2
  104. data/vendor/datasketches-cpp/theta/include/theta_sketch.hpp +32 -15
  105. data/vendor/datasketches-cpp/theta/include/theta_sketch_impl.hpp +150 -93
  106. data/vendor/datasketches-cpp/theta/include/theta_union.hpp +6 -1
  107. data/vendor/datasketches-cpp/theta/include/theta_union_base.hpp +3 -1
  108. data/vendor/datasketches-cpp/theta/include/theta_union_base_impl.hpp +9 -2
  109. data/vendor/datasketches-cpp/theta/include/theta_union_impl.hpp +8 -5
  110. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base.hpp +5 -4
  111. data/vendor/datasketches-cpp/theta/include/theta_update_sketch_base_impl.hpp +34 -9
  112. data/vendor/datasketches-cpp/theta/test/CMakeLists.txt +1 -0
  113. data/vendor/datasketches-cpp/theta/test/theta_a_not_b_test.cpp +2 -0
  114. data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java_v1.sk +0 -0
  115. data/vendor/datasketches-cpp/theta/test/theta_compact_empty_from_java_v2.sk +0 -0
  116. data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java_v1.sk +0 -0
  117. data/vendor/datasketches-cpp/theta/test/theta_compact_estimation_from_java_v2.sk +0 -0
  118. data/vendor/datasketches-cpp/theta/test/theta_compact_exact_from_java.sk +0 -0
  119. data/vendor/datasketches-cpp/theta/test/theta_intersection_test.cpp +2 -0
  120. data/vendor/datasketches-cpp/theta/test/theta_setop_test.cpp +446 -0
  121. data/vendor/datasketches-cpp/theta/test/theta_sketch_test.cpp +429 -1
  122. data/vendor/datasketches-cpp/theta/test/theta_union_test.cpp +25 -11
  123. data/vendor/datasketches-cpp/tuple/CMakeLists.txt +18 -33
  124. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch.hpp +1 -1
  125. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_sketch_impl.hpp +3 -3
  126. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union.hpp +1 -1
  127. data/vendor/datasketches-cpp/tuple/include/array_of_doubles_union_impl.hpp +3 -3
  128. data/vendor/datasketches-cpp/tuple/include/tuple_sketch.hpp +29 -9
  129. data/vendor/datasketches-cpp/tuple/include/tuple_sketch_impl.hpp +34 -14
  130. data/vendor/datasketches-cpp/tuple/include/tuple_union.hpp +6 -1
  131. data/vendor/datasketches-cpp/tuple/include/tuple_union_impl.hpp +8 -3
  132. data/vendor/datasketches-cpp/tuple/test/array_of_doubles_sketch_test.cpp +16 -0
  133. data/vendor/datasketches-cpp/tuple/test/tuple_a_not_b_test.cpp +1 -0
  134. data/vendor/datasketches-cpp/tuple/test/tuple_intersection_test.cpp +1 -0
  135. data/vendor/datasketches-cpp/tuple/test/tuple_sketch_test.cpp +46 -8
  136. data/vendor/datasketches-cpp/tuple/test/tuple_union_test.cpp +8 -0
  137. metadata +33 -12
  138. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator.hpp +0 -75
  139. data/vendor/datasketches-cpp/kll/include/kll_quantile_calculator_impl.hpp +0 -184
  140. data/vendor/datasketches-cpp/req/include/req_quantile_calculator.hpp +0 -69
  141. data/vendor/datasketches-cpp/req/include/req_quantile_calculator_impl.hpp +0 -60
  142. data/vendor/datasketches-cpp/theta/test/theta_update_empty_from_java.sk +0 -0
  143. data/vendor/datasketches-cpp/theta/test/theta_update_estimation_from_java.sk +0 -0
@@ -32,29 +32,14 @@ target_include_directories(req
32
32
  target_link_libraries(req INTERFACE common)
33
33
  target_compile_features(req INTERFACE cxx_std_11)
34
34
 
35
- set(req_HEADERS "")
36
- list(APPEND req_HEADERS "include/req_common.hpp")
37
- list(APPEND req_HEADERS "include/req_sketch.hpp")
38
- list(APPEND req_HEADERS "include/req_sketch_impl.hpp")
39
- list(APPEND req_HEADERS "include/req_compactor.hpp")
40
- list(APPEND req_HEADERS "include/req_compactor_impl.hpp")
41
- list(APPEND req_HEADERS "include/req_quantile_calculator.hpp")
42
- list(APPEND req_HEADERS "include/req_quantile_calculator_impl.hpp")
43
-
44
35
  install(TARGETS req
45
36
  EXPORT ${PROJECT_NAME}
46
37
  )
47
38
 
48
- install(FILES ${req_HEADERS}
39
+ install(FILES
40
+ include/req_common.hpp
41
+ include/req_sketch.hpp
42
+ include/req_sketch_impl.hpp
43
+ include/req_compactor.hpp
44
+ include/req_compactor_impl.hpp
49
45
  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/DataSketches")
50
-
51
- target_sources(req
52
- INTERFACE
53
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_common.hpp
54
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_sketch.hpp
55
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_sketch_impl.hpp
56
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_compactor.hpp
57
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_compactor_impl.hpp
58
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_quantile_calculator.hpp
59
- ${CMAKE_CURRENT_SOURCE_DIR}/include/req_quantile_calculator_impl.hpp
60
- )
@@ -21,17 +21,12 @@
21
21
  #define REQ_COMMON_HPP_
22
22
 
23
23
  #include <random>
24
- #include <chrono>
25
24
 
26
25
  #include "serde.hpp"
27
26
  #include "common_defs.hpp"
28
27
 
29
28
  namespace datasketches {
30
29
 
31
- // TODO: have a common random bit with KLL
32
- static std::independent_bits_engine<std::mt19937, 1, unsigned>
33
- req_random_bit(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()));
34
-
35
30
  namespace req_constants {
36
31
  static const uint16_t MIN_K = 4;
37
32
  static const uint8_t INIT_NUM_SECTIONS = 3;
@@ -38,6 +38,9 @@ public:
38
38
  req_compactor& operator=(const req_compactor& other);
39
39
  req_compactor& operator=(req_compactor&& other);
40
40
 
41
+ template<typename TT, typename CC, typename AA>
42
+ req_compactor(const req_compactor<TT, CC, AA>& other, const Allocator& allocator);
43
+
41
44
  bool is_sorted() const;
42
45
  uint32_t get_num_items() const;
43
46
  uint32_t get_nom_capacity() const;
@@ -128,6 +131,9 @@ private:
128
131
  template<typename S>
129
132
  static std::pair<std::unique_ptr<T, items_deleter>, size_t> deserialize_items(const void* bytes, size_t size, const S& serde, const Allocator& allocator, uint32_t num);
130
133
 
134
+ // for type converting constructor
135
+ template<typename TT, typename CC, typename AA>
136
+ friend class req_compactor;
131
137
  };
132
138
 
133
139
  } /* namespace datasketches */
@@ -26,6 +26,7 @@
26
26
 
27
27
  #include "count_zeros.hpp"
28
28
  #include "conditional_forward.hpp"
29
+ #include "common_defs.hpp"
29
30
 
30
31
  #include <iomanip>
31
32
 
@@ -131,6 +132,33 @@ req_compactor<T, C, A>& req_compactor<T, C, A>::operator=(req_compactor&& other)
131
132
  return *this;
132
133
  }
133
134
 
135
+ template<typename T, typename C, typename A>
136
+ template<typename TT, typename CC, typename AA>
137
+ req_compactor<T, C, A>::req_compactor(const req_compactor<TT, CC, AA>& other, const A& allocator):
138
+ allocator_(allocator),
139
+ lg_weight_(other.lg_weight_),
140
+ hra_(other.hra_),
141
+ coin_(other.coin_),
142
+ sorted_(other.sorted_),
143
+ section_size_raw_(other.section_size_raw_),
144
+ section_size_(other.section_size_),
145
+ num_sections_(other.num_sections_),
146
+ state_(other.state_),
147
+ num_items_(other.num_items_),
148
+ capacity_(other.capacity_),
149
+ items_(nullptr)
150
+ {
151
+ if (other.items_ != nullptr) {
152
+ items_ = allocator_.allocate(capacity_);
153
+ const uint32_t from = hra_ ? capacity_ - num_items_ : 0;
154
+ const uint32_t to = hra_ ? capacity_ : num_items_;
155
+ for (uint32_t i = from; i < to; ++i) new (items_ + i) T(other.items_[i]);
156
+ if (sorted_ && !std::is_sorted(items_ + from, items_ + to, C())) {
157
+ throw std::logic_error("items must be sorted");
158
+ }
159
+ }
160
+ }
161
+
134
162
  template<typename T, typename C, typename A>
135
163
  bool req_compactor<T, C, A>::is_sorted() const {
136
164
  return sorted_;
@@ -245,7 +273,7 @@ std::pair<uint32_t, uint32_t> req_compactor<T, C, A>::compact(req_compactor& nex
245
273
  if (compaction_range.second - compaction_range.first < 2) throw std::logic_error("compaction range error");
246
274
 
247
275
  if ((state_ & 1) == 1) { coin_ = !coin_; } // for odd flip coin;
248
- else { coin_ = req_random_bit(); } // random coin flip
276
+ else { coin_ = random_bit(); } // random coin flip
249
277
 
250
278
  const auto num = (compaction_range.second - compaction_range.first) / 2;
251
279
  next.ensure_space(num);
@@ -451,7 +479,7 @@ req_compactor<T, C, A>::req_compactor(bool hra, uint8_t lg_weight, bool sorted,
451
479
  allocator_(allocator),
452
480
  lg_weight_(lg_weight),
453
481
  hra_(hra),
454
- coin_(req_random_bit()),
482
+ coin_(random_bit()),
455
483
  sorted_(sorted),
456
484
  section_size_raw_(section_size_raw),
457
485
  section_size_(nearest_even(section_size_raw)),
@@ -22,22 +22,25 @@
22
22
 
23
23
  #include "req_common.hpp"
24
24
  #include "req_compactor.hpp"
25
- #include "req_quantile_calculator.hpp"
25
+ #include "quantile_sketch_sorted_view.hpp"
26
+
27
+ #include <stdexcept>
26
28
 
27
29
  namespace datasketches {
28
30
 
29
31
  template<
30
32
  typename T,
31
- typename Comparator = std::less<T>,
32
- typename SerDe = serde<T>,
33
+ typename Comparator = std::less<T>, // strict weak ordering function (see C++ named requirements: Compare)
34
+ typename S = serde<T>, // deprecated, to be removed in the next major version
33
35
  typename Allocator = std::allocator<T>
34
36
  >
35
37
  class req_sketch {
36
38
  public:
39
+ using value_type = T;
40
+ using comparator = Comparator;
37
41
  using Compactor = req_compactor<T, Comparator, Allocator>;
38
42
  using AllocCompactor = typename std::allocator_traits<Allocator>::template rebind_alloc<Compactor>;
39
- using AllocDouble = typename std::allocator_traits<Allocator>::template rebind_alloc<double>;
40
- using vector_double = std::vector<double, AllocDouble>;
43
+ using vector_double = std::vector<double, typename std::allocator_traits<Allocator>::template rebind_alloc<double>>;
41
44
 
42
45
  /**
43
46
  * Constructor
@@ -55,6 +58,14 @@ public:
55
58
  req_sketch& operator=(const req_sketch& other);
56
59
  req_sketch& operator=(req_sketch&& other);
57
60
 
61
+ /*
62
+ * Type converting constructor.
63
+ * @param other sketch of a different type
64
+ * @param allocator instance of an Allocator
65
+ */
66
+ template<typename TT, typename CC, typename SS, typename AA>
67
+ explicit req_sketch(const req_sketch<TT, CC, SS, AA>& other, const Allocator& allocator = Allocator());
68
+
58
69
  /**
59
70
  * Returns configured parameter K
60
71
  * @return parameter K
@@ -113,6 +124,12 @@ public:
113
124
  */
114
125
  const T& get_max_value() const;
115
126
 
127
+ /**
128
+ * Returns an instance of the comparator for this sketch.
129
+ * @return comparator
130
+ */
131
+ Comparator get_comparator() const;
132
+
116
133
  /**
117
134
  * Returns an approximation to the normalized (fractional) rank of the given item from 0 to 1 inclusive.
118
135
  * With the template parameter inclusive=true the weight of the given item is included into the rank.
@@ -123,7 +140,6 @@ public:
123
140
  * @param item to be ranked
124
141
  * @return an approximate rank of the given item
125
142
  */
126
-
127
143
  template<bool inclusive = false>
128
144
  double get_rank(const T& item) const;
129
145
 
@@ -135,9 +151,10 @@ public:
135
151
  *
136
152
  * @param split_points an array of <i>m</i> unique, monotonically increasing values
137
153
  * that divide the input domain into <i>m+1</i> consecutive disjoint intervals.
138
- * The definition of an "interval" is inclusive of the left split point (or minimum value) and
139
- * exclusive of the right split point, with the exception that the last interval will include
140
- * the maximum value.
154
+ * If the template parameter inclusive=false, the definition of an "interval" is inclusive of the left split point and exclusive of the right
155
+ * split point, with the exception that the last interval will include the maximum value.
156
+ * If the template parameter inclusive=true, the definition of an "interval" is exclusive of the left split point and inclusive of the right
157
+ * split point.
141
158
  * It is not necessary to include either the min or max values in these split points.
142
159
  *
143
160
  * @return an array of m+1 doubles each of which is an approximation
@@ -178,8 +195,9 @@ public:
178
195
  * @param rank the given normalized rank
179
196
  * @return approximate quantile given the normalized rank
180
197
  */
198
+ using quantile_return_type = typename quantile_sketch_sorted_view<T, Comparator, Allocator>::quantile_return_type;
181
199
  template<bool inclusive = false>
182
- const T& get_quantile(double rank) const;
200
+ quantile_return_type get_quantile(double rank) const;
183
201
 
184
202
  /**
185
203
  * Returns an array of quantiles that correspond to the given array of normalized ranks.
@@ -221,24 +239,28 @@ public:
221
239
  /**
222
240
  * Computes size needed to serialize the current state of the sketch.
223
241
  * This version is for fixed-size arithmetic types (integral and floating point).
242
+ * @param instance of a SerDe
224
243
  * @return size in bytes needed to serialize this sketch
225
244
  */
226
- template<typename TT = T, typename std::enable_if<std::is_arithmetic<TT>::value, int>::type = 0>
227
- size_t get_serialized_size_bytes() const;
245
+ template<typename TT = T, typename SerDe = S, typename std::enable_if<std::is_arithmetic<TT>::value, int>::type = 0>
246
+ size_t get_serialized_size_bytes(const SerDe& sd = SerDe()) const;
228
247
 
229
248
  /**
230
249
  * Computes size needed to serialize the current state of the sketch.
231
250
  * This version is for all other types and can be expensive since every item needs to be looked at.
251
+ * @param instance of a SerDe
232
252
  * @return size in bytes needed to serialize this sketch
233
253
  */
234
- template<typename TT = T, typename std::enable_if<!std::is_arithmetic<TT>::value, int>::type = 0>
235
- size_t get_serialized_size_bytes() const;
254
+ template<typename TT = T, typename SerDe = S, typename std::enable_if<!std::is_arithmetic<TT>::value, int>::type = 0>
255
+ size_t get_serialized_size_bytes(const SerDe& sd = SerDe()) const;
236
256
 
237
257
  /**
238
258
  * This method serializes the sketch into a given stream in a binary form
239
259
  * @param os output stream
260
+ * @param instance of a SerDe
240
261
  */
241
- void serialize(std::ostream& os) const;
262
+ template<typename SerDe = S>
263
+ void serialize(std::ostream& os, const SerDe& sd = SerDe()) const;
242
264
 
243
265
  // This is a convenience alias for users
244
266
  // The type returned by the following serialize method
@@ -250,24 +272,53 @@ public:
250
272
  * It is a blank space of a given size.
251
273
  * This header is used in Datasketches PostgreSQL extension.
252
274
  * @param header_size_bytes space to reserve in front of the sketch
275
+ * @param instance of a SerDe
253
276
  */
254
- vector_bytes serialize(unsigned header_size_bytes = 0) const;
277
+ template<typename SerDe = S>
278
+ vector_bytes serialize(unsigned header_size_bytes = 0, const SerDe& sd = SerDe()) const;
255
279
 
256
280
  /**
257
281
  * This method deserializes a sketch from a given stream.
258
282
  * @param is input stream
283
+ * @param instance of an Allocator
259
284
  * @return an instance of a sketch
285
+ *
286
+ * Deprecated, to be removed in the next major version
260
287
  */
261
288
  static req_sketch deserialize(std::istream& is, const Allocator& allocator = Allocator());
262
289
 
290
+ /**
291
+ * This method deserializes a sketch from a given stream.
292
+ * @param is input stream
293
+ * @param instance of a SerDe
294
+ * @param instance of an Allocator
295
+ * @return an instance of a sketch
296
+ */
297
+ template<typename SerDe = S>
298
+ static req_sketch deserialize(std::istream& is, const SerDe& sd = SerDe(), const Allocator& allocator = Allocator());
299
+
263
300
  /**
264
301
  * This method deserializes a sketch from a given array of bytes.
265
302
  * @param bytes pointer to the array of bytes
266
303
  * @param size the size of the array
304
+ * @param instance of an Allocator
267
305
  * @return an instance of a sketch
306
+ *
307
+ * Deprecated, to be removed in the next major version
268
308
  */
269
309
  static req_sketch deserialize(const void* bytes, size_t size, const Allocator& allocator = Allocator());
270
310
 
311
+ /**
312
+ * This method deserializes a sketch from a given array of bytes.
313
+ * @param bytes pointer to the array of bytes
314
+ * @param size the size of the array
315
+ * @param instance of a SerDe
316
+ * @param instance of an Allocator
317
+ * @return an instance of a sketch
318
+ */
319
+ template<typename SerDe = S>
320
+ static req_sketch deserialize(const void* bytes, size_t size, const SerDe& sd = SerDe(), const Allocator& allocator = Allocator());
321
+
271
322
  /**
272
323
  * Prints a summary of the sketch.
273
324
  * @param print_levels if true include information about levels
@@ -279,6 +330,9 @@ public:
279
330
  const_iterator begin() const;
280
331
  const_iterator end() const;
281
332
 
333
+ template<bool inclusive = false>
334
+ quantile_sketch_sorted_view<T, Comparator, Allocator> get_sorted_view(bool cumulative) const;
335
+
282
336
  private:
283
337
  Allocator allocator_;
284
338
  uint16_t k_;
@@ -310,13 +364,6 @@ private:
310
364
  static double get_rank_ub(uint16_t k, uint8_t num_levels, double rank, uint8_t num_std_dev, uint64_t n, bool hra);
311
365
  static bool is_exact_rank(uint16_t k, uint8_t num_levels, double rank, uint64_t n, bool hra);
312
366
 
313
- using QuantileCalculator = req_quantile_calculator<T, Comparator, Allocator>;
314
- using AllocCalc = typename std::allocator_traits<Allocator>::template rebind_alloc<QuantileCalculator>;
315
- class calculator_deleter;
316
- using QuantileCalculatorPtr = typename std::unique_ptr<QuantileCalculator, calculator_deleter>;
317
- template<bool inclusive>
318
- QuantileCalculatorPtr get_quantile_calculator() const;
319
-
320
367
  // for deserialization
321
368
  class item_deleter;
322
369
  req_sketch(uint16_t k, bool hra, uint64_t n, std::unique_ptr<T, item_deleter> min_value, std::unique_ptr<T, item_deleter> max_value, std::vector<Compactor, AllocCompactor>&& compactors);
@@ -369,6 +416,9 @@ private:
369
416
  }
370
417
  }
371
418
 
419
+ // for type converting constructor
420
+ template<typename TT, typename CC, typename SS, typename AA>
421
+ friend class req_sketch;
372
422
  };
373
423
 
374
424
  template<typename T, typename C, typename S, typename A>