You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by jm...@apache.org on 2022/05/13 02:47:40 UTC

[datasketches-cpp] branch quantile_type_conversion updated: add allocator_type and get_allocator()

This is an automated email from the ASF dual-hosted git repository.

jmalkin pushed a commit to branch quantile_type_conversion
in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git


The following commit(s) were added to refs/heads/quantile_type_conversion by this push:
     new 8c63080  add allocator_type and get_allocator()
8c63080 is described below

commit 8c630805459bdd19a612dce3435c1079bb4e6424
Author: Jon <jm...@apache.org>
AuthorDate: Thu May 12 19:47:31 2022 -0700

    add allocator_type and get_allocator()
---
 quantiles/include/quantiles_sketch.hpp      | 7 +++++++
 quantiles/include/quantiles_sketch_impl.hpp | 5 +++++
 quantiles/test/quantiles_sketch_test.cpp    | 2 +-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/quantiles/include/quantiles_sketch.hpp b/quantiles/include/quantiles_sketch.hpp
index 55b08d7..acf430a 100644
--- a/quantiles/include/quantiles_sketch.hpp
+++ b/quantiles/include/quantiles_sketch.hpp
@@ -151,6 +151,7 @@ template <typename T,
 class quantiles_sketch {
 public:
   using value_type = T;
+  using allocator_type = Allocator;
   using comparator = Comparator;
   using vector_double = std::vector<double, typename std::allocator_traits<Allocator>::template rebind_alloc<double>>;
 
@@ -230,6 +231,12 @@ public:
    */
   Comparator get_comparator() const;
 
+  /**
+   * Returns the allocator for this sketch.
+   * @return allocator
+   */
+  allocator_type get_allocator() const;
+
   /**
    * Returns an approximation to the value of the data item
    * that would be preceded by the given fraction of a hypothetical sorted
diff --git a/quantiles/include/quantiles_sketch_impl.hpp b/quantiles/include/quantiles_sketch_impl.hpp
index 0a4d5ea..2aac025 100644
--- a/quantiles/include/quantiles_sketch_impl.hpp
+++ b/quantiles/include/quantiles_sketch_impl.hpp
@@ -684,6 +684,11 @@ C quantiles_sketch<T, C, A>::get_comparator() const {
   return C();
 }
 
+template<typename T, typename C, typename A>
+A quantiles_sketch<T, C, A>::get_allocator() const {
+  return allocator_;
+}
+
 // implementation for fixed-size arithmetic types (integral and floating point)
 template<typename T, typename C, typename A>
 template<typename SerDe, typename TT, typename std::enable_if<std::is_arithmetic<TT>::value, int>::type>
diff --git a/quantiles/test/quantiles_sketch_test.cpp b/quantiles/test/quantiles_sketch_test.cpp
index a878201..6e5de34 100644
--- a/quantiles/test/quantiles_sketch_test.cpp
+++ b/quantiles/test/quantiles_sketch_test.cpp
@@ -908,7 +908,7 @@ TEST_CASE("quantiles sketch", "[quantiles_sketch]") {
     const int n = 403;
     quantiles_sketch<double> sk_double(k);
     
-    quantiles_sketch<float> sk_float(k);
+    quantiles_sketch<float> sk_float(k, sk_double.get_allocator());
     REQUIRE(sk_float.is_empty());
     
     for (int i = 0; i < n; ++i) sk_double.update(i + .01);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org