You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by al...@apache.org on 2022/12/14 20:17:11 UTC

[datasketches-cpp] branch density_sketch updated: added is_estimation_mode() method

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

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


The following commit(s) were added to refs/heads/density_sketch by this push:
     new 8062a90  added is_estimation_mode() method
8062a90 is described below

commit 8062a9056f68be3a60514a5d3eb63c5db27b0f1b
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Wed Dec 14 12:17:05 2022 -0800

    added is_estimation_mode() method
---
 density/include/density_sketch.hpp      | 6 ++++++
 density/include/density_sketch_impl.hpp | 5 +++++
 density/test/density_sketch_test.cpp    | 2 ++
 3 files changed, 13 insertions(+)

diff --git a/density/include/density_sketch.hpp b/density/include/density_sketch.hpp
index 551d51f..578ac8b 100755
--- a/density/include/density_sketch.hpp
+++ b/density/include/density_sketch.hpp
@@ -94,6 +94,12 @@ public:
    */
   uint32_t get_num_retained() const;
 
+  /**
+   * Returns true if this sketch is in estimation mode.
+   * @return estimation mode flag
+   */
+  bool is_estimation_mode() const;
+
   /**
    * Updates this sketch with a given point.
    * @param point given point
diff --git a/density/include/density_sketch_impl.hpp b/density/include/density_sketch_impl.hpp
index 86da337..f33110f 100755
--- a/density/include/density_sketch_impl.hpp
+++ b/density/include/density_sketch_impl.hpp
@@ -61,6 +61,11 @@ uint32_t density_sketch<T, K, A>::get_num_retained() const {
   return num_retained_;
 }
 
+template<typename T, typename K, typename A>
+bool density_sketch<T, K, A>::is_estimation_mode() const {
+  return levels_.size() > 1;
+}
+
 template<typename T, typename K, typename A>
 template<typename FwdVector>
 void density_sketch<T, K, A>::update(FwdVector&& point) {
diff --git a/density/test/density_sketch_test.cpp b/density/test/density_sketch_test.cpp
index a51ceb2..4f5927f 100755
--- a/density/test/density_sketch_test.cpp
+++ b/density/test/density_sketch_test.cpp
@@ -37,6 +37,7 @@ TEST_CASE("density sketch: one item", "[density_sketch]") {
 
   sketch.update(std::vector<float>({0, 0, 0}));
   REQUIRE_FALSE(sketch.is_empty());
+  REQUIRE_FALSE(sketch.is_estimation_mode());
   REQUIRE(sketch.get_estimate({0, 0, 0}) == 1);
   REQUIRE(sketch.get_estimate({0.01, 0.01, 0.01}) > 0.95);
   REQUIRE(sketch.get_estimate({1, 1, 1}) < 0.05);
@@ -61,6 +62,7 @@ TEST_CASE("density sketch: iterator", "[density_sketch]") {
   unsigned n = 1000;
   for (unsigned i = 1; i <= n; ++i) sketch.update(std::vector<float>(3, i));
   REQUIRE(sketch.get_n() == n);
+  REQUIRE(sketch.is_estimation_mode());
   //std::cout << sketch.to_string(true, true);
   unsigned count = 0;
   for (auto pair: sketch) {


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