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 2020/02/25 22:32:10 UTC
[incubator-datasketches-cpp] branch master updated: cpc union
moving update
This is an automated email from the ASF dual-hosted git repository.
alsay pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-datasketches-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 176d74e cpc union moving update
176d74e is described below
commit 176d74e90a1b85990dc5dd6ed9a09ae097367e8a
Author: AlexanderSaydakov <Al...@users.noreply.github.com>
AuthorDate: Tue Feb 25 14:31:58 2020 -0800
cpc union moving update
---
cpc/include/cpc_union.hpp | 3 +++
cpc/include/cpc_union_impl.hpp | 15 +++++++++++++--
cpc/test/cpc_union_test.cpp | 10 ++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/cpc/include/cpc_union.hpp b/cpc/include/cpc_union.hpp
index 9601cc0..9bdae6e 100644
--- a/cpc/include/cpc_union.hpp
+++ b/cpc/include/cpc_union.hpp
@@ -53,6 +53,7 @@ class cpc_union_alloc {
cpc_union_alloc<A>& operator=(cpc_union_alloc<A>&& other) noexcept;
void update(const cpc_sketch_alloc<A>& sketch);
+ void update(cpc_sketch_alloc<A>&& sketch);
cpc_sketch_alloc<A> get_result() const;
private:
@@ -65,6 +66,8 @@ class cpc_union_alloc {
cpc_sketch_alloc<A>* accumulator;
vector_u64<A> bit_matrix;
+ template<typename S> void internal_update(S&& sketch); // to support both rvalue and lvalue
+
cpc_sketch_alloc<A> get_result_from_accumulator() const;
cpc_sketch_alloc<A> get_result_from_bit_matrix() const;
diff --git a/cpc/include/cpc_union_impl.hpp b/cpc/include/cpc_union_impl.hpp
index 3363b77..bd390dc 100644
--- a/cpc/include/cpc_union_impl.hpp
+++ b/cpc/include/cpc_union_impl.hpp
@@ -85,6 +85,17 @@ cpc_union_alloc<A>& cpc_union_alloc<A>::operator=(cpc_union_alloc<A>&& other) no
template<typename A>
void cpc_union_alloc<A>::update(const cpc_sketch_alloc<A>& sketch) {
+ internal_update(sketch);
+}
+
+template<typename A>
+void cpc_union_alloc<A>::update(cpc_sketch_alloc<A>&& sketch) {
+ internal_update(std::forward<cpc_sketch_alloc<A>>(sketch));
+}
+
+template<typename A>
+template<typename S>
+void cpc_union_alloc<A>::internal_update(S&& sketch) {
const uint16_t seed_hash_union = compute_seed_hash(seed);
const uint16_t seed_hash_sketch = compute_seed_hash(sketch.seed);
if (seed_hash_union != seed_hash_sketch) {
@@ -106,9 +117,9 @@ void cpc_union_alloc<A>::update(const cpc_sketch_alloc<A>& sketch) {
cpc_sketch_alloc<A>::flavor::SPARSE != initial_dest_flavor) throw std::logic_error("wrong flavor");
// The following partially fixes the snowplow problem provided that the K's are equal.
- // A complete fix is coming soon.
if (cpc_sketch_alloc<A>::flavor::EMPTY == initial_dest_flavor and lg_k == sketch.get_lg_k()) {
- *accumulator = sketch;
+ *accumulator = std::forward<S>(sketch);
+ return;
}
walk_table_updating_sketch(sketch.surprising_value_table);
diff --git a/cpc/test/cpc_union_test.cpp b/cpc/test/cpc_union_test.cpp
index 256ee10..a9928a9 100644
--- a/cpc/test/cpc_union_test.cpp
+++ b/cpc/test/cpc_union_test.cpp
@@ -37,6 +37,7 @@ class cpc_union_test: public CppUnit::TestFixture {
CPPUNIT_TEST(reduce_k_empty);
CPPUNIT_TEST(reduce_k_sparse);
CPPUNIT_TEST(reduce_k_window);
+ CPPUNIT_TEST(moving_update);
CPPUNIT_TEST_SUITE_END();
void lg_k_limits() {
@@ -149,6 +150,15 @@ class cpc_union_test: public CppUnit::TestFixture {
CPPUNIT_ASSERT_DOUBLES_EQUAL(1000, r.get_estimate(), 1000 * RELATIVE_ERROR_FOR_LG_K_11);
}
+ void moving_update() {
+ cpc_union u(11);
+ cpc_sketch s(11);
+ for (int i = 0; i < 100; i++) s.update(i); // sparse
+ u.update(std::move(s));
+ cpc_sketch r = u.get_result();
+ CPPUNIT_ASSERT_DOUBLES_EQUAL(100, r.get_estimate(), 100 * RELATIVE_ERROR_FOR_LG_K_11);
+ }
+
};
CPPUNIT_TEST_SUITE_REGISTRATION(cpc_union_test);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org