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 2019/08/06 19:53:57 UTC
[incubator-datasketches-cpp] 01/01: remove default construction in
deserialize
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch kll_deserialize_fix
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
commit 162c2d946336b414e3cf5362730cb7c91a07cbeb
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Aug 6 12:53:43 2019 -0700
remove default construction in deserialize
---
kll/include/kll_sketch.hpp | 2 --
kll/test/kll_sketch_custom_type_test.cpp | 30 +++++++++++++++++++++++++++++-
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/kll/include/kll_sketch.hpp b/kll/include/kll_sketch.hpp
index 10919a5..4663af5 100644
--- a/kll/include/kll_sketch.hpp
+++ b/kll/include/kll_sketch.hpp
@@ -752,7 +752,6 @@ kll_sketch<T, C, S, A>::kll_sketch(uint16_t k, uint8_t flags_byte, std::istream&
}
items_ = A().allocate(capacity);
items_size_ = capacity;
- for (unsigned i = 0; i < items_size_; i++) A().construct(&items_[i], T());
const auto num_items = levels_[num_levels_] - levels_[0];
S().deserialize(is, &items_[levels_[0]], num_items);
if (is_single_item) {
@@ -798,7 +797,6 @@ kll_sketch<T, C, S, A>::kll_sketch(uint16_t k, uint8_t flags_byte, const void* b
}
items_ = A().allocate(capacity);
items_size_ = capacity;
- for (unsigned i = 0; i < items_size_; i++) A().construct(&items_[i], T());
const auto num_items(levels_[num_levels_] - levels_[0]);
ptr += S().deserialize(ptr, &items_[levels_[0]], num_items);
if (is_single_item) {
diff --git a/kll/test/kll_sketch_custom_type_test.cpp b/kll/test/kll_sketch_custom_type_test.cpp
index 4e60024..12d3d7d 100644
--- a/kll/test/kll_sketch_custom_type_test.cpp
+++ b/kll/test/kll_sketch_custom_type_test.cpp
@@ -22,7 +22,8 @@
#include <kll_sketch.hpp>
#include <test_allocator.hpp>
-#include "../../common/test/test_type.hpp"
+#include <test_type.hpp>
+
namespace datasketches {
@@ -34,6 +35,7 @@ class kll_sketch_custom_type_test: public CppUnit::TestFixture {
CPPUNIT_TEST(compact_level_zero);
CPPUNIT_TEST(merge_small);
CPPUNIT_TEST(merge_higher_levels);
+ CPPUNIT_TEST(serialize_deserialize);
CPPUNIT_TEST_SUITE_END();
public:
@@ -122,6 +124,32 @@ public:
CPPUNIT_ASSERT_EQUAL(18, sketch2.get_max_value().get_value());
}
+ void serialize_deserialize() {
+ kll_test_type_sketch sketch1;
+
+ const int n = 1000;
+ for (int i = 0; i < n; i++) sketch1.update(i);
+
+ std::stringstream s(std::ios::in | std::ios::out | std::ios::binary);
+ sketch1.serialize(s);
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_serialized_size_bytes(), (uint32_t) s.tellp());
+ auto sketch2 = kll_test_type_sketch::deserialize(s);
+ CPPUNIT_ASSERT_EQUAL(sketch2.get_serialized_size_bytes(), (uint32_t) s.tellg());
+ CPPUNIT_ASSERT_EQUAL(s.tellp(), s.tellg());
+ CPPUNIT_ASSERT_EQUAL(sketch1.is_empty(), sketch2.is_empty());
+ CPPUNIT_ASSERT_EQUAL(sketch1.is_estimation_mode(), sketch2.is_estimation_mode());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_n(), sketch2.get_n());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_num_retained(), sketch2.get_num_retained());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_min_value().get_value(), sketch2.get_min_value().get_value());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_max_value().get_value(), sketch2.get_max_value().get_value());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_normalized_rank_error(false), sketch2.get_normalized_rank_error(false));
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_normalized_rank_error(true), sketch2.get_normalized_rank_error(true));
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_quantile(0.5).get_value(), sketch2.get_quantile(0.5).get_value());
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_rank(0), sketch2.get_rank(0));
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_rank(n), sketch2.get_rank(n));
+ CPPUNIT_ASSERT_EQUAL(sketch1.get_rank(n / 2), sketch2.get_rank(n / 2));
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(kll_sketch_custom_type_test);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org