This is an automated email from the ASF dual-hosted git repository. jmalkin pushed a commit to branch density_custom_kernel in repository https://gitbox.apache.org/repos/asf/datasketches-cpp.git
commit 5a21a3588370e69182ac24c279e4fa3e07acc725 Author: AlexanderSaydakov <[email protected]> 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: [email protected] For additional commands, e-mail: [email protected]
